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;