美文网首页程序员
开启MySQL远程访问权限,允许远程连接

开启MySQL远程访问权限,允许远程连接

作者: 飞叔Brother | 来源:发表于2018-08-06 17:00 被阅读8次

登陆MySQL数据库

mysql -u root -p

查看mysql.user表

mysql> select host,user,password from mysql.user;

+---------------+------+-------------------------------------------+

| host          | user | password                                  |

+---------------+------+-------------------------------------------+

| localhost    | root |                                          |

| data2        | root |                                          |

+---------------+------+-------------------------------------------+

2 rows in set (0.00 sec)

可以看到在user表中已经创建的root用户。host字段表示登陆的主机。

实现远程连接(授权法)

将host字段的值改为%就表示在任何客户端机器上能以root用户登陆到mysql服务器,建议在开发是设置为%。

将权限改为ALL PRIVILEGES

mysql>grant all privileges  on *.* to root@'%' identified by "password";

Query OK, 0 rows affected (0.00 sec)

mysql>flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,password from mysql.user;

+---------------+------+-------------------------------------------+

| host          | user | password                                  |

+---------------+------+-------------------------------------------+

| localhost     | root |                                           |

| data2         | root |                                           |

| %            | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |

+---------------+------+-------------------------------------------+

3 rows in set (0.00 sec)

这样机器就可以以用户名root密码root远程访问该机器上的mysql。

实现远程连接(改表法)

update mysql.user set host = '%' where user = 'root';

这样在远端就可以通过root用户访问Mysql.


安利一个特别热心的编程乐园群:624108656

超级热心的群

相关文章

网友评论

    本文标题:开启MySQL远程访问权限,允许远程连接

    本文链接:https://www.haomeiwen.com/subject/kncgvftx.html