一、密码错误
报错日志:pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)")
出现这个问题的时候是密码错误,需要确认mysql登录密码
二、链接超时
报错日志:pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '192.168.200.58' (timed out)")
出现这个问题是链接服务超时,可能的原因是因为机器开了防火墙,关闭防护墙即可
执行命令
systemctl stop firewalld.service #关闭防火墙
三、访问服务被拒
报错日志:pymysql.err.OperationalError: (1130, "192.168.200.38' is not allowed to connect to this MySQL server")
这个问题是因为mysql限制了本机访问,其他机器想要访问需要修改user表
1.登录mysql
mysql -u root -p
2.进入mysql表
use mysql
3.修改user表中root用户的host,原host值为localhost,修改为%,任意机器可访问,也可修改为指定的host
update user set Host="%" where User="root";