在生产环境中有时候需要修改复制用户账户的密码,比如密码遗失,或者由于多个不同的复制用户想统一为单独一个复制账户。对于这些操作应尽可能慎重以避免操作不同导致主从不一致而需要进行修复。本文描述了修改复制账户密码以及变更复制账户。 1、更改复制账户密码[sql] view plaincopyprint?--演示环境,同一主机上的2个实例,主3406,从3506  --当前版本,注:master账户表明是对主库进行相关操作,slave则是对从库进行相关操作  master@localhost[(none)]> show variables like 'version';  +---------------+------------+  | Variable_name | Value      |  +---------------+------------+  | version       | 5.6.12-log |  +---------------+------------+    --主库上的记录  master@localhost[test]> select * from tb1;  +------+-------+  | id   | name  |  +------+-------+  |    1 | robin |  +------+-------+    --从库上的记录  slave@localhost[test]> select * from tb1;  +------+-------+  | id   | name  |  +------+-------+  |    1 | robin |  +------+-------+    --当前从库上的状态信息  slave@localhost[test]> show slave status\G  *************************** 1. row ***************************                 Slave_IO_State: Waiting for master to send event                    Master_Host: 192.168.1.177                    Master_User: repl                    Master_Port: 3406                  Connect_Retry: 60                Master_Log_File: inst3406bin.000001            Read_Master_Log_Pos: 3296006                 Relay_Log_File: relay-bin.000002                  Relay_Log_Pos: 811          Relay_Master_Log_File: inst3406bin.000001               Slave_IO_Running: Yes              Slave_SQL_Running: Yes                Replicate_Do_DB: test,sakila   --仅复制了test以及sakila数据库            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: 3296006                Relay_Log_Space: 978             --主库上复制账户的信息  master@localhost[test]> show grants for 'repl'@'192.168.1.177';  +----------------------------------------------------------------------------------------------------------------+  | Grants for repl@192.168.1.177                                                                                  |  +----------------------------------------------------------------------------------------------------------------+  | GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.177' IDENTIFIED BY PASSWORD '*A424E797037BF191C5C2038C039' |  +----------------------------------------------------------------------------------------------------------------+    --修改复制账户密码  master@localhost[test]> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.1.177' IDENTIFIED BY 'replpwd';    --如下查询密码已更改  master@localhost[test]> select user,host,password from mysql.user where user='repl';  +------+---------------+-------------------------------------------+  | user | host          | password                                  |  +------+---------------+-------------------------------------------+  | repl | 192.168.1.177 | *4A04E4FD524292A79E3DCFEBBD46094478F178EF |  +------+---------------+-------------------------------------------+    --更新记录  master@localhost[test]> insert into tb1 values(2,'fred');    --重库上可以查询到刚刚被更新的记录  slave@localhost[test]> select * from tb1;  +------+-------+  | id   | name  |  +------+-------+  |    1 | robin |  |    2 | fred  |  +------+-------+    slave@localhost[test]> stop slave;  Query OK, 0 rows affected (0.02 sec)    slave@localhost[test]> start slave;  Query OK, 0 rows affected (0.01 sec)    --再次查看状态出现了错误提示  slave@localhost[test]> show slave status \G  *************************** 1. row ***************************                 Slave_IO_State: Connecting to master                    Master_Host: 192.168.1.177                    Master_User: repl                    Master_Port: 3406                  Connect_Retry: 60                Master_Log_File: inst3406bin.000001            Read_Master_Log_Pos: 3296438                 Relay_Log_File: relay-bin.000002                  Relay_Log_Pos: 1243          Relay_Master_Log_File: inst3406bin.000001               Slave_IO_Running: Connecting              Slave_SQL_Running: Yes                Replicate_Do_DB: test,sakila                        ....................                  Last_IO_Errno: 1045                  Last_IO_Error: error connecting to master 'repl@192.168.1.177:3406' - retry-time: 60  retries: 1    --更改重库连接密码,该信息记录在从库master.info文件中                  slave@localhost[test]> stop slave;    slave@localhost[test]> change master to                         -> master_user='repl',              -> master_password='replpwd';   Query OK, 0 rows affected, 2 warnings (0.00 sec)    --修改密码后,从库状态正常,以下检查结果不再列出  slave@localhost[test]> start slave;    --查看master.info,密码已更改且为名文  slave@localhost[(none)]> system grep repl /data/inst3506/data3506/master.info  repl  replpwd  2、更换复制账户及密码[sql] view plaincopyprint?master@localhost[test]> GRANT REPLICATION SLAVE ON *.* TO 'repl2'@'192.168.1.177' IDENTIFIED BY 'Repl2';  Query OK, 0 rows affected (0.00 sec)      slave@localhost[test]> stop slave;  Query OK, 0 rows affected (0.28 sec)    master@localhost[test]> insert into tb1 values(3,'jack');  Query OK, 1 row affected (0.00 sec)    slave@localhost[test]> change master to       -> MASTER_USER='repl2',      -> MASTER_PASSWORD='Repl2';  Query OK, 0 rows affected, 2 warnings (0.01 sec)    slave@localhost[test]> system more /data/inst3506/data3506/master.info  23  inst3406bin.000001  3294834  192.168.1.177  repl2  Repl2  3406    ..........    slave@localhost[test]> start slave;  Query OK, 0 rows affected (0.01 sec)    slave@localhost[test]> select * from tb1 where id=3;  +------+------+  | id   | name |  +------+------+  |    3 | jack |  +------+------+  1 row in set (0.00 sec)    slave@localhost[(none)]> show slave status \G  *************************** 1. row ***************************                 Slave_IO_State: Waiting for master to send event                    Master_Host: 192.168.1.177                    Master_User: repl2                    Master_Port: 3406                  Connect_Retry: 60                Master_Log_File: inst3406bin.000001  --Author :Leshami            Read_Master_Log_Pos: 3296871             --Blog   : http://blog.csdn.net/leshami                 Relay_Log_File: relay-bin.000002                  Relay_Log_Pos: 501          Relay_Master_Log_File: inst3406bin.000001               Slave_IO_Running: Yes              Slave_SQL_Running: Yes                Replicate_Do_DB: test,sakila  3、关于change masterCHANGE MASTER TO changes the parameters that the slave server uses for connecting to the masterserver, for reading the master binary log, and reading the slave relay log. It also updates the contentsof the master info and relay log info repositories (see Section 16.2.2, “Replication Relay and StatusLogs”). To use CHANGE MASTER TO, the slave replication threads must be stopped (use STOP SLAVEif necessary). In MySQL 5.6.11 and later, gtid_next [2060] must also be set to AUTOMATIC (Bug#16062608). Options not specified retain their value, except as indicated in the following discussion. Thus, in mostcases, there is no need to specify options that do not change. For example, if the password to connectto your MySQL master has changed, you just need to issue these statements to tell the slave about thenew password: STOP SLAVE; -- if replication was runningCHANGE MASTER TO MASTER_PASSWORD='new3cret';START SLAVE; -- if you want to restart replication MASTER_HOST, MASTER_USER, MASTER_PASSWORD, and MASTER_PORT provide information to theslave about how to connect to its master: Note: Replication cannot use Unix socket files. You must be able to connect to themaster MySQL server using TCP/IP. If you specify the MASTER_HOST or MASTER_PORT option, the slave assumes that the masterserver is different from before (even if the option value is the same as its current value.) In thiscase, the old values for the master binary log file name and position are considered no longerapplicable, so if you do not specify MASTER_LOG_FILE and MASTER_LOG_POS in the statement,MASTER_LOG_FILE='' and MASTER_LOG_POS=4 are silently appended to it. Setting MASTER_HOST='' (that is, setting its value explicitly to an empty string) is not the same asnot setting MASTER_HOST at all. Beginning with MySQL 5.5, trying to set MASTER_HOST to an emptystring fails with an error. Previously, setting MASTER_HOST to an empty string caused START SLAVEsubsequently to fail. (Bug #28796)

