linux下mysql开启/关闭远程访问

时间:2021-05-04 11:41:08


接上文:http://blog.csdn.net/l241002209/article/details/72763774


[mysql@localhost MySQL-5.6.36-1.linux_glibc2.5.x86_64.rpm-bundle]$ mysql -uroot -p123456

#设置远程访问

#root是允许远程访问的账户名(可以是其他的),"192.168.7.200"表示只允许这个ip地址远程访问(任意地址:‘%’),‘123456’是远程访问密码

#完整意思:允许用户root在ip为192.168.7.200的主机上使用密码123456来登录mysql

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.7.200' IDENTIFIED BY '123456' WITH GRANT OPTION;

mysql> FLUSH PRIVILEGES;

#移除远程访问

mysql> REVOKE ALL PRIVILEGES ON *.* FROM 'root'@'192.168.7.200';#移除授权

#下面是删除之前设置的远程登录信息(user,ip,password)

mysql> use mysql;

mysql> select host,user from user where user='root';

mysql> delete from user where user='root' and host='192.168.7.200';

mysql> flush privileges;

mysql> select host,user from user where user='root';#可以看到已经删除了