红联Linux门户
Linux帮助

Ubuntu下允许mysql远程连接

发布时间:2015-11-28 15:35:53来源:linux网站作者:yjlongg

第一步:授权用户可进行远程连接

以root用户登录mysql:mysql -u root -p

授权:grant all privileges on *.* to root@"%" identified by "password" with grant option;

*.*:第一个*代表数据库名;第二个*代表表名。这里的意思是所有数据库里的所有表都授权给用户

root:授予root账号,也可以是其他用户。
“%”:表示授权的用户IP可以指定,这里代表任意的IP地址都能访问MySQL数据库。
“password”:分配账号对应的密码。
刷新权限:flush privileges;
让我们所做设置立即生效。


第二步:允许任意IP访问
编辑 /etc/mysql/my.cnf
sudo vi /etc/mysql/my.cnf 找到 bind-address = 127.0.0.1,注释掉这行,即:#bind-address = 127.0.0.1,或者将其改为:bind-address = 0.0.0.0,允许任意IP访问。或者自己指定一个IP地址。


第三步:重启mysql服务
sudo service mysql restart
或者:sudo /etc/init.d/mysql restart


mysql远程登陆不上:http://www.linuxdiyf.com/linux/15361.html

MySQL远程连接不上的解决:http://www.linuxdiyf.com/linux/11488.html

ubuntu 15.04开放mysql远程3306端口:http://www.linuxdiyf.com/linux/15206.html