Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1754293
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: Mysql/postgreSQL

2012-11-13 00:36:45

最近单位在用DB2 Q-replication,因此先拿mysql的master/slave进行安装测试,具体的步骤如下:
MYSQL version

点击(此处)折叠或打开

  1. C:\Program Files\MariaDB 5.5\bin>mysql --version
  2. mysql Ver 15.1 Distrib 5.5.25-MariaDB, for Win32 (x86)
以下为在一天电脑上面的实施步骤:
1 instal master  mysql  instance 
2 install  slave mysql instance 
method: 
copy  installed file C:\Program Files\MariaDB 5.5 to a new disk :E:\slave
3  install service  of slave  instance 

点击(此处)折叠或打开

  1. E:\slave\bin>mysqld.exe --install slave --default-flie=e:\salve\my.ini
  2. Service successfully installed.
4 config slave file file 
C:\Program Files\MariaDB 5.5\data、my.ini

点击(此处)折叠或打开

  1. [mysqld]
  2. datadir=C:/Program Files/MariaDB 5.5/data
  3. port=3306
  4. sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
  5. default_storage_engine=innodb
  6. innodb_buffer_pool_size=396M
  7. innodb_flush_log_at_trx_commit = 2
  8. innodb_log_file_size=50M
  9. server-id =1
  10. log-bin=mysql-bin
  11. [client]
  12. port=3306

E:\slave\data\my.ini

点击(此处)折叠或打开

  1. [mysqld]
  2. datadir=e:/slave/data
  3. port=3309
  4. sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
  5. default_storage_engine=innodb
  6. innodb_buffer_pool_size=396M
  7. innodb_flush_log_at_trx_commit = 2 
  8. innodb_log_file_size=50M
  9. server-id =127 
  10. [client]
  11. port=3309

5 start master,slave services

点击(此处)折叠或打开

  1. E:\slave\bin>net start slave
  2. slave 服务正在启动 ..
  3. slave 服务已经启动成功。


  4. E:\slave\bin>net start mysql
  5. MySQL 服务正在启动 ..
  6. MySQL 服务已经启动成功。
6 在master上创建一个slave账户以用来执行replication

点击(此处)折叠或打开

  1. C:\Program Files\MariaDB 5.5\bin>mysql -uroot -p
  2. Enter password: *********
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is 1
  5. Server version: 5.5.25-MariaDB mariadb.org binary distribution

  6. This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  7. and you are welcome to modify and redistribute it under the GPL v2 license

  8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  9. MariaDB [(none)]> \u mysql
  10. Database changed
  11. MariaDB [mysql]> grant replication slave on *.* to 'slaveuser'@localhost identi
  12. fied by 'xxxxxx'
  13.     -> ;
  14. Query OK, 0 rows affected (0.04 sec)
6 在复制之前,确认master instance开启了如下参数
serverid =1 
log-bin=mysql-bin

点击(此处)折叠或打开


  1. MariaDB [(none)]> show variables like 'ser%' \G;
  2. *************************** 1. row ***************************
  3. Variable_name: server_id
  4.         Value: 1
  5. 1 row in set (0.00 sec)
  6. MariaDB [(none)]> show variables like 'log%' \G;
  7. *************************** 1. row ***************************
  8. Variable_name: log
  9.         Value: OFF
  10. *************************** 2. row ***************************
  11. Variable_name: log_bin
  12.         Value: ON
  13. *************************** 3. row ***************************

修该slave 库是使用相同的设置

点击(此处)折叠或打开

  1. MariaDB [(none)]> show variables like 'ser%' \G;
  2. *************************** 1. row ***************************
  3. Variable_name: server_id
  4.         Value: 127
  5. 1 row in set (0.00 sec)
subscribe master database 
定制你要replication的DB,myblog
master首先设置读锁,读取日志文件名和偏移量,备份要同步的数据库,然后解锁

点击(此处)折叠或打开

  1. MariaDB [(none)]> show databases;
  2. +--------------------+
  3. | Database |
  4. +--------------------+
  5. | information_schema |
  6. | myblog |
  7. | mysql |
  8. | performance_schema |
  9. | test |
  10. +--------------------+
  11. 5 rows in set (0.00 sec)

