配置mysql允许远程连接的方法

默认分类 · 2023-04-03 · 146 人浏览

默认情况下,mysql只允许本地登录,如果要开启远程连接,则需要修改/etc/mysql/my.conf文件。

开启MySQL远程访问权限 允许远程连接
1、登陆mysql数据库
mysql -u root -p

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

   grant all privileges on *.*  to root@'%' identified by '123456.' ;

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 user;
hostuserpassword
localhostroot*A731AEBFB621E354CD41BAF207D884A609E81F5E
192.168.1.1root*A731AEBFB621E354CD41BAF207D884A609E81F5E
%root*A731AEBFB621E354CD41BAF207D884A609E81F5E

3 rows in set (0.00 sec)

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