Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 478|回复: 0

MySQL服务器修改主机名后问题解决

[复制链接]
  • TA的每日心情
    奋斗
    2024-11-24 15:47
  • 签到天数: 804 天

    [LV.10]以坛为家III

    2053

    主题

    2111

    帖子

    72万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    726782
    发表于 2021-5-24 15:02:55 | 显示全部楼层 |阅读模式

    1、单机MySQL主机名修改

    今天无事看到自己的主机名不对,于是改了一下,以便区分服务器,那只重启MySQL时出现下面错误:

     

    MySQL manager or server PID file could not be found!       [FAILED]
    Starting MySQL.Manager of pid-file quit without updating fi[FAILED]

     

    怎么会找不到PID呢,看下面:

    [root@daban114.com ~]#  ps aux | grep mysql
    mysql    16433  0.0  0.2  36636  5756 ?        Sl   15:07   0:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql --log-error=/usr/local/mysql/var/hao9goAndSecondWeb.err --pid-file=/usr/local/mysql/var/hao9goAndSecondWeb.pid --socket=/tmp/mysql.sock --port=3306
    root     16992  0.0  0.0   4020   704 pts/0    S+   15:11   0:00 grep mysql

    原来PID还是原来主机名.pid,运行:

    kill -9 <mysqlpid> 然后 service mysql start 哈哈看到绿色的OK了,

    [root@daban114 ~]# service mysql start
    Starting MySQL.                                            [  OK  ]

     

    [mysql@master ~]$ /etc/init.d/mysql restart
    MySQL server PID file could not be found! [FAILED]
    Starting MySQL..^[[A.......................................[FAILED]....................................................
    .The server quit without updating PID file (/usr/local/mysql5.6/data/master.pid).
    [mysql@master ~]$ /etc/init.d/mysql restart

    mysql 修改主机名后 ,手动kill进程 重启

     

    2、MySQL从库主机名修改

    环境:MySQL5.6 + CentOS6.5

      问题描述:从库修改主机名后,从库的同步没有自动启动,用start slave命令开启失败

      从库修改主机名后,从库的同步没有自动启动,查看状态如下:

      mysql> show slave statusG

      *************************** 1. row ***************************

      Slave_IO_State:

      Master_Host: 192.168.1.2

      Master_User: manager_slave

      Master_Port: 3306

      Connect_Retry: 10

      Master_Log_File: logbin.000053

      Read_Master_Log_Pos: 588641410

      Relay_Log_File: zzstep-relay-bin.000015

      Relay_Log_Pos: 38778474

      Relay_Master_Log_File: logbin.000053

      Slave_IO_Running: No

      Slave_SQL_Running: No

      Replicate_Do_DB:

      Replicate_Ignore_DB: mysql,information_schema,performance_schema

      Replicate_Do_Table:

      Replicate_Ignore_Table:

      Replicate_Wild_Do_Table:

      Replicate_Wild_Ignore_Table: hn.sphinx%

      Last_Errno: 0

      Last_Error:

      Skip_Counter: 0

      Exec_Master_Log_Pos: 588641410

      Relay_Log_Space: 0

      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: NULL

      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: 0

      Master_UUID: 8ce09c46-a7be-11e4-8e06-0050569f4b5b

      Master_Info_File: /opt/mysql_data/master.info

      SQL_Delay: 0

      SQL_Remaining_Delay: NULL

      Slave_SQL_Running_State:

      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)

      使用start slave命令开启失败:

      mysql> start slave;

      ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository

      使用reset slave命令解决:

      mysql> reset slave;

      Query OK, 0 rows affected (0.01 sec)

      mysql> start slave;

      Query OK, 0 rows affected (0.03 sec)

      mysql> show slave statusG

      *************************** 1. row ***************************

      Slave_IO_State: Queueing master event to the relay log

      Master_Host: 192.168.1.2

      Master_User: manager_slave

      Master_Port: 3306

      Connect_Retry: 10

      Master_Log_File: logbin.000021

      Read_Master_Log_Pos: 11215004

      Relay_Log_File: db_mysql_02-relay-bin.000007

      Relay_Log_Pos: 22097

      Relay_Master_Log_File: logbin.000005

      Slave_IO_Running: Yes

      Slave_SQL_Running: Yes

      Replicate_Do_DB:

      Replicate_Ignore_DB: mysql,information_schema,performance_schema

      Replicate_Do_Table:

      Replicate_Ignore_Table:

      Replicate_Wild_Do_Table:

      Replicate_Wild_Ignore_Table: hn.sphinx%

      Last_Errno: 0

      Last_Error:

      Skip_Counter: 0

      Exec_Master_Log_Pos: 21937

      Relay_Log_Space: 13113813

      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: 1071515

      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: 11

      Master_UUID: 8ce09c46-a7be-11e4-8e06-0050569f4b5b

      Master_Info_File: /opt/mysql_data/master.info

      SQL_Delay: 0

      SQL_Remaining_Delay: NULL

      Slave_SQL_Running_State: creating table

      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)

      mysql>

      总结:

      由于修改主机名后,relay-log的名称发生变化,导致文件IO失败,reset slave可以重新定位。

        文章来源:http://huangfuff.blog.51cto.com/2632203/1610429

     

    如果修改了从库的主机名,而从库又忘了做relay-log和relay-log-index的配置,估计会导致从库同步失败。由于公司刚改了主机名,写个博客,后续出问题好进行改进。方案测试通过。

    步骤如下:

    1: 从库先停止主从复制

        stop slave;

    2: 记录下主从同步的信息(主要是以下两个信息)

        show slave status\G

        Master_Log_File: mysql-bin.000085

        Read_Master_Log_Pos: 120

    3: 重置数据库

        reset slave;

            --> 在这里,最好设置一个两个参数,预防后续再改主机名

                relay-log = relay-log

                relay-log-index = relay-log.index

    4: 如果主库设置给从库的用户名和密码忘记了话,再grant一次(记得就跳过这步了)

        grant replication slave on *.* to 'replication'@'192.168.1.2' identified by 'xxx';

    5: 从库设置slave

        change master to master_log_file='mysql-bin.000085',master_log_pos=120,master_user='replication',master_password='xxx', master_host='192.168.1.1';

    6: 开启从库

        start slave;

    另外,再reset slave后感觉得配置下relay-log和relay-log-index,然后重启下数据。再从第5步开始,这样后续改主机名就不会影响到了。

     

    如果是主库没指定bin-log和bin-log-index,那修改主机名后会怎么样,不知道会产生什么样的问题和应对方案该怎么样。暂时方案如下:

        1: 在mysql上找到主的位置,应该是一开始的。位置:4

            show master status\G

            --> 其实这里,如果改了主机名,最好在配置里面指定两个参数(后续改主机就没事了)

                log-bin=master-bin

                log-bin-index = masters-bin.index

        2: 先把从库停止

            stop slave;

        3: 把之前从库的同步信息全部去掉

            reset slave;

        4: 然后指向主的第一个位置开始同步

            change master to master_log_file='master-bin.000001',master_log_pos=4,master_user='replication',master_password='xxx', master_host='192.168.1.1';

        5: 再开启从应该就可以了

            start slave;

     

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2025-1-23 09:24 , Processed in 0.059890 second(s), 27 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表