A, Docker MySQL Cluster installation simulation
1, download the image
docker pull mysql:5.7
2. Create Master instance and launch
3306 RUN -p Docker: 3306 --name MySQL-Master \ -v / mydata / MySQL / Master / log: / var / log / MySQL \ -v / mydata / MySQL / Master / Data: / var / lib / MySQL \ -v / mydata / MySQL / master / the conf: / etc / MySQL \ -e = MYSQL_ROOT_PASSWORD the root \ -d MySQL: 5.7 parameter Description -p 3307: 3306: 3306 mapped to port 3307 of the container port of the host -v / mydata / mysql / master / conf : / etc / mysql: hanging folder configuration to the host -v / mydata / mysql / master / log: / var / log / mysql: log folder mounted to the host l -v / mydata / mysql / master / data: / var / lib / mysql /: the host to mount configuration folder -e MYSQL_ROOT_PASSWORD = root: initializing root password
Modify the master configuration file
Modified master basic configuration Vim /mydata/mysql/master/conf/my.cnf [Client] default = UTF8-Character-SET [MySQL] default = UTF8-Character-SET [mysqld] init_connect = '= the SET collation_connection utf8_unicode_ci' init_connect = 'the SET NAMES UTF8' Character-Server-SET = UTF8 collation = utf8_unicode_ci-Server
skip-Character-SET-Client-Handshake skip-name-resolve
# skip DNS Note: skip-name-resolve must be added, or connected mysql It will be super slow
Add master primary configuration from the reproducing section the server_id =. 1 log-bin = MySQL-bin Read-only = 0 the binlog-do-DB = gmall_ums the binlog-do-DB = gmall_pms the binlog-do-DB = gmall_oms the binlog-do-DB = gmall_sms -do-db = binlog gmall_cms replicate the ignore-ignore-db = # MySQL database replicate the ignore-db = SYS- replicate-the ignore-db = information_schema replicate-the ignore-db = performance_schema
3. Create Slave instance and launch
docker run -p 3316:3306 --name mysql-slaver-01 \ -v /mydata/mysql/slaver/log:/var/log/mysql \ -v /mydata/mysql/slaver/data:/var/lib/mysql \ -v /mydata/mysql/slaver/conf:/etc/mysql \ -e MYSQL_ROOT_PASSWORD=root \ -d mysql:5.7
Modify slave configuration files
修改slave基本配置 vim /mydata/mysql/slaver/conf/my.cnf [client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve
修改slave基本配置 vim /mydata/mysql/slaver/conf/my.cnf [client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8 collation-server=utf8_unicode_ci skip-character-set-client-handshake skip-name-resolve
4, in order to master his authorized users to synchronize data
1, the container enters the master Docker Exec Expediting IT mysql / bin / the bash 2, into the interior of mysql (mysql -uroot--p) 1), root can remotely access authorization (independent from the main, in order to facilitate remote connection we mysql) Grant All privileges ON . * * to 'the root' @ '%' IDENTIFIED by 'the root' with Grant Option; the flush privileges; 2), was added to a synchronized user GRANT REPLICATION SLAVE ON * * to ' backup' @ '%' identified by '. 123456 '; 3, view the status of master show master status \ G;
5, master data synchronization configuration slaver
1, the container enters the slaver Docker mysql-slaver Exec Expediting IT-01 / bin / the bash 2, into the interior of mysql (mysql -uroot--p) 1), root can remotely access authorization (independent from the main, in order to facilitate remote connection we mysql) . * * Grant All privileges to ON 'the root' @ '%' IDENTIFIED by 'the root' with Grant Option; the flush privileges; 2), set the main database connection change master to master_host = '192.168.159.128' , master_user = 'backup' , master_password = '123456', MASTER_LOG_FILE = 'MySQL-bin.000001', MASTER_LOG_POS = 0, MASTER_PORT = 3307; . 3), starting from the synchronization database start Slave; . 4), from the library to view the state show slave status \ G;
Thus complete master slave configuration;
to sum up:
1), master-slave database in its own configuration file statement which needs to be synchronized database, database and other information which is ignored. And server-id can not be the same
2), the main library authorize an account password to synchronize your data
3), from the library using the account password to connect the primary repository to synchronize data