Centos7怎么让本地服务器的mysql支持另一个服务器?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7怎么让本地服务器的mysql支持另一个服务器?相关的知识,希望对你有一定的参考价值。

参考技术A
    授权远程访问grant授权命令开通防火墙端口firewalld-cmd操作
参考技术B 两个步骤,第一个步骤是在centos中开通3306端口,这是mysql使用的。
第二是在mysql数据库中开通用户的远程访问权限,在别的服务器也可以访问这台服务器上的mysql数据库服务。

mysql-proxy不再支持mysql5.7的client客户端登录

一、服务器的环境:

[[email protected]_82_178_centos ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[[email protected]_82_178_centos ~]# 
本地云主机安装有mysql-proxy-0.8.5
采用二进制安装mysql5.7

二、mysql-proxy安装过程请看考如下链接:
https://blog.51cto.com/wujianwei/2087871

三、mysql-proxy配置文件如下:


[[email protected]_82_178_centos ~]# cat /data/mysql-proxy/conf/mysql-proxy 
[mysql-proxy]
user=mysql-proxy
daemon=true
keepalive=true
###日志级别
log-level=info
log-file=/data/mysql-proxy/log/mysql-proxy.log
pid-file =/data/mysql-proxy/log/mysql-proxy.pid
###本机ip地址
proxy-address=0.0.0.0:9198
#admin-address=127.0.0.1:9197
##backend主   注意addresses
proxy-backend-addresses=10.135.82.178

四、启动命令:

/usr/local/mysql-proxy-0.8.5/bin/mysql-proxy --defaults-file=/data/mysql-proxy/conf/mysql-proxy
[[email protected]_82_178_centos ~]# ss -lntup|grep mysql
tcp    LISTEN     0      128       *:9198                  *:*                   users:(("mysql-proxy",pid=7855,fd=10))
tcp    LISTEN     0      128      :::3306                 :::*                   users:(("mysqld",pid=5665,fd=31))

五、mysql client版本测试:
mysql5.7的客户端mysql的开到此处登录不到后端的mysql server

[[email protected]_82_178_centos ~]# /usr/local/mysql7/bin/mysql -V
/usr/local/mysql7/bin/mysql  Ver 14.14 Distrib 5.7.24, for linux-glibc2.12 (x86_64) using  EditLine wrapper
[[email protected]_82_178_centos ~]# 

[[email protected]_82_178_centos ~]# /usr/local/mysql7/bin/mysql -uroot -p‘69jianwuweimysql‘ -h10.135.82.178 -P9198
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.

mysql8.0的客户端mysql的开到此处登录不到后端的mysql server


[[email protected]_82_178_centos bin]# /usr/local/mysql8013/bin/mysql -V
/usr/local/mysql8013/bin/mysql  Ver 8.0.13 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL)
[[email protected]_82_178_centos bin]# /usr/local/mysql8013/bin/mysql -uroot -p‘69jianwuweimysql‘ -h10.135.82.178 -P9198
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.

mysql5.6的客户端mysql的可以登录后端的mysql server

[[email protected]_82_178_centos bin]# /usr/local/mysql5.6.39/bin/mysql -V
/usr/local/mysql5.6.39/bin/mysql  Ver 14.14 Distrib 5.6.39, for linux-glibc2.12 (x86_64) using  EditLine wrapper
[[email protected]_82_178_centos bin]#  /usr/local/mysql5.6.39/bin/mysql -uroot -p‘69jianwuweimysql‘ -h10.135.82.178 -P9198

mysql5.5的客户端mysql的可以登录后端的mysql server

[[email protected]_82_178_centos ~]# /usr/local/mysql5.5/bin/mysql -V
/usr/local/mysql5.5/bin/mysql  Ver 14.14 Distrib 5.5.60, for linux-glibc2.12 (x86_64) using readline 5.1
[[email protected]_82_178_centos ~]# 

[[email protected]_82_178_centos ~]# /usr/local/mysql5.5/bin/mysql -uroot -p‘69jianwuweimysql‘ -h10.135.82.178 -P9198 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 38033
Server version: 5.7.24-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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.

[email protected] [(none)]>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test01             |
| test02             |
+--------------------+
6 rows in set (0.13 sec)

mariadb5.5的版本测试可以通过mysql-proxy登录后端的mysql server:


[[email protected]_82_178_centos bin]# rpm -qa|grep mariadb
[[email protected]_82_178_centos bin]# rpm -qa|grep mariadb

centos7的系统上安装mysql client的方式:
yum install -y mariadb.x86_64 mariadb-libs.x86_64

[[email protected]_82_178_centos bin]# rpm -qa|grep mariadb
mariadb-5.5.60-1.el7_5.x86_64
mariadb-libs-5.5.60-1.el7_5.x86_64

[[email protected]_82_178_centos bin]# mysql -V
mysql  Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1
[[email protected]_82_178_centos bin]# 

[[email protected]_82_178_centos bin]# mysql -uroot -p‘69jianwuweimysql‘ -h10.135.82.178 -P9198
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MySQL connection id is 38323
Server version: 5.7.24-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.

[email protected] [(none)]>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test01             |
| test02             |
+--------------------+
6 rows in set (0.00 sec)

六、登录云主机本地的mysql server,授权一个账户测试mysql-proxy代理后端数据库应用:

创建测试账户:

[email protected] [(none)]>grant all on test01.* to [email protected]‘%‘ identified by ‘69jianwuweimysql‘;
Query OK, 0 rows affected, 1 warning (0.13 sec)

[email protected] [(none)]>flush privileges;
Query OK, 0 rows affected (0.10 sec)

登录测试:

[[email protected]_82_178_centos ~]# mysql -umpuser -p‘69jianwuweimysql‘ -h10.135.82.178 -P9198
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MySQL connection id is 74544
Server version: 5.7.24-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;‘ or ‘h‘ for help. Type ‘c‘ to clear the current input statement.

[email protected] [(none)]>show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test01             |
+--------------------+
2 rows in set (0.00 sec)

[email protected] [(none)]>q

通过云控制台的安全组,授权特定的外网ip,允许访问本云主机的数据库:

技术图片

在远程的物理机器登录远端的云主机数据库:


[[email protected] ~]# /usr/local/mysql5.5/bin/mysql -umpuser -p‘69jianwuweimysql‘ -h119.29.97.131 -P9198
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 74679
Server version: 5.7.24-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test01             |
+--------------------+
2 rows in set (0.04 sec)

到此处简单的讲解和演示完毕

以上是关于Centos7怎么让本地服务器的mysql支持另一个服务器?的主要内容,如果未能解决你的问题,请参考以下文章

阿里云centos7服务器怎么备份mysql数据库

centos7下mysql5.6的主从复制

[centos同步数据库]CentOS7, mysql主从同步数据库配置

远程 Spring 启动应用程序仍然连接到我的本地 mysql

在CentOS7上部署MySQL-MMM高可用群集

centos7怎么rpm安装mysql5.7