谷粒商城创建mysql主从(十三)
361-363 创建mysql主从
STEP 1 启动主从
[ ~]# docker run -p 3307:3306 --name mysql-master -v /mydata/mysql/master/conf:/etc/mysql -v /mydata/mysql/master/logs:/var/log/mysql -v /mydata/mysql/master/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7 6a7d36b510b618d8d7c4d408051004153f95644dc4ab09fdcc9d1e1b19d97c5e [ ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6a7d36b510b6 mysql:5.7 "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 33060/tcp, 0.0.0.0:3307->3306/tcp mysql-master 961ab799c1fe redis "docker-entrypoint.s…" 12 days ago Up 11 days 0.0.0.0:6379->6379/tcp focused_kirch 4dd3eda0035b a4fdfd462add "docker-entrypoint.s…" 12 days ago Up 11 days 0.0.0.0:3306->3306/tcp, 33060/tcp mysql [ ~]# docker run -p 3317:3306 --name mysql-slave01 -v /mydata/mysql/slave/conf:/etc/mysql -v /mydata/mysql/slave/logs:/var/log/mysql -v /mydata/mysql/slave/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7 991c33239f50e49a0a99ecee5cf9d58b561635dbf688cf6d4359fbdfb4ac9456 [ ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 991c33239f50 mysql:5.7 "docker-entrypoint.s…" 14 seconds ago Up 13 seconds 33060/tcp, 0.0.0.0:3317->3306/tcp mysql-slave01 6a7d36b510b6 mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 33060/tcp, 0.0.0.0:3307->3306/tcp mysql-master 961ab799c1fe redis "docker-entrypoint.s…" 12 days ago Up 11 days 0.0.0.0:6379->6379/tcp focused_kirch 4dd3eda0035b a4fdfd462add "docker-entrypoint.s…" 12 days ago Up 11 days 0.0.0.0:3306->3306/tcp, 33060/tcp mysql [
STEP 2 修改配置文件
[ ~]# cat /mydata/mysql/master/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 server_id=1 log-bin=mysql-bin read-only=0 binlog-do-db=gulimall_ums binlog-do-db=gulimall_pms binlog-do-db=gulimall_oms binlog-do-db=gulimall_sms binlog-do-db=gulimall_wms binlog-do-db=gulimall-admin replicate-ignore-db=mysql replicate-ignore-db=sys replicate-ignore-db=information_schema replicate-ignore-db=performance_schema [ ~]# cat /mydata/mysql/slave/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 server_id=2 log-bin=mysql-bin read-only=1 binlog-do-db=gulimall_ums binlog-do-db=gulimall_pms binlog-do-db=gulimall_oms binlog-do-db=gulimall_sms binlog-do-db=gulimall_wms binlog-do-db=gulimall-admin replicate-ignore-db=mysql replicate-ignore-db=sys replicate-ignore-db=information_schema replicate-ignore-db=performance_schema [ ~]#
STEP3 主服务器授权
mysql> grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘root‘ with grant option -> ; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> grant replication slave on *.* to ‘backup‘@‘%‘ identified by ‘123456‘; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> show master status\G; *************************** 1. row *************************** File: mysql-bin.000001 Position: 889 Binlog_Do_DB: gulimall_ums,gulimall_pms,gulimall_oms,gulimall_sms,gulimall_wms,gulimall-admin Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec) ERROR: No query specified mysql> show master status -> ; +------------------+----------+---------------------------------------------------------------------------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+---------------------------------------------------------------------------------+------------------+-------------------+ | mysql-bin.000001 | 889 | gulimall_ums,gulimall_pms,gulimall_oms,gulimall_sms,gulimall_wms,gulimall-admin | | | +------------------+----------+---------------------------------------------------------------------------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> exit Bye :/# read escape sequence [ ~]#
STEP 4 从服务器开启同步
change master to master_host=‘192.168.1.117‘,master_user=‘backup‘, master_password=‘123456‘,master_log_file=‘mysql-bin.000001‘,master_log_pos=0,master_port=3307; start slave; show slave status;
相关推荐
CoderToy 2020-11-16
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11
世樹 2020-11-11