Table Of Contents
Preamble
My initial idea was more to test MySQL Replication switchover and failover but had a presentation of MySQL 5.6 new replication features and realized that I have never setup such environment myself. So decided to give a try and use Percona backup tool (XtraBackup) and classic mysqldump utility to create from scratch a slave instance.
Blog post has been done using MySQL 5.6.11 (binary release i.e. Linux – Generic (glibc 2.5) (x86, 64-bit), Compressed TAR Archive), Oracle Enterprise Linux 6.4 64 bits and Percona XtraBackup 2.1.3. In below server1.domain.com is my master server and server2.domain.com the slave one. They are both virtual machine using non routable IP adresses.
Replication with GTID prerequisites
For better segregation I have decided to create a MySQL Replication dedicated account with minimum rights (using root would not be a good idea):
|
And create a test database and table:
|
Table I load with something like:
|
You can check master status and GTID position with:
|
The typical variables to setup for replication are (when using the new GTID functionality), I use non-default binlog_format = row as MySQL 5.6 has apparently been drastically improved for this most used replication format (as Oracle say). In below whether you are on server1 or server2 you must adapt server_id and report_host variables:
log-bin = /mysql/logs/mysql01/mysql-bin server-id = 1 | 2 relay_log = /mysql/logs/mysql01/relay-bin binlog_format = row gtid_mode = on log_slave_updates = true enforce_gtid_consistency = true master_info_repository = table relay_log_info_repository = table sync_master_info = 1 # Never do this on a production server, default value = 10000 master-verify-checksum = on slave-sql-verify-checksum = on report_host = server1.domain.com | server2.domain.com report_port = 3326
To ease testing I’m adding the three alias in profile of my mysql Linux account:
alias start_mysql01='cd /mysql/software/mysql01/; ./bin/mysqld_safe --defaults-file=/mysql/software/mysql01/conf/my.cnf &' alias stop_mysql01="/mysql/software/mysql01/bin/mysqladmin --defaults-file=/mysql/software/mysql01/conf/my.cnf --user=root --password=`cat ~mysql/.root_password` shutdown" alias mysql01='/mysql/software/mysql01/bin/mysql --defaults-file=/mysql/software/mysql01/conf/my.cnf --user=root --password=`cat ~mysql/.root_password`' |
The .root_password file is in home directory of mysql Linux account:
[mysql@server1 ~]$ ll .root_password -r-------- 1 mysql dba 16 May 31 17:11 .root_password |
As a reminder I personally use the below MySQL directory naming convention:
Directory | Used for |
---|---|
/mysql/data01/mysql01 | Strore MyISAM and InnoDB files, dataxx directories can also be created to spread I/O |
/mysql/dump/mysql01 | All log files (slow log, error log, general log, …) |
/mysql/logs/mysql01 | All binary logs (log-bin, relay_log) |
/mysql/software/mysql01 | MySQL binaries (the my.cnf file is then stored in a conf subdirectory, as well as socket and pid files) |
This MySQL directories naming convention should allow you to have multiple MySQL instance running on same server (mysql01, mysql02 and so on). Please note it is slightly different from what has been nicely presented by George Trujillo in hisInstalling MySQL 5.1 on Solaris 10 using MOCA post. MOCA stands for MySQL Optimal Configuration Architecture (MOCA) and I like this name…