由於安裝資料庫時將MySQL的資料目錄放在了根目錄下,現在儲存空間不足,想透過mv將資料目錄移到其他目錄下,但將資料目錄移到其他資料目錄後,啟動資料庫失敗。
本測試基於MySQL 8.0.31
mysql> shutdown; Query OK, 0 rows affected (0.02 sec)
shell> pwd /mysql80
shell> mv /mysql80 /data shell> cd /data/mysql80/svr shell> ln -s mysql-8.0.31-linux-glibc2.12-x86_64 mysql
shell> chown -R mysql.mysql /data
shell> sed -i 's#/mysql80#/data/mysql80#g' my5001.cnf
shell> /data/mysql80/svr/mysql/bin/mysqld_safe \ --defaults-file=/data/mysql80/conf/my5001.cnf --user=mysql &
此時啟動資料庫失敗,錯誤日誌錯誤如下:
這裡報錯顯示找不到mysqld: File '/mysql80/dbdata/data5001/log/binlog .000012' not found (OS errno 2 - No such file or directory)
2023-02-27T10:38:09.240576 08:00 0 [ERROR] [MY-010958] [Server] Could filenot. ##2023-02-27T10:38:09.240657 08:00 0 [ERROR] [MY-010041] [Server] Can't init tc log
2023-02-27T10:38:09.240718 ] [MY-010119] [Server] Aborting
2023-02-27T10:38:10.548605 08:00 0 [System] [MY-010910] [Server] /data/mysql80/svr/mysql/bin/msql Shutdown complete (mysqld 8.0.31) MySQL Community Server - GPL.
binlog文件,並且報錯顯示的
binlog的目錄還是之前的,但是設定檔中的目錄已經修改
shell> grep 'log-bin' my5001.cnf log-bin=/data/mysql80/dbdata/data5001/log/binlog log-bin-trust-function-creators
binlog.index檔案中存放著每個
binlog檔案的絕對路徑位址,這裡的路徑還是之前路徑,內容如下:
shell> cat binlog.index /mysql80/dbdata/data5001/log/binlog.000001 /mysql80/dbdata/data5001/log/binlog.000002 /mysql80/dbdata/data5001/log/binlog.000003 /mysql80/dbdata/data5001/log/binlog.000004 /mysql80/dbdata/data5001/log/binlog.000005 /mysql80/dbdata/data5001/log/binlog.000006 /mysql80/dbdata/data5001/log/binlog.000007 /mysql80/dbdata/data5001/log/binlog.000008 /mysql80/dbdata/data5001/log/binlog.000009 /mysql80/dbdata/data5001/log/binlog.000010 /mysql80/dbdata/data5001/log/binlog.000011 /mysql80/dbdata/data5001/log/binlog.000012
binlog.index檔案中
binlog的絕對路徑:
shell> sed -i 's#/mysql80#/data/mysql80#g' binlog.index shell> cat binlog.index /data/mysql80/dbdata/data5001/log/binlog.000001 /data/mysql80/dbdata/data5001/log/binlog.000002 /data/mysql80/dbdata/data5001/log/binlog.000003 /data/mysql80/dbdata/data5001/log/binlog.000004 /data/mysql80/dbdata/data5001/log/binlog.000005 /data/mysql80/dbdata/data5001/log/binlog.000006 /data/mysql80/dbdata/data5001/log/binlog.000007 /data/mysql80/dbdata/data5001/log/binlog.000008 /data/mysql80/dbdata/data5001/log/binlog.000009 /data/mysql80/dbdata/data5001/log/binlog.000010 /data/mysql80/dbdata/data5001/log/binlog.000011 /data/mysql80/dbdata/data5001/log/binlog.000012
shell> /data/mysql80/svr/mysql/bin/mysqld_safe --defaults-file=/data/mysql80/conf/my5001.cnf --user=mysql &
2023-02-27T15:56:55.224372 08:00 0 [ERROR] [MY-010599] [Repl] log /mysql80/dbdata/data5002/log/log relaylog.000002 listed in the index, but failed to stat.mysql> start replica;2023-02-27T15:56:55.224422 08:00 0 [ERROR] [MY-011059] [Repl] Error counting relaylog -02-27T15:56:55.226571 08:00 0 [ERROR] [MY-010426] [Repl] Slave: Failed to initialize the master info structure for channel ''; its record may still be preslent in 'mysql. , consider deleting it.
客戶端報錯
2023-02-27T15:56:55.226622 08:00 0 [ERROR] [MY-010529] [Repl] Failed to create or recover repli010529] [Repl] Failed to create or recover repli010529] [Repl] Failed to create or recover repli.執行start replica 時也會報錯:
ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository
# error log報錯2023-02-27T15:57:53.858798 08:00 8 [ERROR] [MY-013124] [Repl] Slave SQL for channel '': Slave failed to initialinfo relay log log repository, Error_code: MY-013124檔案中relay log的絕對路徑relaylog.index
10.問題解決
修改
sed -i 's#/mysql80#/data/mysql80#g' relaylog.index
# 重启实例 mysql> restart; # 启动主从复制 mysql> start replica;
此時主從複製恢復正常。
以上是MySQL行動資料目錄後啟動失敗怎麼解決的詳細內容。更多資訊請關注PHP中文網其他相關文章!