您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“MySQL移動數據目錄后啟動失敗怎么解決”,內容詳細,步驟清晰,細節處理妥當,希望這篇“MySQL移動數據目錄后啟動失敗怎么解決”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。
由于安裝數據庫時將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 not open log file.
2023-02-27T10:38:09.240657+08:00 0 [ERROR] [MY-010041] [Server] Can't init tc log
2023-02-27T10:38:09.240718+08:00 0 [ERROR] [MY-010119] [Server] Aborting
2023-02-27T10:38:10.548605+08:00 0 [System] [MY-010910] [Server] /data/mysql80/svr/mysql/bin/mysqld: 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 &
數據庫啟動成功。
需要注意的是,如果該實例還作為其他實例的從節點,還需要設置 relaylog.index 文件中relay log的絕對路徑,否則會報如下錯誤: 錯誤日志報錯:
2023-02-27T15:56:55.224372+08:00 0 [ERROR] [MY-010599] [Repl] log /mysql80/dbdata/data5002/log/relaylog.000002 listed in the index, but failed to stat.
2023-02-27T15:56:55.224422+08:00 0 [ERROR] [MY-011059] [Repl] Error counting relay log space.
2023-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 present in 'mysql.slave_master_info' table, consider deleting it.
2023-02-27T15:56:55.226622+08:00 0 [ERROR] [MY-010529] [Repl] Failed to create or recover replication info repositories.
執行 start replica 時也會報錯:
# 客戶端報錯
mysql> 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 initialize relay log info structure from the repository, Error_code: MY-013124
修改 relaylog.index
文件中relay log的絕對路徑
sed -i 's#/mysql80#/data/mysql80#g' relaylog.index
重新啟動數據庫,并啟動主從復制
# 重啟實例 mysql> restart; # 啟動主從復制 mysql> start replica;
此時主從復制恢復正常。
讀到這里,這篇“MySQL移動數據目錄后啟動失敗怎么解決”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。