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;