做到这步卡住了,明天晚上不上,相对来说还是比较简单的,
E:\slave\bin>mysql -uroot -p  --database=myblog < dump.sql
Enter password: *********
ERROR at line 1478: Unknown command '\''.
备份文件在导入到新表的时候报错~~~~~~~~~~~~~~字符集不兼容,
解决方法:

点击(此处)折叠或打开

  1. E:\slave\bin>mysql -u root -p --default-character-set=utf8 slaveblog < dump.sql
  2. Enter password: *********
8 使用命令开启复制过程

在执行该命令之前,首先确定master的状态:

点击(此处)折叠或打开

  1. MariaDB [(none)]> show master status \G;
  2. *************************** 1. row ***************************
  3.             File: mysql-bin.000002
  4.         Position: 245
  5.     Binlog_Do_DB:
  6. Binlog_Ignore_DB:
  7. 1 row in set (0.00 sec)
在slave上执行

 点击(此处)折叠或打开

  1. change master to
  2.  master_host='127.0.0.1',
  3.  master_user='slaveuser',
  4.  master_password='xxxxxxxx',
  5.  master_log_file='mysql-bin.000002',
  6.  master_log_pos=245,
  7.  master_port=3306,
  8.  master_connect_retry=10;
启动服务,请确定结果

点击(此处)折叠或打开

  1. MariaDB [(none)]> start slave;
  2. Query OK, 0 rows affected (0.00 sec)

  3. MariaDB [(none)]> show slave status \G;
  4. *************************** 1. row ***************************
  5.                Slave_IO_State: Waiting for master to send event
  6.                   Master_Host: 127.0.0.1
  7.                   Master_User: slaveuser
  8.                   Master_Port: 3306
  9.                 Connect_Retry: 10
  10.               Master_Log_File: mysql-bin.000002
  11.           Read_Master_Log_Pos: 245
  12.                Relay_Log_File: kinfinger-PC-relay-bin.000002
  13.                 Relay_Log_Pos: 529
  14.         Relay_Master_Log_File: mysql-bin.000002
  15.              Slave_IO_Running: Yes
  16.             Slave_SQL_Running: Yes
  17.               Replicate_Do_DB:
  18.           Replicate_Ignore_DB:
  19.            Replicate_Do_Table:
  20.        Replicate_Ignore_Table:
  21.       Replicate_Wild_Do_Table:
  22.   Replicate_Wild_Ignore_Table:
  23.                    Last_Errno: 0
  24.                    Last_Error:
  25.                  Skip_Counter: 0
  26.           Exec_Master_Log_Pos: 245
  27.               Relay_Log_Space: 830
  28.               Until_Condition: None
  29.                Until_Log_File:
  30.                 Until_Log_Pos: 0
  31.            Master_SSL_Allowed: No
  32.            Master_SSL_CA_File:
  33.            Master_SSL_CA_Path:
  34.               Master_SSL_Cert:
  35.             Master_SSL_Cipher:
  36.                Master_SSL_Key:
  37.         Seconds_Behind_Master: 0
  38. Master_SSL_Verify_Server_Cert: No
  39.                 Last_IO_Errno: 0
  40.                 Last_IO_Error:
  41.                Last_SQL_Errno: 0
  42.                Last_SQL_Error:
  43.   Replicate_Ignore_Server_Ids:
  44.              Master_Server_Id: 1
  45. 1 row in set (0.00 sec)

  46. ERROR: No query specified
进行验证测试: 
master上执行 :

点击(此处)折叠或打开

  1. MariaDB [myblog]> create table rep( id int not null) engine=innodb;
  2. Query OK, 0 rows affected (0.17 sec)

  3. MariaDB [myblog]> insert into rep values(8);
  4. Query OK, 1 row affected (0.00 sec)

SLAVE DO :

点击(此处)折叠或打开

  1. MariaDB [myblog]> select * from rep ;
  2. +----+
  3. | id |
  4. +----+
  5. | 8 |
  6. +----+
  7. 1 row in set (0.00 sec)

有上可知,我们的replication已经成功
阅读(1284) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~