一、准备工作
1、已安装跳板机,示例IP:192.168.0.26,操作系统为ubuntu
2、已安装MySQL 8.0,本示例安装的是ubuntu系统支持的mysql 8.0版本(参考:https://bbs.huaweicloud.com/blogs/412913),示例IP:192.168.0.60
二、注意事项
1、mysql 8.0有多个配置文件,要找到正确的配置文件。
三、实现步骤
1、MySQL服务端授权配置
(1)指定可访问远程IP
vim /etc/mysql/mysql.conf.d/mysqld.cnf
更新配置
bind-address = *
mysqlx-bind-address = *
可以授权任何IP访问;也可以指定IP访问,如:192.168.0.26,当有多个IP时,中间用逗号隔开。
(2)访问授权配置
mysql -u root -p
输入password:
进入mysql> 控制台
按顺序执行以下授权指令:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密码';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
2、跳板机的操作
(1)安装Mysql-client
sudo apt-get install mysql-client
(2)通过客户端访问验证
mysql -h 192.168.0.60 -u root -p
回车,输入password:
显示以下内容则说明连接成功:
root@host:~# mysql -h 192.168.0.60 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.39-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
3、本地数据库连接工具测试,以Navicate为例:
配置数据库所在服务信息:
配置跳板机服务器信息,其中主机为外网可访问的IP或域名地址: