ERROR 1044 (42000): Access denied for user 'root'@'%' to database 'mysql'

转自https://www.cnblogs.com/jiangfeilong/p/10560754.html

 关键要授予 WITH GRANT OPTION;#

原因:修改数据库账号时删除了默认的localhost root,  新建了% root 但没有赋予全部权限;

解决方法:

1.关闭数据库# mysqld stop

2.在my.cnf里加入skip-grant-tables

3.停止服务器进程  //没有找到停止的方法用ps -ef | grep mysqld 后 kill掉了

4.重新启动服务器

5.进入 use mysql

6.先刷新一下权限表。

mysql> flush privileges;

CREATE USER 'root'@'%' IDENTIFIED BY '12';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;#注意刷新权限表

7.关闭mysqld            /etc/init.d/mysqld stop

8.将my.cnf 里的设置注释掉

#select host,user from mysql.user

 9.开启mysqld       /etc/init.d/mysqld start

10.直接# mysql 进入服务器

11.设置用户密码

select host, user, authentication_string, plugin from user;//查看用户密码信息
//authentication_string 为用户密码 plugin 加密方式
update user set authentication_string='' where user='root';
ALTER user 'root'@'localhost' IDENTIFIED BY '1';//设置密码
flush privileges;

 

posted @ 2024-02-06 16:16  feiyun8616  阅读(23)  评论(0编辑  收藏  举报