Master-slave configuration steps: create a database to be synchronized in the master database, create an account for the master database, and modify the master-slave database configuration createdatabasewebdefadefacharactersetutf8grantreplicationslaveon ** torepdcssub @ 192168191 master-slave configuration steps:
Create the database to be synchronized in the master database, create the account of the master database, and modify the configuration of the master and slave databases.
Create database web default character set utf8
Grant replication slave on *. * to 'repdcssub '@ '192. 168.191.112 'identified by '123 ';
Grant all privileges on *. * to 'repdcssub '@ '192. 168.191.112' identified by '20140901'
Mysql-h192.168.191.113-urep-p123456
Mysqldump -- master-data can be restored from the top,
Create a synchronization user (master/slave)
Grant replication slave on *. * to 'repdcs '@ '192. 168.191.110 'identified by '123 ';
Grant all privileges on *. * to 'repdcs '@ '192. 168.191.110 'identified by '123 ';
Flush privileges;
Mysql> show master status;
Flush privileges;
Configure my. cnf from the slave database
[Root @ ligangtest u02] # more/etc/my. cnf
[Mysqld]
Datadir =/u02/ligangdata
Socket =/var/lib/mysql. sock
User = mysql
Old_passwords = 1
Character-set-server = utf8
Symbolic-links = 0
Lower_case_table_names = 1
Default-storage-engine = innoDB
# Innodb_log_buffer_pool_size = 2G
Max_connections = 300
Server-id = 2
Init_connect = 'set NAMES utf8'
Log-bin = mysqlbin
Master-host = 192.168.191.111
Master-user = repdcs
Master-pass = 123456
Master-connect-retry = 60
Replicate-do-db = dcs
[Mysqld_safe]
Log-error =/u03/log/mysqld. log
Pid-file =/var/run/mysqld. pid
[Mysql]
Default-character-set = utf8
# Character-set-server = utf8
Configure my. ini for the master database
[Root @ ligang log] # more/etc/my. cnf
[Mysqld]
Datadir =/u02/ligangdata
Socket =/var/lib/mysql. sock
User = mysql
Old_passwords = 1
Character-set-server = utf8
# Disabling symbolic-links is recommended to prevent assorted security risks;
Symbolic-links = 0
Lower_case_table_names = 1
Default-storage-engine = innoDB
Server-id = 1
Log-bin = mysqlbin
Innodb_flush_log_at_trx_commit = 1
Sync_binlog = 1
Init_connect = 'set NAMES utf8'
# Innodb_log_buffer_pool_size = 2G
Max_connections = 300
[Mysqld_safe]
Log-error =/u03/log/mysqld. log
Pid-file =/var/run/mysqld. pid
[Mysql]
Default-character-set = utf8
# Character-set-server = utf8
Parameter configuration instructions
Server-id = n // Set the database id. the default master server is 1, which can be set at will, but it cannot be repeated if there are multiple slave servers.
Master-host = 192.168.191.111 // IP address or domain name of the master server
Master-port = 3306 // the port number of the master database
Master-user = repdcs // user who synchronizes the database
Master-password = 123456 // password for database synchronization
Master-connect-retry = 60 // time difference between the reconnection if the master server is disconnected from the slave server
Replicate-do-db = dcs // database for synchronization
Set slave server to readonly
Mysql-e "set global read_only = 1 ;"
Command to check whether the master database is normal or not:
Show slave status;
Show master status;