Mariadb master-slave synchronization
This article is the download address of the built mariadb-10.0.17 version: https://downloads.mariadb.org/interstitial/mariadb-10.0.17/source/mariadb-10.0.17.tar.gz/from/http%3A//ftp.hosteurope.de/mirror/archive.mariadb.org/?serve
Master:192.168.1.166
Slave:192.168.1.165
1. Create an ordinary mysql account, set the directory where the database stores data, and set permissions
[root@zsxyweb3] # groupadd-r mysql
[root@zsxyweb3~] # useradd-r-g mysql-s / sbin/nologin mysql
[root@zsxyweb3~] # mkdir-p / data/mydata
[root@zsxyweb3~] # chown-R mysql:mysql / data
two。 Install the database dependency package
[root@zsxyweb3~] # yum install-y gcc gcc-c++ make cmake ncurses ncurses libxml2 libxml2-developenssl-devel bison bison-devel ncurses-devel
3. Upload mariadb package, decompress, compile and install.
[root@zsxyweb3 ~] # tar zxvf mariadb-10.0.17.tar.gz
[root@zsxyweb3 mariadb-10.0.17] # cmake-DCMAKE_INSTALL_PREFIX=/app/mysql-DMYSQL_DATADIR=/data/mydata-DWITH_INNOBASE_STORAGE_ENGINE=1-DWITH_ARCHIVE_STPRAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1-DWIYH_READLINE=1-DWIYH_SSL=system-DVITH_ZLIB=system-DWITH_LOBWRAP=0-DMYSQL_UNIX_ADDR=/tmp/mysql.sock-DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci
[root@zsxyweb3 mariadb-10.0.17] # make&& make install
4. Copy the database startup script to the / etc/init.d/mysqld directory and modify the / etc/my.cnf configuration file.
[root@zsxyweb3mariadb-10.0.17] # cd / app/mysql/
[root@zsxyweb3mysql] # cp support-files/mysql.server / etc/rc.d/init.d/mysqld
[root@zsxyweb3mysql] # chmod + x / etc/rc.d/init.d/mysqld
[root@zsxyweb3mysql] # cp support-files/my-large.cnf / etc/my.cnf
5. Initialize the database, start the database
[root@zsxyweb3mysql] # scripts/mysql_install_db-user=mysql-datadir=/app/mysql/data
[root@zsxyweb3mysql] # mkdir log
[root@zsxyweb3mysql] # service mysqld start
6. System variables of the database
[root@zsxyweb3 mysql] # vim/etc/profile.d/mysqld.sh
Export PATH=$PATH:/usr/local/mysql/bin
[root@zsxyweb3 mysql] # source/etc/profile.d/mysqld.sh
[root@zsxyweb3 mysql] # mysql
Welcome to the MySQL monitor. Commands end with; or\ g.
Your MySQL connection id is 148
Server version: 5.5.5-10.0.17-MariaDB-logSource distribution
Copyright (c) 2000, 2013, Oracle and/orits affiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
Affiliates. Other names may be trademarksof their respective
Owners.
Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.
Mysql >
7.master192.168.1.166 / etc/my.cnf is as follows
[client]
Port = 3306
Socket = / tmp/mysql.sock
[mysqld]
Port = 3306
Socket = / tmp/mysql.sock
Skip-external-locking
Key_buffer_size = 256m
Max_allowed_packet = 4690m
Table_open_cache = 16
Sort_buffer_size = 64m
Read_buffer_size = 32m
Read_rnd_buffer_size = 256m
Myisam_sort_buffer_size = 1024m
Thread_cache_size = 8
Query_cache_size= 128M
Log-error=/app/mysql/log/alert.log
Slow_query_log_file=/app/mysql/log/slow.log
General_log_file=/app/mysql/log/general.log
Datadir = / app/mysql/data
Log-bin=mysql-bin
Binlog_format=mixed
Server-id = 1
[mysqldump]
Quick
Max_allowed_packet = 4690m
[mysql]
No-auto-rehash
[myisamchk]
Key_buffer_size = 128m
Sort_buffer_size = 128m
Read_buffer = 2m
Write_buffer = 2m
[mysqlhotcopy]
Interactive-timeout
8.slave192.168.1.165 Li / etc/my.cnf
Port = 3306
Socket = / tmp/mysql.sock
Skip-external-locking
Key_buffer_size = 256m
Max_allowed_packet = 1m
Table_open_cache = 256
Sort_buffer_size = 1m
Read_buffer_size = 1m
Read_rnd_buffer_size = 4m
Myisam_sort_buffer_size = 64m
Thread_cache_size = 8
Query_cache_size= 16M
Log-error=/app/mysql/log/alert.log
Slow_query_log_file=/app/mysql/log/slow.log
General_log_file=/app/mysql/log/general.log
Thread_concurrency = 8
Datadir = / data/mydata
Log-bin=mysql-bin
Binlog_format=mixed
Server-id = 2
[mysqldump]
Quick
Max_allowed_packet = 16m
[mysql]
No-auto-rehash
[myisamchk]
Key_buffer_size = 128m
Sort_buffer_size = 128m
Read_buffer = 2m
Write_buffer = 2m
[mysqlhotcopy]
Interactive-timeout
9. Authorize mysql on the master database
Mysql > GRANT ALL PRIVILEGES ON *. * TO'root'@'192.168.1.% IDENTIFIED BY 'passwd' WITH GRANT OPTION
Mysql > flush privileges
Mysql > show master status
+-+
| | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | |
+-+
| | mysql-bin.000008 | 2890 | |
+-+
1 row in set (0.00 sec)
10. From slave mysql
Mysql > stop slave
Mysql > change master tomaster_host='192.168.1.166',master_user='root',master_password='passwd',master_log_file='mysql-bin.000008',master_log_pos=2890,master_connect_retry=5,master_heartbeat_period=2,Master_Port=3306
Mysql > flush privileges
Mysql > start slave
Mysql > show slave status\ G
* 1. Row**
Slave_IO_State: Waiting formaster to send event
Master_Host: 192.168.1.166
Master_User: root
Master_Port: 3306
Connect_Retry: 5
Master_Log_File: mysql-bin.000008
Read_Master_Log_Pos: 2890
Relay_Log_File:zsxyweb3-relay-bin.000002
Relay_Log_Pos: 1198
Relay_Master_Log_File: mysql-bin.000008
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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: 2890
Relay_Log_Space: 1498
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_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
1 row in set (0.00 sec)
Note: mainly check whether Slave_IO_Running: Yes Slave_SQL_Running: Yes is yes