当前位置:网站首页>How Navicat connects to MySQL on a remote server
How Navicat connects to MySQL on a remote server
2022-08-03 15:32:00 【Lovely hair】
本文已参与「新人创作礼」活动,一起开启掘金创作之路.
前言:
==Operating environment and tools==
Navicat for Mysql
One Tencent Cloud lightweight server(Centos 7)
Mysql 8.0.24(installed on the remote server)
Xshell7(连接操作远程服务器)
一、修改mysqlremote authorization login settings
1、Log in to the database of the remote server(使用Xshell)
mysql -uroot -p ## 以root登录数据库
复制代码
输入root的登录密码,After success, you will see the following information:
2、查看mysqlThe current default port for the service
use mysql; ## 选择mysql数据库
select user,host from user; ## View user access ports
复制代码
==说明:rootThe user default islocalhost,Note that only local login is allowedmysql服务.And we're going to take it remotelyroot用户连接数据库,就必须修改host的值,改为**'%'**:允许任何ip访问.==
3.修改host允许任何ip访问
Go ahead and enter the following commands in the command palette:
update user set host = '%' where user = 'root';
复制代码
Seeing the above information indicates that the modification is successful!
Then use the previous command again:
select user,host from user; ## View user access ports
复制代码
会看到:root用户的host已经修改为'%'!
==注意:修改完成后 Also need to refresh the service configuration,不然修改不会生效,并且第4step will fail.==
Then type in the command panel:
mysql> FLUSH PRIVILEGES; ## Refresh service configuration items
复制代码
显示Query OK,表示刷新完成.Now we can configure the user permissions we want to log in remotely.
4.授权root用户进行远程登录
输入命令:
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root_pwd'; ## 授权root远程登录 后面的root_pwdRepresents the login password
复制代码
输入完之后,看到Query OK,说明执行成功!
==说明:This command can authorize any mysql数据库userThe users in the table access the database by remote login,本例中以'root'作为举例,To authorize other users,只需修改'root'The value of the specified user can be used,'root_pwd'为'root'User's corresponding login password,It can be modified to the login password of the user you want to authorize.==
5.启动本地Navicat连接
打开Navicat客户端,新建mysql连接
输入相关信息:
If it shows that the connection is successful,那么恭喜你,The database can be operated remotely
==如果显示2003错误,无法连接上数据库,Please continue to see the operation below==
二、Solve the problem of unable to connect(2003)
1、First make sure that the firewall is allowed3306端口
2、Make sure fire prevention is activated
==未启动==
[[email protected] ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
FirewallD is not running
[[email protected] ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead) #Indicates that the fire resistance is not activated
Docs: man:firewalld(1)
复制代码
==已启动==
[[email protected] ~]# systemctl start firewalld
[[email protected] ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2021-03-07 20:57:40 CST; 9s ago #active (running)Indicates that the firewall is activated
Docs: man:firewalld(1)
Main PID: 29918 (firewalld)
CGroup: /system.slice/firewalld.service
└─29918 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
复制代码
3、放通防火墙
[[email protected] ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
复制代码
4、Re-add firewall rules
[[email protected] ~]# firewall-cmd --permanent --add-port=3305/tcp
success
[[email protected] ~]# firewall-cmd --reload
success
复制代码
==然后继续使用Navicatto connect==
边栏推荐
猜你喜欢
随机推荐
How to use binary search and find whether the rotation in the array contains a (target) value?Rotate the sorted array leetcode 81. Search
身为售后工程师的我还是觉得软件测试香,转行成功定薪11.5K,特来分享下经验。
随笔-Unity中一个简易的Spine动画控制器
问题3:你提交的缺陷开发认为这不是BUG,怎么办?
语音识别新一轮竞争打响,自然对话会是下一个制高点吗?
分享一款免费OPC UA服务器
有希望就是好的
高压直流输电(HVDC)的最优潮流(OPF)(Matlab代码实现)
How to play deep paging with hundreds of millions of data?Compatible with MySQL + ES + MongoDB
教你如何获取微信公众号历史文章链接
2022年镇海夏令营组合数学和数论班 —— 数学作业 1
问题6:下拉框测试点
16 【过渡 动画】
js数组方法总结
6000 字+,帮你搞懂互联网架构演变历程!
上亿数据怎么玩深度分页?兼容MySQL + ES + MongoDB
Use Typora+EasyBlogImageForTypora to write a blog and upload pictures quickly without a picture bed
Js array method is summarized
问题4:什么是缺陷?你们公司缺陷的优先级是怎样划分的?
程序员面试必备PHP基础面试题 – 第二十天