mysql更改数据库数据存储目录_MySQL更改数据库数据存储目录
MySQL數(shù)據(jù)庫(kù)默認(rèn)的數(shù)據(jù)庫(kù)文件位于/var/lib/mysql下,有時(shí)候由于存儲(chǔ)規(guī)劃等原因,需要更改MySQL數(shù)據(jù)庫(kù)的數(shù)據(jù)存儲(chǔ)目錄。下文總結(jié)整理了實(shí)踐過(guò)程的操作步驟。
1:確認(rèn)MySQL數(shù)據(jù)庫(kù)存儲(chǔ)目錄
[root@DB-Server?tmp]#?mysqladmin?-u?root?-p?variables?|?grep?datadir
Enter?password:
|?datadir?|?/var/lib/mysql/
2:關(guān)閉MySQL服務(wù)
在更改MySQL的數(shù)據(jù)目錄前,必須關(guān)閉MySQL服務(wù)。
方式1:
[root@DB-Server?~]#?service?mysql?status
MySQL?running?(9411)[?OK?]
[root@DB-Server?~]#?service?mysql?stop
Shutting?down?MySQL..[?OK?]
[root@DB-Server?~]#
方式2:
[root@DB-Server?~]#?/etc/rc.d/init.d/mysql?status
MySQL?running?(8900)[?OK?]
[root@DB-Server?~]#?/etc/rc.d/init.d/mysql?stop
Shutting?down?MySQL..[?OK?]
[root@DB-Server?~]#
3:創(chuàng)建新的數(shù)據(jù)庫(kù)存儲(chǔ)目錄
[root@DB-Server ~]# cd /u01
[root@DB-Server u01]# mkdir mysqldata
4:移動(dòng)MySQL數(shù)據(jù)目錄到新位置
[root@DB-Server ~]# mv /var/lib/mysql /u01/mysqldata/
5:修改配置文件my.cnf
并不是所有版本都包含有my.cnf這個(gè)配置文件,在MySQL 5.5版本,我就找不到my.cnf這個(gè)配置文件, 而有些MySQL版本該文件位于/usr/my.cnf,如果/etc/目錄下沒(méi)有my.cnf配置文件,請(qǐng)到/usr/share/mysql/下找到*.cnf文件,拷貝其中一個(gè)到/etc/并改名為my.cnf中。命令如下:
[root@DB-Server mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
編輯/etc/my.cnf文件,修改參數(shù)socket
MySQL 5.5 版本
#?The?following?options?will?be?passed?to?all?MySQL?clients
[client]
#password???????=?your_password
port????????????=?3306
socket??????????=?/u01/mysqldata/mysql/mysql.sock
#?Here?follows?entries?for?some?specific?programs
#?The?MySQL?server
[mysqld]
port????????????=?3306
socket??????????=?/u01/mysqldata/mysql/mysql.sock
skip-external-locking
key_buffer_size?=?16M
max_allowed_packet?=?1M
table_open_cache?=?64
sort_buffer_size?=?512K
net_buffer_length?=?8K
read_buffer_size?=?256K
read_rnd_buffer_size?=?512K
myisam_sort_buffer_size?=?8M
6:修改啟動(dòng)腳本/etc/init.d/mysql
將參數(shù)datadir修改為datadir=/u01/mysqldata/mysql/
7:啟動(dòng)MySQL服務(wù)并驗(yàn)證MySQL數(shù)據(jù)庫(kù)路徑
[root@DB-Server?~]#?service?mysql?start
Starting?MySQL..[??OK??]
[root@DB-Server?~]#?mysqladmin?-u?root?-p?variables?|?grep?datadir
Enter?password:
|?datadir????????|?/u01/mysqldata/mysql/
總結(jié)
以上是生活随笔為你收集整理的mysql更改数据库数据存储目录_MySQL更改数据库数据存储目录的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 勒巴沟岩画是谁画的啊?
- 下一篇: python 查找文件内容性能 grep