ERROR 1198 (HY000): This operation cannot be performed with a running slave; run_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2644 | 回复: 0   主题: ERROR 1198 (HY000): This operation cannot be performed with a running slave; run        下一篇 
solo9867
注册用户
等级:新兵
经验:61
发帖:71
精华:0
注册:2011-12-15
状态:离线
发送短消息息给solo9867 加好友    发送短消息息给solo9867 发消息
发表于: IP:您无权察看 2014-11-26 9:28:32 | [全部帖] [楼主帖] 楼主

今天做mysql主从时出现"ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE firs" 

这个错误

 Replication consists of following 3 parts….

The master records changes to its data in its binary log (Binary Log Events).

The slave copies the master’s binary log events to its relay log.

The slave replays the events in the relay log, applying the changes to its own

data using Slave Thread.

The basic steps to set up replication are…

Set up replication accounts on master server.

Configure the master and slave.

Instruct the slave to connect to and replicate from the master.

Here are few assumptions….

Master IP Address: 192.168.1.215

Slave IP Address: Â  192.168.1.203

Replication User: replication

User Password: slave

The I/O Slave Thread (it runs on Slave Server) makes a TCP/IP connection to the master. Thats why we need to create an user account on Master Server with proper privileges.

Now run the following query on Master to create a Slave account….

mysql>  GRANT REPLICATION SLAVE ON *.* TO ‘replication‘@’192.168.1.203′ IDENTIFIED BY ’slave’;

Now edit my.cnf file on Master accordingly.

[mysqld]

server-id                       = 1

log-bin                          = mysql-bin

log-bin-index                = mysql-log-bin.index

relay-log                       = mysql-relay-bin

relay-log-index             = mysql-relay-bin.index

expire_logs_days         = 10

max_binlog_size          = 100M

binlog_do_db               = [Database Name to be Replicated]

binlog_ignore_db         = [Database Name not to be Replicated]

#binlog_ignore_db       = [Database Name not to be Replicated] (for more than one data base which is not supposed to be replicated)

datadir                          = /var/lib/mysql

tmpdir                           = /tmp

Now restart Master mysql server and run the following query…

mysql>  SHOW MASTER STATUS;

Now edit my.cnf file on Slave accordingly…..

[mysqld]

server_id                = 2

master_host            = 192.168.1.215

master_user            = replication

master_password   = slave

master_port            = 3306

relay_log                = mysql-relay-bin

relay-log-index       = mysql-relay-bin.index

We can set the value for master_host, master_user and master_password using mysql query. So it is better to avoid setting those values  directly from configuration file.

If master is having data already, insert the data from master server to slave server database or each of the databases.

Copy master database back up inside slave server and run  the following command on slave….

mysql -u[username] -p[password] [database name] < directory_path/[database.sql]

Now Restart Mysql Slave server and  run following query to synchronize master and slave….

mysql> CHANGE MASTER TO MASTER_HOST=’192.168.1.215′, MASTER_USER=’replication’, MASTER_PASSWORD=’slave’, MASTER_LOG_FILE=’mysql-bin.000004′, MASTER_LOG_POS=570;

Note: MASTER_LOG_FILE and MASTER_LOG_POS values have been taken from the result of SHOW MASTER STATUS

If a Slave is already running on your Slave Server,  Mysql Server will throw a error like…

ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first

So run..

mysql> STOP SLAVE;

And  run the query for CHANGING MASTER again.

If it shows an error like..

ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log

Run…

mysql> RESET SLAVE;

And  run the query for CHANGING MASTER again.

Finally start slave on slave server using..

mysql> START SLAVE;

mysql> SHOW SLAVE STATUS\G

Congrats! Mysql Master-Slave Replication has been set up

Also we will be able to see the Replication Threads in the process list on both the Master and the Slave.

So simply run…

mysql> SHOW PROCESSLIST.

--转自 北京联动北方科技有限公司




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论