Navicat connection to the database on the server Tencent cloud

Described below are two database servers on the cloud Tencent Navicat connection:

Method One: [do not need to modify remote connection client privilege]

Click on the desktop installed navicat icon, enter the following figure:

Connections: SSH , enter the server outside the network's own ip address, account number and password to log server

As shown below:

 

Then set the general properties, the connection to the database, fill in the host localhost , because mysql installed on a local server, and then fill in the user name and password mysql

As shown below:

 

 

Method Two: Modify the relevant authority MySQL remote client connections]

The following command is the best in the root performed using the user: [Otherwise, some files may be blocked modify permissions problem, you need to modify user permissions to the file manually]

1 , we need to change the 3306 port, see the 3306 port is open, and the general MySQL by default is not open to outside access functions.

Use the following statement to query:

 

# netstat -an | grep 3306

If the query results are as follows, then we need to change the MySQL configuration file.

查询结果可以看出,MySQL3306端口只是监听本地的连接,这样就阻碍了外部IP对该数据库的访问,修改 MySQL 配置文件:

# /etc/mysql/mysql.conf.d/mysqld.cnf

在MySQL配置文件中找到  bind-address = 127.0.0.1 这一行

bind-address = 127.0.0.1 这行注释掉或者改为你想要使用的客户端主机 ip如下图所示:

 

 

这样,我们的 MySQL 远程访问端口就开启成功了。

 

2、我们进入 MySQL 命令界面,运行下列SQL 语句:

 

使用下面命令先在服务器终端上登录mysqlroot用户

 

# mysql -uroot -p

 

然后输入root用户密码就可以登录mysql了

 

使用下面命令切换为使用mysql数据库

 

mysql> use mysql; 

 

使用下面命令查看用户是否具有访问权限:

 

mysql> select user, host from user;

 

如下图所示

 

上面显示root用户只用访问本地的权限,我们需要通配符 % 来修改 root 用户对应的 host 字段,使其具有访问所有 ip 地址的权限:

mysql> update user set host = '%' where user = 'root';

如下图所示:

 

如果抛出如下异常:

Duplicate entry '%-root' for key 'PRIMARY'

说明有多个root用户纪录在user表中了,我们重新执行下面命令就可以看到字段 host %

mysql> select host from user where user = 'root';

我们执行:

mysql> flush privileges;

刷新一下 MySQL 的系统权限相关表。

下面还要确认的一件事就是确认客户端用户是否具有权限,我们给与他们相应的访问权限:

mysql> grant all privileges on *.* to username@"%" identified by "password";

最后退出mysql重启一下 MySQL 服务:

mysql> exit;   //退出mysql
#sudo mysql restart   //重启mysql服务

3服务端设置好了,我们在 Navicat 客户端设置一下连接:

打开 Navicat软件,点击左上方的 "连接",设置一下数据库的连接名,服务器外网ip地址,mysql用户名及密码等,

点击测试连接成功后再点击确定按钮便能在 Navicat 中远程操作服务器上的 MySQL 了。

如下图所示:

 

 

到这里,Navicat连接腾讯云服务器上的数据库的两种方法就结束了,希望可以帮助大家。。。

Guess you like

Origin www.cnblogs.com/nzcblogs/p/11141023.html
Recommended