第一步是要创建一个可以远程连接的 MySQL 用户
mysql> GRANT ALL PRIVILEGES ON dbname.* TO 'user'@'%' IDENTIFIED BY 'userPWD' WITH GRANT OPTION;
mysql> flush privileges;
### "%"表示任意IP,如果要为特定的user指定从特定的IP访问,方法如下:
mysql> GRANT ALL PRIVILEGES ON dbname.* TO 'user'@'ip' IDENTIFIED BY 'userPWD' WITH GRANT OPTION;
mysql> flush privileges;
第二步是要修改 mysql 的配置文件 /etc/mysql/my.cnf
在旧版本中找到 skip-networking,把它注释掉就可以了
#skip-networking
在新版本中:
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
bind-address = 127.0.0.1 这一行要注释掉
#bind-address = 127.0.0.1
或者把允许访问的ip 填上
bind-address = 192.168.1.100
然后重启 MySQL
/etc/init.d/mysql restart
以上方法只完成了外网访问的配置,它只允许从主机上访问MYSQL,如果要完全从外网访问则需要将主机的3306端口映射到虚拟机的3306上(当然其它的端口也是可以的)
虚拟机端口映射:
http://wenku.baidu.com/view/b01c2ccca1c7aa00b52acb62.html###