Linux下修改MySQL數(shù)據(jù)庫(kù)數(shù)據(jù)文件路徑的步驟
使用rpm安裝方式安裝完MySQL數(shù)據(jù)庫(kù)后,數(shù)據(jù)文件的默認(rèn)路徑為/var/lib/mysql,然而根目錄并不適合用于存儲(chǔ)數(shù)據(jù)文件。
原路徑:/var/lib/mysql
目標(biāo)路徑:/home/mysql_data/mysql
Linux系統(tǒng)版本:centos7.6
MySQL數(shù)據(jù)庫(kù)版本:5.7.25
步驟:
1、創(chuàng)建目標(biāo)路徑
mkdir -p /home/mysql_data
2、關(guān)閉MySQL
systemctl stop mysqld
3、復(fù)制數(shù)據(jù)文件
cp -arp /var/lib/mysql /home/mysql_data
4、修改配置文件/etc/my.cnf
將datadir和socket中的原路徑修改為目標(biāo)路徑
datadir=/home/mysql_data/mysql socket=/home/mysql_data/mysql/mysql.sock
5、啟動(dòng)MySQL服務(wù)
systemctl start mysqld
NOTE:
1、報(bào)錯(cuò)如下:
2019-12-22T08:32:42.430564Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-12-22T08:32:42.430599Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-12-22T08:32:42.430616Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-12-22T08:32:42.430898Z 0 [ERROR] InnoDB: The innodb_temporary data file 'ibtmp1' must be writable
2019-12-22T08:32:42.430923Z 0 [ERROR] InnoDB: The innodb_temporary data file 'ibtmp1' must be writable
2019-12-22T08:32:42.430936Z 0 [ERROR] InnoDB: Could not create the shared innodb_temporary.
2019-12-22T08:32:42.430952Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2019-12-22T08:32:43.038973Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-12-22T08:32:43.039021Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-12-22T08:32:43.039037Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-12-22T08:32:43.039046Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-12-22T08:32:43.039056Z 0 [ERROR] Failed to initialize builtin plugins.
2019-12-22T08:32:43.039063Z 0 [ERROR] Aborting
解決:
執(zhí)行命令:
setenforce 1
再重新啟動(dòng)
2、報(bào)錯(cuò)如下:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
解決:
修改配置文件my.cnf,添加或修改如下配置:
[client] socket = /home/mysql_data/mysql/mysql.sock
總結(jié)
以上所述是小編給大家介紹的Linux下修改MySQL數(shù)據(jù)庫(kù)數(shù)據(jù)文件路徑,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
Mysql一對(duì)多輕松實(shí)現(xiàn)追蹤歷史首條記錄
本文介紹了在數(shù)據(jù)庫(kù)中處理一對(duì)多關(guān)系時(shí),如何使用JOIN和WHERE子句來(lái)找到每個(gè)主表記錄對(duì)應(yīng)的子表中特定記錄(例如時(shí)間最早的記錄),通過(guò)將B表與自身進(jìn)行比較并使用MIN()函數(shù),可以精確匹配到所需記錄2024-12-12
使用bin-log日志還原數(shù)據(jù)庫(kù)的例子
使用bin-log日志還原數(shù)據(jù)庫(kù)的例子,供大家學(xué)習(xí)參考2013-02-02
MySQL數(shù)據(jù)庫(kù)完全備份與增量備份詳解
這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)完全備份與增量備份詳解,完全備份就是將數(shù)據(jù)庫(kù)中的數(shù)據(jù)及所有對(duì)象全部備份,具體詳細(xì)內(nèi)容需要的朋友可以參考一下2022-08-08
MySQL合并查詢(xún)結(jié)果的實(shí)現(xiàn)
本文主要介紹了MySQL合并查詢(xún)結(jié)果的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03
使用SKIP-GRANT-TABLES 解決 MYSQL ROOT密碼丟失
這篇文章主要介紹了使用SKIP-GRANT-TABLES 解決 MYSQL ROOT密碼丟失的相關(guān)資料,需要的朋友可以參考下2015-09-09
MySQL中TIMESTAMP類(lèi)型返回日期時(shí)間數(shù)據(jù)中帶有T的解決
這篇文章主要介紹了MySQL中TIMESTAMP類(lèi)型返回日期時(shí)間數(shù)據(jù)中帶有T的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12

