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


原因:修改数据库账号时删除了默认的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;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM