查找原因
- 数据库连接url是否正确?
- 用户名密码是否正确?
- MySQL是否允许远程访问?
MySQL允许远程访问方法
- 修改user表
mysql -u root –p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
- 授权
//1.允许root用户从任何主机使用密码123456登录
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
//2.允许someone用户使用密码123456从10.10.50.127登录
mysql>GRANT ALL PRIVILEGES ON *.* TO 'someone'@’10.10.50.127’ IDENTIFIED BY '123456' WITH GRANT OPTION;
//3.赋予任何主机访问数据的权限
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
//刷新
mysql>FLUSH RIVILEGES;