mysql连接拒绝问题

mysql中在其它机器连接mysql服务器时报错问题汇总

一、[running][email protected]:~$mysql -uroot -h 192.168.9.108 -p   //带-p参数,在下一步进行密码输入
Enter password:    //无字符串输入
ERROR 1045 (28000): Access denied for user 'root'@'192.168.9.136' (using password: NO)


此问题原因是在192.168.9.136这台机器的mysql中没有对192.168.9.136访问授权,可以直接登录数据库服务器192.168.9.108通过命令连到数据库授权

授权方法如下:

mysql>  grant all privileges on *.* to 'root'@'192.168.9.136' identified by 'test' with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

如果在执行grant语句授权报如下错误时:
ERROR 1045 (28000): Access denied for user 'root'@'192.168.9.108' (using password: YES)

则可以使用如下命令查看当前登录用户的权限:

mysql> show grants;
+-------------------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]                                                                                            |
+-------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.209.7.243' IDENTIFIED BY PASSWORD '*1E3F4A87D0945AC27F4F8EA69B3E3EC153DCFCF2' |
+-------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

从上面可以看出当前用户只是拥有所有权限,但没有分配给其他用户权限的权限



mysql> show grants for root@localhost;    
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
1 row in set (0.00 sec)

从此命令显示root@localhost 方式连接才具有分配权限的权限“WITH GRANT OPTION”

这样就可以通过mysql -h localhost -u root -p方式连接数据库,与之前的区别是之前连数据库是以IP的方式连接

连接后再执行授权语句:
grant all privileges on *.* to 'root'@'192.168.9.136' identified by 'test' ;
如果不的报错,则说明授权成功,然后再执行下面命令则可以连接
mysql> flush privileges; 

如果执行授权语句还是报错,则可以改为mysql -h 127.0.0.1 -u root -p方式连接数据,再授权即可。

验证方式:mysql>select host,username,password from mysql.user;
如果显示出新加的root,192.168.9.136记录,则表示授权成功

你可能感兴趣的:(mysql,登录权限)