Rumah >pangkalan data >tutorial mysql >Cara menggunakan Docker untuk menggunakan MySQL5.7&8.0 kelompok hamba induk
> Gunakan mysql 5.7 cluster master & slave (untuk ujian sahaja)
Cermin versi 5.7
1 Cipta rangkaian tindanan
docker network create --driver overlay common-network --attachable
2. Edit dua fail konfigurasi master.cnf dan slave.cnf
!includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ [mysqld] log-bin=mysql-bin server-id=1 gtid-mode=on enforce-gtid-consistency=on
!includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/ [mysqld] server-id=2 gtid-mode=on enforce-gtid-consistency=on
3 Mulakan 2 mysql: mysql-master, mysql-slave
docker run -d \ --name mysql-master \ --network common-network \ -e mysql_root_password=passw0rd \ -v `pwd`/master.cnf:/etc/mysql/my.cnf \ -p 3306:3306 \ -d mysql:5.7rreee
4. Tambahkan pengguna untuk replikasi daripada pustaka
docker run -d \ --name mysql-slave \ --network common-network \ -e mysql_root_password=passw0rd \ -v `pwd`/slave.cnf:/etc/mysql/my.cnf \ -p 3307:3306 \ -d mysql:5.7
5. Sambungkan tuan & hamba
docker run -it --rm --network common-network mysql mysql -hmysql-master -uroot -ppassw0rd \ -e "create user 'repl'@'%' identified by 'password' require ssl; " \ -e "grant replication slave on *.* to 'repl'@'%';"
6
Status berikut adalah normal:
slave_io_running: yes
slave_sql_running: yes
> Gunakan mysql 8.0 cluster master & slave (untuk ujian sahaja )
Mirror version mysql:8.0
1 Cipta rangkaian tindanan
docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -ppassw0rd \ -e "change master to master_host='mysql-master', master_port=3306, master_user='repl', master_password='password', master_auto_position=1, master_ssl=1;" \ -e "start slave;"
docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -ppassw0rd -e "show slave status\g"
docker network create --driver overlay common-network --attachable
docker run -d \ --name mysql-master \ --network common-network \ -e mysql_root_password=passw0rd \ -p 3306:3306 \ -d mysql --default-authentication-plugin=mysql_native_password
docker run -d \ --name mysql-slave \ --network common-network \ -e mysql_root_password=passw0rd \ -p 3307:3306 \ -d mysql --default-authentication-plugin=mysql_native_password
docker run -it --rm --network common-network mysql mysql -hmysql-master -uroot -ppassw0rd \ -e "set persist server_id=1;" \ -e "set persist_only gtid_mode=on;" \ -e "set persist_only enforce_gtid_consistency=true; " \ -e "create user 'repl'@'%' identified by 'password' require ssl; " \ -e "grant replication slave on *.* to 'repl'@'%';"
docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -ppassw0rd \ -e "set persist server_id=2;" \ -e "set persist_only gtid_mode=on;" \ -e "set persist_only enforce_gtid_consistency=true; "
docker restart mysql-master mysql-slave
slave_io_running: yes
slave_sql_running: yes 🎜>
> Sahkan penyegerakan data
Buat pangkalan data anoyi pada master
docker run -it --rm --network common-network mysql mysql -hmysql-slave -uroot -ppassw0rd \ -e "change master to master_host='mysql-master', master_port=3306, master_user='repl', master_password='password', master_auto_position=1, master_ssl=1;" \ -e "start slave;"
Lihat senarai pangkalan data pada hamba
Atas ialah kandungan terperinci Cara menggunakan Docker untuk menggunakan MySQL5.7&8.0 kelompok hamba induk. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!