远程连接MySQL出现host is not allowed to connect to this mysql server
我在阿里云上建了个MySQL的数据库,用自带的MySQL client能启动,可是在cmd里输入:mysql -uroot -p
显示 mysql不是内部命令也不是可运行的程序,发现原来环境变量没配,配置如下:
- 选择Mysql安装的目录,在Mysql安装的目录中找到bin目录,把此路径复制。
- 我的电脑右键–>属性–>高级系统设置–>高级–>环境变量–>系统变量–>path–>在path变量中添加变量值,变量值为刚复制的路径
- 打开cmd输入mysql -u root -p后系统响应,再输入口令就行了,即可进入到Mysql
然后我在本地电脑上用Navicat for MySQL这个软件连接阿里云的MySQL数据库,出现host is not allowed to connect to this mysql server的错误,这是阿里云上的数据库没有授权给远程访问,解决方法如下:
-
首先授权远程访问的端口(阿里云上启动多个Tomcat修改端口后授权方法也是如此):
2.找到所在区,因为我是华东的,所以选择如下:
3.
4.
5.
6.
7.再远程控制阿里云服务器上:1、登录MySQL mysql -u root -p密码 2、执行use mysql;
3、执行update user set host = '%' where user = 'root';
4、执行FLUSH PRIVILEGES;
8.再到本地打开Navicat连接,可以了: