ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'
mysql> use mysql
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'
mysql> exit
版权声明:本文为博主原创文章,未经博主允许不得转载。
出现这种问题,主要的原因就是权限配置的时候 没有配置正确。
解决方法如下:
(1)登陆进MySQL 时, mysql -u root -p
(2)show grants; 会出现root如下的权限表示:GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '565491d704013245' WITH GRANT OPTION
解释:
grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;
(3)grant all privileges on *.* to 'root'@'%' with grant option;
(4)FLUSH PRIVILEGES;
(5)exit
Bye
[root@testtest ~]# service mysqld stop
Stopping mysqld: [ OK ]
[root@testtest ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[root@testtest ~]# mysql -u root -p -hlocalhost
Enter password:
mysql> use mysql
mysql> SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;
mysql> UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> GRANT ALL ON *.* TO 'root'@'localhost';
mysql> GRANT ALL ON *.* TO 'root'@'cn.cn.cn.cn';
mysql> GRANT ALL ON *.* TO 'root'@'245.245.245.245';
mysql> GRANT ALL ON *.* TO 'root'@'127.0.0.1';
mysql> FLUSH PRIVILEGES;
mysql> quit
Bye
[root@testtest ~]# service mysqld start