mysql配置远程访问

  1. 1. Bonus-Tip: Revoke Access

建立远程访问用户

1
2
3
4
5
GRANT ALL PRIVILEGES ON *.* TO 'YOURUSER'@'%' IDENTIFIED BY 'YOURPASSWORD' WITH GRANT OPTION;
FLUSH PRIVILEGES;
#查看结果:
SELECT * from information_schema.user_privileges where grantee like "'YOURUSER'%";

配置my.cnf,通常是/etc/mysql/my.cnf,找到并注释掉下面语句

1
2
3
bind-address = 127.0.0.1 # 或者改成 bind-address = 0.0.0.0
skip-networking

重启服务器

Bonus-Tip: Revoke Access

If you accidentally grant access to a user, then better have revoking option handy.

1
2
3
4
5
#Following will revoke all options for THEUSER from all machines:
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'THEUSER'@'%';
#Following will revoke all options for THEUSER from particular IP:
mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'THEUSER'@'1.2.3.4';

Its better to check information_schema.user_privileges table after running REVOKE command.

If you see USAGE privilege after running REVOKE command, its fine. It is as good as no privilege at all. I am not sure if it can be revoked.