本文说明云服务器 ECS Linux 上 MySQL 无法访问问题的一般排查步骤。
$ rpm -qa mysql mysql-4.1.7-4.RHEL4.1 # 说明已经安装了 MySQL
service mysqld status
service mysqld start
/etc/init.d/mysql start
safe_mysqld& //使用&表示将safe_mysqld放在后台执行。
mysqladmin -u root password mysqladmin -u root password 'kaishi'
这里的“密码”为我们欲新设的密码。系统会提示我们输入旧密码(若是 MySQL 刚安装,则默认密码为空)
如果本机可以登陆了,但是其他机器的客户端登陆报错。比如:
ERROR 1130 (00000): Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQ L server
则首先查看了 iptables 的设置,确认开放了 3306 端口:
iptables -A INPUT -p tcp -m tcp --sport 3306 -j ACCEPT iptables -A OUTPUT -p tcp -m tcp --dport 3306 -j ACCEPT service iptables save
如果还是无法访问,则可能是 MySQL 的权限问题。则可以通过如下步骤排查:
mysql -h localhost -u root -pkaishi show databases; use mysql; select Host, User, Password from user; +-----------------------+------+-------------------------------------------+ | Host | User | Password | +-----------------------+------+-------------------------------------------+ | localhost | root | *18F54215F48E644FC4E0F05EC2D39F88D7244B1A | | localhost.localdomain | root | | | localhost.localdomain | | | | localhost | | | +-----------------------+------+-------------------------------------------+
grant select,update,insert,delete on easyview.* to sillycat@192.168.10.103 identified by "kaishi";
use mysql; select host,user,password from user;
update user set host = '%' where user = 'sillycat'; flush privileges;