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