本文主要是介绍Mysql--sqlyog远程连接,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下载安装MySQL
我们在MySQL官方网站中找到我们对应系统的MySQL安装包(如果需要别的安装包可以在下方网站内查找),这里我用redhat9作为演示
MySQL :: Download MySQL Community Server (Archived Versions)
这里我们选择第一个下载到我们主机
安装MySQL
下载完之后我们开启我们的虚拟机,使用xshell以及xftp上传我们下载的安装包,直接拖拽即可
然后我们在xshell中进行操作
下载过后发现这里是一个tar包(但是tar包并不是压缩文件),可以先查看是否有tar命令,如果没有可以直接使用yum命令下载。
[root@node1 mysql]# yum install tar
解开tar包
rpm包安装MySQL
这里我们不需要全部安装,只需要安装一部分足以让我们MySQL正常运行
common>libs>client>server
[root@node1 mysql]# rpm -ivh mysql-community-common-8.0.35-1.el9.x86_64.rpm [root@node1 mysql]# rpm -ivh mysql-community-client-plugins-8.0.35-1.el9.x86_64.rpm [root@node1 mysql]# rpm -ivh mysql-community-libs-8.0.35-1.el9.x86_64.rpm [root@node1 mysql]# rpm -ivh mysql-community-icu-data-files-8.0.35-1.el9.x86_64.rpm [root@node1 mysql]# rpm -ivh mysql-community-server-8.0.35-1.el9.x86_64.rpm [root@node1 mysql]# rpm -ivh mysql-community-client-8.0.35-1.el9.x86_64.rpm [root@node1 mysql]# rpm -ivh mysql-community-server-8.0.35-1.el9.x86_64.rpm
开启MySQL服务,查看状态
[root@node1 mysql]# systemctl start mysqld
[root@node1 mysql]# systemctl status mysqld
● mysqld.service - MySQL ServerLoaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor pres>Active: active (running) since Wed 2024-03-27 16:21:29 CST; 8s ago
登录MySQL
这时候登录MySQL是登录不了的,因为MySQL自身在日志内生成了一个随机密码,先获取密码再登录
[root@node1 mysql]# grep password /var/log/mysqld.log
2024-03-27T08:21:22.876557Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ytx)US5:uwdj
[root@node1 mysql]# mysql -uroot -p
Enter password:
修改密码
mysql> alter user root@localhost identified by 'Mysql@123';
Query OK, 0 rows affected (0.02 sec)
这时候我们尝试通过sqlyog进行远程登录操作
1130:Host ‘IP‘ is not allowed to connect to this MySQL server
这个问题是因为我们的登录MySQL的用户的权限只允许我们的localhost账户进行操作,所以需要修改权限。
mysql> select user,host,plugin from mysql.user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.01 sec)#增加权限命令
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> flush privileges; #刷新权限表
Query OK, 0 rows affected (0.01 sec)mysql> select user,host from user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | % |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
现在我们root的host已经改变为%,可以允许ssh远程访问。再次尝试登录
2508报错
但是现在我们又报错2058
这个是因为我们密码的加密方式不被sqlyog所认同(sqlyog版本的问题),所以并不能进去。
mysql> select user,host,plugin from mysql.user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | % | caching_sha2_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)###改变MySQL加密方式alter user root@localhost identified with mysql_native_password by 'Mysql@123';
Query OK, 0 rows affected (0.00 sec)mysql> select user,host,plugin from mysql.user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)
现在再次访问,就可以从sqlyog访问MySQL
这篇关于Mysql--sqlyog远程连接的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!