1.刚开始登录用的是
mysql -uroot -pmysql_P@s5 -P3318 -h【远程登录ip】
2.设置权限报错
grant all privileges on *.* to 'root'@'%' identified by 'mysql_P@s5' with grant option;
报错:ERROR 1045 (28000): Access denied for user 'root'@'%' (using password: YES)
3.查看权限
查看root权限
show grants for 'root'@'%';
+-------------------------------------------+
| Grants for root@% |
+-------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' |
+-------------------------------------------+
发现root有创建普通登录用户的权限没有赋予权限的权限
查看所有用户
> SELECT user,host FROM mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
发现还有一个本地root用户
查看本地root权限
> show grants for 'root'@'localhost';
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
此时问题已经出来了。这是在设置远程登录权限时创建的root并没有赋予权限
4,问题解决
登录本地root用户设置权限
~]# mysql -uroot -p -P3318 -hlocalhost
> grant all privileges on *.* to 'root'@'%' identified by 'mysql_P@s5' with grant option;
查看已经没有问题了
> show grants for 'root'@'%';
+-------------------------------------------------------------+
| Grants for root@% |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
|