特别值得一提的是Ubuntu mysql有很多值得学习的地方,这里我们主要介绍Ubuntu mysql,包括介绍Ubuntu mysql等方面。因需要在ubuntu下面为Ubuntu mysql建立slave机。
综合了网上的个别资料与Ubuntu mysql参考手册,成功的实施了Ubuntu mysql的复制工作。具体步骤不多,不过在配置的过程中也出现过不少问题,花了点时间,下面简单的记录一下整个配置过程。
1. 在master上建立一个专门用来做复制的用户:grant replication slave on *.* to 'replicationuser'@'192.168.51.165' identified by '123456';
2.设置master机my.cnf:
执行sudo vim etc/Ubuntu mysql/my.cnf在[Ubuntu mysqld]区域加入以下内容:
server-id = 1
log_bin = /var/log/Ubuntu mysql/Ubuntu mysql-bin.log #开启二进制日志
binlog_do_db = testdb #需要同步的数据库,可选
binlog_ignore_db = Ubuntu mysql,information_schema #
- 1.
- 2.
- 3.
- 4.
- 5.
不需要同步的数据库,可选重启master服务器 sudo /etc/init.d/Ubuntu mysql restart
3.设置slave机my.cnf:
执行sudo vim etc/Ubuntu mysql/my.cnf在[Ubuntu mysqld]区域加入以下内容:server-id = 2重启slave服务器 sudo /etc/init.d/Ubuntu mysql restart
4.刷新主服务器上所有的表和块写入语句:flush tables with read lock; 然后读取主服务器上的二进制文件名和分支:show master status;将File和Position的值记录下来。
并备份master上的数据到slave进行初始化。(flush tables with read lock是为了确保没有数据库操作),(只要记录下File和Position的值,这里就可以执行第6个步骤释放锁:Ubuntu mysql> unlock table; )
scp -r ./* root@192.168.47.175:/var/lib/Ubuntu mysql 用root***权限,更改root密码 sudo su -passwd
5.登陆slave的Ubuntu mysql,用系统真实值代替选项:
Ubuntu mysql> CHANGE MASTER TO MASTER_HOST='192.168.51.162',MASTER_USER='replicationuser',
MASTER_PASSWORD='123456',MASTER_LOG_FILE='Ubuntu mysql-bin.000001',MASTER_LOG_POS=1279702;
这里master_log_file和master_log_pos就是前面show master status的结果
- 1.
- 2.
- 3.
6.登陆master并释放锁:Ubuntu mysql> unlock table;
7.切换到slave机,启动从线程:Ubuntu mysql> start slave;这样就完成了master/slave的配置工作。***可以用show processlist"G;来分别查看 master与slave的状态。master: 48发送binlog到slave,等待更新。
*************************** 5. row ***************************
Id: 48
User: replicationuser
Host: 192.168.51.165:43746
db: NULL
Command: Binlog Dump
Time: 767
State: Has sent all binlog to slave; waiting for binlog to be updated
Info: NULL
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
slave:12等待master发送更新信息。13等待本身I"O线程的数据写入
*************************** 3. row ***************************
Id: 12
User: system user
Host:
db: NULL
Command: Connect
Time: 470
State: Waiting for master to send event
Info: NULL
*************************** 4. row ***************************
Id: 13
User: system user
Host:
db: NULL
Command: Connect
Time: 359
State: Has read all relay log; waiting for the slave I/O thread to update it
Info: NULL
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
如果show processlist\G;可以看到上面的信息,那代表slave机建立成功。在master上所做的数据更改会马上表现到slave机。
【编辑推荐】