小编推荐:欲学习电脑技术、系统维护、网络管理、编程开发和安全攻防等高端IT技术,请 点击这里注册账号,公开课频道价值万元IT培训教程免费学,让您少走弯路、事半功倍,好工作升职加薪!

免责声明:本站系公益性非盈利IT技术普及网,本文由投稿者转载自互联网的公开文章,文末均已注明出处,其内容和图片版权归原网站或作者所有,文中所述不代表本站观点,若有无意侵权或转载不当之处请从网站右下角联系我们处理,谢谢合作!

mysql 复制用户_MySQL修改复制用户及密码相关推荐

  1. mysql授权无密码用户_MySQL下新建用户,授权,删除用户,修改密码

    一.创建一个新的用户. 创建用户的方式有两种: 1.create user:就是向用户管理表里插入一个新的用户. 2.最好的方法是使用GRANT语句,因为这样更精确,错误少.从MySQL 3.22.1 ...

  2. mysql 存储过程改用户_Mysql修改存储过程相关权限问题

    在使用mysql数据库经常都会遇到这么一个问题,其它用户定义的存储过程,现在使用另一个用户却无法修改或者删除等:正常情况下存储过程的定义者对它有修改.删除的权限:但是其它的用户就要相于的授权,不然无法 ...

  3. mysql怎么复制信息_mysql关于复制的一些信息参考

    1.主库的复制用户密码修改后,在备库修改复制: stop slave; change master to master_user='username', master_password='passwo ...

  4. 关闭mysql权限管理_MySQL系列:用户及权限管理

    一.权限介绍 1.权限类别:对象界别划分 库级别.表级别.字段级别.管理类权限.程序类权限 (1)库和表级别的权限:对于具体的库或者表进行授权操作 ALTER.CREATE.CREATE VIEW.D ...

  5. mysql replication 原理_MySQL Replication(复制)基本原理 | 学步园

    1.复制进程 Mysql的复制(replication)是一个异步的复制,从一个Mysql instace(称之为Master)复制到另一个Mysql instance(称之Slave).实现整个复制 ...

  6. mysql 同步 异步_MySQL异步复制、半同步复制详解

    MySQL数据复制的原理图大致如下: 从上图我们可以看出MySQL数据库的复制需要启动三个线程来实现: 其中1个在主服务器上,另两个在从服务器上.当发出START SLAVE时,从服务器创建一个I/O ...

  7. mysql 5.6 删除用户_mysql 新增 删除用户和权限分配

    1. 新增用户 mysql>insert into mysql.user(Host,User,Password) values("localhost","lionb ...

  8. mysql 恢复root用户_mysql误删root用户恢复方案

    linux下误删mysql的root用户,解决方法 开始对liunx界面不熟悉,可能由于不小心,把root误删了,怎么办? 1. # killall mysqld    干掉所有mysql进程 2. ...

  9. mysql权限表_MySQL 数据库赋予用户权限操作表

    MySQL清空数据库的操作:truncate table tablename; MySQL 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库对象 to 用户 一.grant 普通数据 ...

最新文章

  1. 最落寞的C9高校:从未没落
  2. K-means算法(理论+opencv实现)
  3. system.err android.os.NetworkOnmainThreadException 错误解决办法
  4. P1119 灾后重建(经典floyd)
  5. React-引领未来的用户界面开发框架-读书笔记(八)
  6. 正弦波 程序 角度传感器_激光位移传感器的原理及应用领域
  7. 表单新增元素与属性(control、placehoulder、list、AutoComplete、pattern、SelectionDirection、indeterminate属性)
  8. 计算机英语第六单元,计算机专业英语第六版第十单元课后汉译英,We do use other forms....这个do...
  9. 【BZOJ3999】旅游,树链剖分中的有向信息合并
  10. mysql存储引擎 索引优化_MySQL存储引擎,索引及基本优化策略
  11. 小米崔宝秋:小米 AIoT 深度拥抱开源
  12. RocketMQ在windows安装配置及使用
  13. 从三大标准衡量hypervisor
  14. C语言中的sqrt函数
  15. win10专业版激活(cmd方式)
  16. 《富爸爸穷爸爸》读书笔记 - 为什么要教授财务知识
  17. Abbyy FineReader PDF转word不乱码
  18. 比较正确的 iPhone7/7+ 的进入DFU的方法是这样的
  19. 简单易上手的理财方法介绍
  20. SQL 使用ADD_MONTHS或ADDDATE实现RFM参数—R(Recency)

热门文章

  1. IIFE(立即执行函数表达式)
  2. 如何把握好 transition 和 animation 的时序,创作描边按钮特效
  3. NativeScript - JS 构建跨平台的原生 APP
  4. 在Visual Studio Code中配置GO开发环境
  5. 自定义控件_VIewPager显示多个Item
  6. 财务部门:你需要多长时间才能够回答老板的这些问题?
  7. YYModel Summary
  8. 从代码里提取的测试需求
  9. 智能课程表Android版-学年学期星期的实现
  10. 孩子在华艺舞校的画画投稿-天女之梦