连接mysql ERROR 1045

问题:
-ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using> password: YES)

处理方式:

Step1:停止服务

service mysql stop

Step2:修改配置文件

whereis msyqld.cnf
vi /etc/mysql/mysql.conf.d/mysqld.cnf

在mysqld选项中添加
[mysqld]
.
.
.
skip-grant-tables

Step3:登入数据库

mysql> UPDATE user SET password=PASSWORD(‘newpswd’) WHERE user=’root’ (修改密码)

mysql> flush privileges ( 刷新MySQL权限相关的表)
mysql> use mysql;
mysql> select user,host,password from user;

+------+-----------------------+----------+
| user | host                  | password |
+------+-----------------------+----------+
| root | %                           | mima  |
| root | localhost.localdomain | mima  |
| root | 127.0.0.1                 | mima  |
|        | localhost                  |          |
|        | localhost.localdomain |          |
+------+-----------------------+----------+

mysql> delete from user where user='';
mysql> exit (退出MySQL)

step4:重启服务

service mysql restart

你可能感兴趣的:(Mysql)