DruidDataSource : create connection error, url: jdbc:mysql://x.xxx.xxx.xxx:3306/miaosha, errorCode 1130, state HY000
java.sql.SQLException: null, message from server: "Host 'x.xxx.xxx.xxx' is not allowed to connect to this MariaDB server"
当我们在本地做完一些项目(需要访问mysql数据库),并且想布置到云服务器上,于是把项目打包上传,并且将本地数据库数据备份下来也上传到云服务器上后,尝试在云服务器上启动该项目,却发现了如下异常:
其实这个异常是数据库只允许 localhost 或 127.0.0.1 访问,不允许远程访问。
解决方案:修改访问权限即可
具体操作步骤如下:
首先进入数据库:
mysql -uroot -proot
进入mysql
use mysql;
查看权限
select host,user from user;
我们发现 root 对应的 host 是 localhost,表示只允许本机访问,我们需要把他改为 %
update user set host ='%' where user ='root' and host ='localhost';
最后刷新一下权限
flush privileges;