linux(ubuntu) 1045, "Access denied for user 'root'@'localhost' (using password: YES)"

问题现象:mysql

最近使用 flask 的 sqlalchemy 框架,在连接数据库(mysql)时出现报错sql

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, "Access denied for user 'root'@'localhost' (using password: YES)") (Background on this error at: http://sqlalche.me/e/e3q8)数据库

直接在终端输入 mysql 也会出现报错flask

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)ubuntu

可是使用 mysql -uroot -p 能够正常进入数据库安全

 

解决方法:框架

个人系统为 ubuntu 测试

修改文件this

/etc/mysql/mysql.conf.d/mysqld.cnfspa

找到 [mysqld]

添加配置:

skip-grant-tables

保存后重启服务

/etc/init.d/mysql restart

 

此时报错都被解决掉了 直接输入 mysql 便可进入数据库

若是是本身测试或者练手小项目就能够继续了,可是此方式存在安全隐患,会跳过权限验证,若是对安全有要求的须要进入数据库修改密码后将此配置去掉后重启

 

use mysql;
update user set password=password("你的新密码") where user="root";
相关文章
相关标签/搜索