欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

mysql多主從集群搭建

錢瀠龍1年前9瀏覽0評論

MySQL多主從集群是一種常見的數據庫架構,能夠提高數據庫的可用性和擴展性。以下是MySQL多主從集群的搭建流程:

步驟一:安裝MySQL

$ apt-get update
$ apt-get install mysql-server

步驟二:創建并配置主節點

$ sudo systemctl stop mysql
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

在mysqld.cnf中添加以下配置:

server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = my_database

然后重啟MySQL:

$ sudo systemctl start mysql

步驟三:創建并配置從節點

$ sudo systemctl stop mysql
$ sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

在mysqld.cnf中添加以下配置:

server-id = 2
relay-log = /var/log/mysql/mysql-relay-bin.log
log_slave_updates = 1
read_only = 1

然后重啟MySQL:

$ sudo systemctl start mysql

步驟四:創建主從關系

mysql>CREATE USER 'repl'@'%' IDENTIFIED BY 'password';
mysql>GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
mysql>FLUSH PRIVILEGES;
mysql>SHOW MASTER STATUS;

記下輸出的File和Position。

mysql>STOP SLAVE;
mysql>CHANGE MASTER TO
->MASTER_HOST='master_ip_address',
->MASTER_USER='repl',
->MASTER_PASSWORD='password',
->MASTER_LOG_FILE='xxxx.log',
->MASTER_LOG_POS=xxxx;
mysql>START SLAVE;

步驟五:測試多主從集群

mysql>INSERT INTO my_database.my_table (id, data) VALUES (1, 'test data');

然后在從節點上查詢,應該可以看到插入的數據。

mysql>SELECT * FROM my_database.my_table;

以上就是MySQL多主從集群的搭建過程。