linux连接命令:
mysql -h xxx.xxx.xxx.xxx -P 3306 -u user -p
如果遇到报错:
ERROR 2003 (HY000): Can't connect to MySQL server on '47.252.29.75' (111)
在 /etc/mysql/mysql.conf.d 目录下修改 mysqld.cnf , 将 bind-address 注释掉
重启mysql服务
service mysqld restart (5.0版本命令)
service mysql restart (5.5.7版本命令)
再次连接,如果报错:
ERROR 1130 (HY000): Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
先进入mysql,再输入以下命令,其中username和password是你数据库的账号密码
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
flush privileges;
如果是mysql8.0及以上的版本,则需要改成
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
flush privileges;
grant all privileges on *.* to 'username'@'%';
再次连接即可成功。