远程连接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
【本文章出自博客园willaty,转载请注明作者出处,误差欢迎指出~】