SAVE MYSQL SERVERS TO DISK; SAVE MYSQL USERS TO DISK; SAVE MYSQL QUERY RULES TO DISK; SAVE MYSQL VARIABLES TO DISK; LOAD MYSQL SERVERS TO RUNTIME; LOAD MYSQL USERS TO RUNTIME; LOAD MYSQL QUERY RULES TO RUNTIME; LOAD MYSQL VARIABLES TO RUNTIME;
apt-get install -y --no-install-recommends lsb-release wget apt-transport-https ca-certificates gnupg wget -O - 'https://repo.proxysql.com/ProxySQL/proxysql-2.7.x/repo_pub_key' | apt-key add - echo deb https://repo.proxysql.com/ProxySQL/proxysql-2.7.x/$(lsb_release -sc)/ ./ | tee /etc/apt/sources.list.d/proxysql.list
sudo apt update sudo apt install proxysql -y
sudo systemctl start proxysql sudo systemctl enable proxysql
mysql -u admin -p -h 127.0.0.1 -P 6032
# 寫入用 INSERT INTO mysql_servers (hostgroup_id, hostname, port) VALUES (10, '10.0.0.1', 3306); # Read only INSERT INTO mysql_servers (hostgroup_id, hostname, port) VALUES (20, '10.0.0.2', 3306);
INSERT INTO mysql_users (username, password, default_hostgroup, transaction_persistent) VALUES ('root', 'PASSWORD', 10, 1);
SET mysql-ssl_p2s_ca = '/mysql-cert/mysql-server-ca.pem'; SET mysql-ssl_p2s_cert = '/mysql-cert/mysql-client-cert.pem'; SET mysql-ssl_p2s_key = '/mysql-cert/mysql-client-key.pem'; SAVE MYSQL VARIABLES TO DISK; LOAD MYSQL VARIABLES TO RUNTIME;
# read only (destination_hostgroup: 20) INSERT INTO mysql_query_rules (rule_id, active, match_pattern, destination_hostgroup, apply) VALUES (1, 1, '^SELECT .*', 20, 1); # read/write (destination_hostgroup: 10) INSERT INTO mysql_query_rules (rule_id, active, match_pattern, destination_hostgroup, apply) VALUES (2, 1, '.*', 10, 1);
SAVE MYSQL SERVERS TO DISK; SAVE MYSQL USERS TO DISK; SAVE MYSQL QUERY RULES TO DISK; LOAD MYSQL SERVERS TO RUNTIME; LOAD MYSQL USERS TO RUNTIME; LOAD MYSQL QUERY RULES TO RUNTIME;
SELECT * FROM runtime_mysql_servers;