展开全部
|这个一台机器,配置一主一从的。
# 1.shutdown mysql
$mysqladmin -uroot -pmysql
$netstat -lnt|e68a843231313335323631343130323136353331333363353762grep 3306
# 2.copy datafile
$cp -R /data/mysqldata/3306 /data/mysqldata/3307
change primary /data/mysqldata/3306/my.cnf
server_id = 2433306
log-bin = /data/mysqldata/3306/binlog/mysql-bin
start mysql
$ mysql_db_startup.sh
# 3.create user for copy on primary
mysql> grant replication slave on *.* to 'repl'@'192.168.2.%' identified by 'replsafe';
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000005 | 330 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.03 sec)
# 4.edit /data/mysqldata/3307/my.cnf on slave
server_id = 2433307
log-bin = /data/mysqldata/3306/binlog/mysql-bin
change 3306 to 3307 on my.cnf
$sed -i 's/3306/3307/g' /data/mysqldata/3307/my.cnf
auto.cnf save mysql server-uuid
$rm /data/mysqldata/3307/data/auto.cnf
# 5.start slave
[mysql@mysql scripts]$ mysql_db_startup.sh 3307
connect to slave mysql
$/usr/local/mysql/bin/mysql -usystem -p'root' -S /data/mysqldata/3307/mysql.sock
mysql> change master to
-> master_host='192.168.2.100',
-> master_port=3306,
-> master_user='repl',
-> master_password='replsafe',
-> master_log_file='mysql-bin.000005',
-> master_log_pos=330;
*** change master to master_host='192.168.2.100',master_port=3306,master_user='repl',master_password='replsafe', master_log_file='mysql-bin.000005',master_log_pos=330;
Query OK, 0 rows affected, 2 warnings (0.08 sec)
mysql> start slave;
Query OK, 0 rows affected (0.04 sec)
# 6.test copy
On primary
mysql> prompt Master>
PROMPT set to 'Master>'
Master> use ylo;
Master> create table ct1(id int);
Master> insert into ct1 values(1);
on slave
mysql> prompt Slave>
Slave>use ylo;
Slave>desc ct1;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
1 row in set (0.06 sec)
Slave>select * from ct1;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.02 sec)
It seems that we are successful.
check copy status
Slave>show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.100
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000005
Read_Master_Log_Pos: 911
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 864
Relay_Master_Log_File: mysql-bin.000005
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: 911
Relay_Log_Space: 1037
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: 2433306
Master_UUID: ed611fac-75a8-11e6-9219-000c29d651e0
Master_Info_File: /data/mysqldata/3307/data/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:
Executed_Gtid_Set:
Auto_Position: 0
1 row in set (0.00 sec)
本回答由网友推荐
已赞过
已踩过<
你对这个回答的评价是?
评论
收起