mysql 报1045错误的解决方式

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045....


pymysql.err.OperationalError: (1045, u"Access denied for user 'root'@'localhost' (using password: No)")


等一系列的问题,都是报1045的错误,如果你在是python3,和mysql8的基础上处理的话,

报该错误说明你的密码认证方式不一样了。

新版mysql使用的caching_sha2_password,只需将其换成mysql_native_password便可以连接上了。

具体的连接方式:

进入mysql终端进行如下操作:

ACA8016B:~ zou$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 8.0.12 Homebrew

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
mysql> 
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'qwer4321';
Query OK, 0 rows affected (0.06 sec)
凉葱落

凉葱落python开发工程师