大纲
一、系统环境
二、MySQL初始化安装过程
三、基于GTID的主从模式配置过程
一、系统环境
系统环境
CentOS5.8 x86_64
master.network.com master 172.16.1.101
slave.network.com slave 172.16.1.105
软件包
- mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz(二进制通用安装包)
拓扑图
二、MySQL初始化安装过程
1、时间同步
[[email protected] ~]# ntpdate s2c.time.edu.cn [[email protected] ~]# ntpdate s2c.time.edu.cn 可根据需要在每个节点上定义crontab任务 [[email protected] ~]# which ntpdate /sbin/ntpdate [[email protected] ~]# echo "*/5 * * * * /sbin/ntpdate s2c.time.edu.cn &> /dev/null" >> /var/spool/cron/root [[email protected] ~]# crontab -l */5 * * * * /sbin/ntpdate s2c.time.edu.cn &> /dev/null
2、主机名称要与uname -n保持一致,并通过/etc/hosts解析
master [[email protected] ~]# hostname master.network.com [[email protected] ~]# uname -n master.network.com [[email protected] ~]# sed -i ‘[email protected]\(HOSTNAME=\).*@\[email protected]‘ /etc/sysconfig/network slave [[email protected] ~]# hostname slave.network.com [[email protected] ~]# uname -n slave.network.com [[email protected] ~]# sed -i ‘[email protected]\(HOSTNAME=\).*@\[email protected]‘ /etc/sysconfig/network master添加hosts解析 [[email protected] ~]# vim /etc/hosts [[email protected] ~]# cat /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 CentOS5.8 CentOS5 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 172.16.1.101 master.network.com master 172.16.1.105 slave.network.com slave 拷贝此hosts文件至slave [[email protected] ~]# scp /etc/hosts slave:/etc/ [email protected]‘s password: hosts 100% 233 0.2KB/s 00:00
3、关闭iptables和selinux
master [[email protected] ~]# service iptables stop [[email protected] ~]# vim /etc/sysconfig/selinux [[email protected] ~]# cat /etc/sysconfig/selinux # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - SELinux is fully disabled. #SELINUX=permissive SELINUX=disabled # SELINUXTYPE= type of policy in use. Possible values are: # targeted - Only targeted network daemons are protected. # strict - Full SELinux protection. SELINUXTYPE=targeted slave [[email protected] ~]# service iptables stop [[email protected] ~]# vim /etc/sysconfig/selinux [[email protected] ~]# cat /etc/sysconfig/selinux # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - SELinux is fully disabled. #SELINUX=permissive SELINUX=disabled # SELINUXTYPE= type of policy in use. Possible values are: # targeted - Only targeted network daemons are protected. # strict - Full SELinux protection. SELINUXTYPE=targeted
4、Master安装并配置MySQL
数据目录底层最好是个逻辑卷,我这里就不再演示逻辑卷的创建了,我的博文中有,此处没有使用逻辑卷 准备数据目录并添加mysql用户 [[email protected] ~]# mkdir -pv /mydata/data mkdir: created directory `/mydata‘ mkdir: created directory `/mydata/data‘ [[email protected] ~]# groupadd -g 3306 mysql [[email protected] ~]# useradd -u 3306 -g mysql -M -s /sbin/nologin -d /mydata/data/ mysql [[email protected] ~]# chown -R mysql.mysql /mydata/data/ 解压并初始化mysql [[email protected] ~]# cd /tmp/ [[email protected] tmp]# tar xf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ [[email protected] tmp]# cd /usr/local/ [[email protected] local]# ln -sv mysql-5.6.26-linux-glibc2.5-x86_64 mysql create symbolic link `mysql‘ to `mysql-5.6.26-linux-glibc2.5-x86_64‘ [[email protected] local]# cd mysql [[email protected] mysql]# chown -R root.mysql ./* [[email protected] mysql]# ll total 232 drwxr-xr-x 2 root mysql 4096 Jan 16 12:48 bin -rw-r--r-- 1 root mysql 17987 Jul 15 2015 COPYING drwxr-xr-x 3 root mysql 4096 Jan 16 12:49 data drwxr-xr-x 2 root mysql 4096 Jan 16 12:49 docs drwxr-xr-x 3 root mysql 4096 Jan 16 12:48 include -rw-r--r-- 1 root mysql 104897 Jul 15 2015 INSTALL-BINARY drwxr-xr-x 3 root mysql 4096 Jan 16 12:49 lib drwxr-xr-x 4 root mysql 4096 Jan 16 12:49 man drwxr-xr-x 10 root mysql 4096 Jan 16 12:49 mysql-test -rw-r--r-- 1 root mysql 2496 Jul 15 2015 README drwxr-xr-x 2 root mysql 4096 Jan 16 12:49 scripts drwxr-xr-x 28 root mysql 4096 Jan 16 12:49 share drwxr-xr-x 4 root mysql 4096 Jan 16 12:49 sql-bench drwxr-xr-x 2 root mysql 4096 Jan 16 12:49 support-files [[email protected] mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/ Installing MySQL system tables...2016-01-16 12:57:52 0 [Warning] ‘THREAD_CONCURRENCY‘ is deprecated and will be removed in a future release. 2016-01-16 12:57:52 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-01-16 12:57:52 0 [Note] ./bin/mysqld (mysqld 5.6.26-log) starting as process 19105 ... 2016-01-16 12:57:53 19105 [Note] InnoDB: Using atomics to ref count buffer pool pages 2016-01-16 12:57:53 19105 [Note] InnoDB: The InnoDB memory heap is disabled 2016-01-16 12:57:53 19105 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-01-16 12:57:53 19105 [Note] InnoDB: Memory barrier is not used 2016-01-16 12:57:53 19105 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-01-16 12:57:53 19105 [Note] InnoDB: Using Linux native AIO 2016-01-16 12:57:53 19105 [Note] InnoDB: Not using CPU crc32 instructions 2016-01-16 12:57:53 19105 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2016-01-16 12:57:53 19105 [Note] InnoDB: Completed initialization of buffer pool 2016-01-16 12:57:53 19105 [Note] InnoDB: Highest supported file format is Barracuda. 2016-01-16 12:57:53 19105 [Note] InnoDB: 128 rollback segment(s) are active. 2016-01-16 12:57:53 19105 [Note] InnoDB: 5.6.26 started; log sequence number 1600627 2016-01-16 12:57:54 19105 [Note] Binlog end 2016-01-16 12:57:54 19105 [Note] InnoDB: FTS optimize thread exiting. 2016-01-16 12:57:54 19105 [Note] InnoDB: Starting shutdown... 2016-01-16 12:57:56 19105 [Note] InnoDB: Shutdown completed; log sequence number 1626007 OK Filling help tables...2016-01-16 12:57:56 0 [Warning] ‘THREAD_CONCURRENCY‘ is deprecated and will be removed in a future release. 2016-01-16 12:57:56 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-01-16 12:57:56 0 [Note] ./bin/mysqld (mysqld 5.6.26-log) starting as process 19128 ... 2016-01-16 12:57:56 19128 [Note] InnoDB: Using atomics to ref count buffer pool pages 2016-01-16 12:57:56 19128 [Note] InnoDB: The InnoDB memory heap is disabled 2016-01-16 12:57:56 19128 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-01-16 12:57:56 19128 [Note] InnoDB: Memory barrier is not used 2016-01-16 12:57:56 19128 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-01-16 12:57:56 19128 [Note] InnoDB: Using Linux native AIO 2016-01-16 12:57:56 19128 [Note] InnoDB: Not using CPU crc32 instructions 2016-01-16 12:57:56 19128 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2016-01-16 12:57:56 19128 [Note] InnoDB: Completed initialization of buffer pool 2016-01-16 12:57:56 19128 [Note] InnoDB: Highest supported file format is Barracuda. 2016-01-16 12:57:56 19128 [Note] InnoDB: 128 rollback segment(s) are active. 2016-01-16 12:57:56 19128 [Note] InnoDB: Waiting for purge to start 2016-01-16 12:57:56 19128 [Note] InnoDB: 5.6.26 started; log sequence number 1626007 2016-01-16 12:57:56 19128 [Note] Binlog end 2016-01-16 12:57:57 19128 [Note] InnoDB: FTS optimize thread exiting. 2016-01-16 12:57:57 19128 [Note] InnoDB: Starting shutdown... 2016-01-16 12:57:58 19128 [Note] InnoDB: Shutdown completed; log sequence number 1626017 OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: ./bin/mysqladmin -u root password ‘new-password‘ ./bin/mysqladmin -u root -h master.network.com password ‘new-password‘ Alternatively you can run: ./bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com WARNING: Found existing config file ./my.cnf on the system. Because this file might be in use, it was not replaced, but was used in bootstrap (unless you used --defaults-file) and when you later start the server. The new default config file was created as ./my-new.cnf, please compare it with your file and take the changes you need. WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server 复制服务启动脚本 [[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [[email protected] mysql]# chkconfig --add mysqld 增加PATH环境变量并使之生效 [[email protected] mysql]# echo ‘export PATH=$PATH:/usr/local/mysql/bin/mysql‘ > /etc/profile.d/mysql.sh [[email protected] mysql]# . /etc/profile.d/mysql.sh 将mysql5.6.26的安装包复制到slave节点上 [[email protected] mysql]# scp /tmp/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz slave.network.com:/tmp/ The authenticity of host ‘slave.network.com (172.16.1.105)‘ can‘t be established. RSA key fingerprint is 13:42:92:7b:ff:61:d8:f3:7c:97:5f:22:f6:71:b3:24. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added ‘slave.network.com‘ (RSA) to the list of known hosts. mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz 100% 298MB 4.7MB/s 01:03
5、Master安装并配置MySQL
准备数据目录并添加mysql用户 [[email protected] ~]# mkdir -pv /mydata/data mkdir: created directory `/mydata‘ mkdir: created directory `/mydata/data‘ [[email protected] ~]# groupadd -g 3306 mysql [[email protected] ~]# useradd -u 3306 -g mysql -M -s /sbin/nologin -d /mydata/data/ mysql [[email protected] ~]# chown -R mysql.mysql /mydata/data/ 解压并初始化mysql [[email protected] ~]# cd /tmp/ [[email protected] tmp]# tar xf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ [[email protected] tmp]# cd /usr/local/ [[email protected] local]# ln -sv mysql-5.6.26-linux-glibc2.5-x86_64 mysql create symbolic link `mysql‘ to `mysql-5.6.26-linux-glibc2.5-x86_64‘ [[email protected] local]# cd mysql [[email protected] mysql]# chown -R root.mysql ./* [[email protected] mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/ Installing MySQL system tables...2016-01-16 13:55:00 0 [Warning] ‘THREAD_CONCURRENCY‘ is deprecated and will be removed in a future release. 2016-01-16 13:55:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-01-16 13:55:00 0 [Note] ./bin/mysqld (mysqld 5.6.26) starting as process 18199 ... 2016-01-16 13:55:00 18199 [Warning] You need to use --log-bin to make --binlog-format work. 2016-01-16 13:55:00 18199 [Note] InnoDB: Using atomics to ref count buffer pool pages 2016-01-16 13:55:00 18199 [Note] InnoDB: The InnoDB memory heap is disabled 2016-01-16 13:55:00 18199 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-01-16 13:55:00 18199 [Note] InnoDB: Memory barrier is not used 2016-01-16 13:55:00 18199 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-01-16 13:55:00 18199 [Note] InnoDB: Using Linux native AIO 2016-01-16 13:55:00 18199 [Note] InnoDB: Not using CPU crc32 instructions 2016-01-16 13:55:00 18199 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2016-01-16 13:55:00 18199 [Note] InnoDB: Completed initialization of buffer pool 2016-01-16 13:55:00 18199 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2016-01-16 13:55:00 18199 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2016-01-16 13:55:00 18199 [Note] InnoDB: Database physically writes the file full: wait... 2016-01-16 13:55:01 18199 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2016-01-16 13:55:03 18199 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2016-01-16 13:55:06 18199 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2016-01-16 13:55:06 18199 [Warning] InnoDB: New log files created, LSN=45781 2016-01-16 13:55:06 18199 [Note] InnoDB: Doublewrite buffer not found: creating new 2016-01-16 13:55:06 18199 [Note] InnoDB: Doublewrite buffer created 2016-01-16 13:55:06 18199 [Note] InnoDB: 128 rollback segment(s) are active. 2016-01-16 13:55:06 18199 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-01-16 13:55:06 18199 [Note] InnoDB: Foreign key constraint system tables created 2016-01-16 13:55:06 18199 [Note] InnoDB: Creating tablespace and datafile system tables. 2016-01-16 13:55:07 18199 [Note] InnoDB: Tablespace and datafile system tables created. 2016-01-16 13:55:07 18199 [Note] InnoDB: Waiting for purge to start 2016-01-16 13:55:07 18199 [Note] InnoDB: 5.6.26 started; log sequence number 0 2016-01-16 13:55:09 18199 [Note] Binlog end 2016-01-16 13:55:09 18199 [Note] InnoDB: FTS optimize thread exiting. 2016-01-16 13:55:09 18199 [Note] InnoDB: Starting shutdown... 2016-01-16 13:55:11 18199 [Note] InnoDB: Shutdown completed; log sequence number 1625977 OK Filling help tables...2016-01-16 13:55:11 0 [Warning] ‘THREAD_CONCURRENCY‘ is deprecated and will be removed in a future release. 2016-01-16 13:55:11 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-01-16 13:55:11 0 [Note] ./bin/mysqld (mysqld 5.6.26) starting as process 18224 ... 2016-01-16 13:55:11 18224 [Warning] You need to use --log-bin to make --binlog-format work. 2016-01-16 13:55:11 18224 [Note] InnoDB: Using atomics to ref count buffer pool pages 2016-01-16 13:55:11 18224 [Note] InnoDB: The InnoDB memory heap is disabled 2016-01-16 13:55:11 18224 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-01-16 13:55:11 18224 [Note] InnoDB: Memory barrier is not used 2016-01-16 13:55:11 18224 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-01-16 13:55:11 18224 [Note] InnoDB: Using Linux native AIO 2016-01-16 13:55:11 18224 [Note] InnoDB: Not using CPU crc32 instructions 2016-01-16 13:55:11 18224 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2016-01-16 13:55:11 18224 [Note] InnoDB: Completed initialization of buffer pool 2016-01-16 13:55:11 18224 [Note] InnoDB: Highest supported file format is Barracuda. 2016-01-16 13:55:11 18224 [Note] InnoDB: 128 rollback segment(s) are active. 2016-01-16 13:55:11 18224 [Note] InnoDB: 5.6.26 started; log sequence number 1625977 2016-01-16 13:55:12 18224 [Note] Binlog end 2016-01-16 13:55:12 18224 [Note] InnoDB: FTS optimize thread exiting. 2016-01-16 13:55:12 18224 [Note] InnoDB: Starting shutdown... 2016-01-16 13:55:13 18224 [Note] InnoDB: Shutdown completed; log sequence number 1625987 OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: ./bin/mysqladmin -u root password ‘new-password‘ ./bin/mysqladmin -u root -h slave.network.com password ‘new-password‘ Alternatively you can run: ./bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd . ; ./bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as ./my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server 复制服务启动脚本 [[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [[email protected] mysql]# chkconfig --add mysqld
三、基于GTID的主从模式配置过程
1、编辑master的配置文件
编辑配置文件,就在当前目录下(/usr/local/mysql) [[email protected] mysql]# vim my.cnf [mysqld] binlog-format=ROW log-bin=master-bin log-slave-updates=true gtid-mode=on enforce-gtid-consistency=true master-info-repository=TABLE relay-log-info-repository=TABLE sync-master-info=1 slave-parallel-workers=2 binlog-checksum=CRC32 master-verify-checksum=1 slave-sql-verify-checksum=1 binlog-rows-query-log_events=1 server-id=1 report-port=3306 port=3306 datadir=/mydata/data innodb_file_per_table = ON socket=/tmp/mysql.sock report-host=172.16.1.101 启动服务并查看gtid是否生效 [[email protected] mysql]# service mysqld start Starting MySQL......... [ OK ] [[email protected] mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.26-log MySQL Community Server (GPL) Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the buffer. mysql> SHOW GLOBAL VARIABLES LIKE ‘%gtid%‘; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | binlog_gtid_simple_recovery | OFF | | enforce_gtid_consistency | ON | | gtid_executed | | | gtid_mode | ON | | gtid_owned | | | gtid_purged | | | simplified_binlog_gtid_recovery | OFF | +---------------------------------+-------+ 7 rows in set (0.00 sec) 查看master的uuid mysql> SHOW GLOBAL VARIABLES LIKE ‘%uuid%‘; +---------------+--------------------------------------+ | Variable_name | Value | +---------------+--------------------------------------+ | server_uuid | dfc512d8-bc12-11e5-97ec-000c29fe8238 | +---------------+--------------------------------------+ 1 row in set (0.00 sec)
2、编辑slave的配置文件
编辑配置文件,就在当前目录下(/usr/local/mysql) [[email protected] mysql]# vim my.cnf [mysqld] binlog-format=ROW log-slave-updates=true gtid-mode=on enforce-gtid-consistency=true master-info-repository=TABLE relay-log-info-repository=TABLE sync-master-info=1 slave-parallel-workers=2 binlog-checksum=CRC32 master-verify-checksum=1 slave-sql-verify-checksum=1 binlog-rows-query-log_events=1 server-id=11 report-port=3306 port=3306 log-bin=mysql-bin.log datadir=/mydata/data socket=/tmp/mysql.sock report-host=172.16.1.105 启动服务并查看gtid是否生效 [[email protected] mysql]# service mysqld start Starting MySQL..... [ OK ] [[email protected] mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.26-log MySQL Community Server (GPL) Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the buffer. mysql> SHOW GLOBAL VARIABLES LIKE ‘%gtid%‘; +---------------------------------+-------+ | Variable_name | Value | +---------------------------------+-------+ | binlog_gtid_simple_recovery | OFF | | enforce_gtid_consistency | ON | | gtid_executed | | | gtid_mode | ON | | gtid_owned | | | gtid_purged | | | simplified_binlog_gtid_recovery | OFF | +---------------------------------+-------+ 7 rows in set (0.00 sec) mysql> SHOW GLOBAL VARIABLES LIKE ‘%uuid%‘; +---------------+--------------------------------------+ | Variable_name | Value | +---------------+--------------------------------------+ | server_uuid | ec8230c2-bc18-11e5-9813-000c296634d1 | +---------------+--------------------------------------+ 1 row in set (0.09 sec)
3、master建立复制账号
mysql> GRANT REPLICATION SLAVE ON *.* TO ‘repuser‘@‘172.16.%.%‘ IDENTIFIED BY ‘reppass‘; Query OK, 0 rows affected (0.09 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec)
4、启动从节点的复制线程
mysql> CHANGE MASTER TO MASTER_HOST=‘master.network.com‘, MASTER_USER=‘repuser‘, MASTER_PASSWORD=‘reppass‘, MASTER_AUTO_POSITION=1; Query OK, 0 rows affected, 2 warnings (0.30 sec) 显示警告信息 mysql> SHOW WARNINGS\G *************************** 1. row *************************** Level: Note Code: 1759 Message: Sending passwords in plain text without SSL/TLS is extremely insecure. *************************** 2. row *************************** Level: Note Code: 1760 Message: Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the ‘START SLAVE Syntax‘ in the MySQL Manual for more information. 2 rows in set (0.00 sec) 查看slave状态信息 mysql> SHOW SLAVE STATUS\G *************************** 1. row *************************** Slave_IO_State: Master_Host: master.network.com Master_User: repuser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: Read_Master_Log_Pos: 4 Relay_Log_File: relay-log.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: mydb Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 0 Relay_Log_Space: 151 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 0 Master_UUID: Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 1 1 row in set (0.00 sec) 启动slave线程 mysql> START SLAVE; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> SHOW SLAVE STATUS\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: master.network.com Master_User: repuser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000003 Read_Master_Log_Pos: 536 Relay_Log_File: relay-log.000002 Relay_Log_Pos: 748 Relay_Master_Log_File: master-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: mydb Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 536 Relay_Log_Space: 946 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_UUID: dfc512d8-bc12-11e5-97ec-000c29fe8238 Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: dfc512d8-bc12-11e5-97ec-000c29fe8238:1-2 Executed_Gtid_Set: dfc512d8-bc12-11e5-97ec-000c29fe8238:1-2 Auto_Position: 1 1 row in set (0.01 sec)
5、测试复制功能
在master上创建一个测试库 mysql> CREATE DATABASE mydb; Query OK, 1 row affected (0.08 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mydb | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.01 sec) 然后在slave上查看是否有此库 mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mydb | # 可以看到复制功能已然实现 | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) 此时master上可以查看到slave的相关信息 mysql> SHOW SLAVE HOSTS; +-----------+--------------+------+-----------+--------------------------------------+ | Server_id | Host | Port | Master_id | Slave_UUID | +-----------+--------------+------+-----------+--------------------------------------+ | 11 | 172.16.1.105 | 3306 | 1 | ec8230c2-bc18-11e5-9813-000c296634d1 | +-----------+--------------+------+-----------+--------------------------------------+ 1 row in set (0.03 sec)
时间: 2024-10-25 08:21:49