远程连接mysql

修改mysql.user表 
以root或debian-sys-maint身份登录mysql

如果root用户连不上,可以新建用户(建议不要用root用户连):

mysql>create user user_name identified by 'password123456';
$ mysql -u debian-sys-maint -p 
mysql> use mysql 
mysql> select Host, User from user; 
mysql> GRANT ALL PRIVILEGES ON *.* TO 'foo'@'%'; 
mysql> SET PASSWORD FOR 'foo'@'%' = PASSWORD("123"); 
mysql> FLUSH PRIVILEGES; 

修改mysql配置文件

$ pwd
/etc/mysql/mysql.conf.d
#ubuntu对应/etc/mysql/my.cnf
$ vim mysqld.cnf #对应修改下面的内容
# 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 = 0.0.0.0

centos需要打开防火墙:iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT 
iptables -L -n 
修改完成后,需要重新启动mysql服务 
$ /etc/init.d/mysql restart


实际连接 
mysql -u foo -p -h 192.168.1.25

参考: http://www.jb51.net/article/31850.htm

posted on 2017-12-11 11:15  willaty  阅读(123)  评论(0编辑  收藏  举报

导航