標籤:

MySQL變更datadir------CentOS7

默認安裝的datadir是/var/lib/mysql,具體見/etc/my.cnf文件

[mysqld]## Remove leading # and set to the amount of RAM for the most important data# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.# innodb_buffer_pool_size = 128M## Remove leading # to turn on a very important data integrity option: logging# changes to the binary log between backups.# log_bin## Remove leading # to set options mainly useful for reporting servers.# The server defaults are faster for transactions and fast SELECTs.# Adjust sizes as needed, experiment to find the optimal values.# join_buffer_size = 128M# sort_buffer_size = 2M# read_rnd_buffer_size = 2Mdatadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0

如果該文件夾所在盤空間不足,可以更換至,比如/home目錄下,具體操作如下:

1、home目錄下建立data目錄

cd /homemkdir data

2、把MySQL服務進程停掉:

mysqladmin -u root -p shutdown

3、把/var/lib/mysql整個目錄移到/home/data

mv /var/lib/mysql /home/data/

這樣就把MySQL的數據文檔移動到了/home/data/mysql下。

4、編輯MySQL的配置文檔/etc/my.cnf。操作如下:

[mysqld]# Remove leading # and set to the amount of RAM for the most important data# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.# innodb_buffer_pool_size = 128M## Remove leading # to turn on a very important data integrity option: logging# changes to the binary log between backups.# log_bin## Remove leading # to set options mainly useful for reporting servers.# The server defaults are faster for transactions and fast SELECTs.# Adjust sizes as needed, experiment to find the optimal values.# join_buffer_size = 128M# sort_buffer_size = 2M# read_rnd_buffer_size = 2Mdatadir=/home/data/mysqlsocket=/home/data/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0

5、最後 做一個mysql.sock 鏈接,很重要:

ln -s /home/data/mysql/mysql.sock /var/lib/mysql/mysql.sock

6、啟動mysqld

systemctl restart mysqld

此時,一般可以啟動了。


以下是可能遇到的坑:

7.selinux惹的禍,centos系統默認會開啟selinux

解決方法:關閉它,打開/etc/selinux/config,把SELINUX=enforcing改為SELINUX=disabled後存檔退出重啟機器試試。

1.可能是/usr/local/mysql/data/rekfan.pid文件沒有寫的許可權

解決方法 :給予許可權,執行 「chown -R mysql:mysql /var/data」 「chmod -R 755 /usr/local/mysql/data」 然後重新啟動mysqld!

2.可能進程里已經存在mysql進程

解決方法:用命令「ps -ef|grep mysqld」查看是否有mysqld進程,如果有使用「kill -9 進程號」殺死,然後重新啟動mysqld!

3.可能是第二次在機器上安裝mysql,有殘餘數據影響了服務的啟動。

解決方法:去mysql的數據目錄/data看看,如果存在mysql-bin.index,就趕快把它刪除掉吧,它就是罪魁禍首了。本人就是使用第三條方法解決的 !blog.rekfan.com/?

4.mysql在啟動時沒有指定配置文件時會使用/etc/my.cnf配置文件,請打開這個文件查看在[mysqld]節下有沒有指定數據目錄(datadir)。

解決方法:請在[mysqld]下設置這一行:datadir = /usr/local/mysql/data

5.skip-federated欄位問題

解決方法:檢查一下/etc/my.cnf文件中有沒有沒被注釋掉的skip-federated欄位,如果有就立即注釋掉吧。

6.錯誤日誌目錄不存在

解決方法:使用「chown」 「chmod」命令賦予mysql所有者及許可權


推薦閱讀:

MySQL cheat sheet
知識布局-grafana-mysql
我是如何開始閱讀MySQL源碼的?
國內做分散式資料庫開發的現狀如何,有怎樣的發展前景?
R markdown 連接mysql數據

TAG:MySQL |