MySQL

1、编辑 my.cnf 文件:

1
sudo vi /etc/mysql/my.cnf

2、将绑定地址行注释掉或者修改为指定 IP

1
#bind-address = 127.0.0.1

3、登录 MySQL:

1
mysql -uroot -p123

4、添加 root 用户访问权限

1
2
grant all privileges on *.* to 'root'@'%' identified by '123';
flush privileges;

5、查看 user 权限,成功修改权限为 %:

1
2
3
4
5
6
7
8
9
select host,user from mysql.user;

+------------+----------------+
| host       | user           |
+------------+----------------+
| %          | root           |
| 127.0.0.1  | root           |
| localhost  | root           |
+------------+----------------+

6、重启 MySQL:

1
sudo /etc/init.d/mysql restart

Postgres

1、编辑 postgresql.conf 文件:

1
2
3
4
sudo vi /etc/postgresql/9.4/main/postgresql.conf

# 增加
listen_addresses = '*'

2、编辑 pg_hba.conf 文件:

1
2
3
4
5
sudo vi /etc/postgresql/9.4/main/pg_hba.conf

# 修改
#host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0               md5

3、重启 Postgres

1
sudo service postgresql restart