1、服務器的環境:mysql
[root@VM_82_178_centos ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [root@VM_82_178_centos ~]# 本地雲主機安裝有mysql-proxy-0.8.5 採用二進制安裝mysql5.7
2、mysql-proxy安裝過程請看考以下連接:
http://www.javashuo.com/article/p-nnjmwhko-cs.htmllinux
3、mysql-proxy配置文件以下:sql
[root@VM_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
4、啓動命令:數據庫
/usr/local/mysql-proxy-0.8.5/bin/mysql-proxy --defaults-file=/data/mysql-proxy/conf/mysql-proxy [root@VM_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))
5、mysql client版本測試:
mysql5.7的客戶端mysql的開到此處登陸不到後端的mysql server後端
[root@VM_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 [root@VM_82_178_centos ~]# [root@VM_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 servercentos
[root@VM_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) [root@VM_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安全
[root@VM_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 [root@VM_82_178_centos bin]# /usr/local/mysql5.6.39/bin/mysql -uroot -p'69jianwuweimysql' -h10.135.82.178 -P9198
mysql5.5的客戶端mysql的能夠登陸後端的mysql server服務器
[root@VM_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 [root@VM_82_178_centos ~]# [root@VM_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. root@10.135.82.178 [(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:app
[root@VM_82_178_centos bin]# rpm -qa|grep mariadb [root@VM_82_178_centos bin]# rpm -qa|grep mariadb centos7的系統上安裝mysql client的方式: yum install -y mariadb.x86_64 mariadb-libs.x86_64 [root@VM_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 [root@VM_82_178_centos bin]# mysql -V mysql Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1 [root@VM_82_178_centos bin]# [root@VM_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. root@10.135.82.178 [(none)]>show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test01 | | test02 | +--------------------+ 6 rows in set (0.00 sec)
6、登陸雲主機本地的mysql server,受權一個帳戶測試mysql-proxy代理後端數據庫應用:tcp
建立測試帳戶:
root@localhost [(none)]>grant all on test01.* to mpuser@'%' identified by '69jianwuweimysql'; Query OK, 0 rows affected, 1 warning (0.13 sec) root@localhost [(none)]>flush privileges; Query OK, 0 rows affected (0.10 sec)
登陸測試:
[root@VM_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. mpuser@10.135.82.178 [(none)]>show databases; +--------------------+ | Database | +--------------------+ | information_schema | | test01 | +--------------------+ 2 rows in set (0.00 sec) mpuser@10.135.82.178 [(none)]>\q
經過雲控制檯的安全組,受權特定的外網ip,容許訪問本雲主機的數據庫:
在遠程的物理機器登陸遠端的雲主機數據庫:
[root@127 ~]# /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)
到此處簡單的講解和演示完畢