自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL更改數(shù)據(jù)庫數(shù)據(jù)存儲目錄

數(shù)據(jù)庫 MySQL
MySQL數(shù)據(jù)庫默認(rèn)的數(shù)據(jù)庫文件位于/var/lib/mysql下,有時候由于存儲規(guī)劃等原因,需要更改MySQL數(shù)據(jù)庫的數(shù)據(jù)存儲目錄。下文總結(jié)整理了實(shí)踐過程的操作步驟。

MySQL數(shù)據(jù)庫默認(rèn)的數(shù)據(jù)庫文件位于/var/lib/mysql下,有時候由于存儲規(guī)劃等原因,需要更改MySQL數(shù)據(jù)庫的數(shù)據(jù)存儲目錄。下文總結(jié)整理了實(shí)踐過程的操作步驟。

1:確認(rèn)MySQL數(shù)據(jù)庫存儲目錄 

  1. [root@DB-Server tmp]# mysqladmin -u root -p variables | grep datadir  
  2. Enter password:   
  3. | datadir | /var/lib/mysql/ 

2:關(guān)閉MySQL服務(wù)

在更改MySQL的數(shù)據(jù)目錄前,必須關(guān)閉MySQL服務(wù)。

方式1: 

  1. [root@DB-Server ~]# service mysql status  
  2. MySQL running (9411)[ OK ]  
  3. [root@DB-Server ~]# service mysql stop  
  4. Shutting down MySQL..[ OK ]  
  5. [root@DB-Server ~]#  

方式2: 

  1. [root@DB-Server ~]# /etc/rc.d/init.d/mysql status  
  2. MySQL running (8900)[ OK ]  
  3. [root@DB-Server ~]# /etc/rc.d/init.d/mysql stop  
  4. Shutting down MySQL..[ OK ]  
  5. [root@DB-Server ~]#  

3:創(chuàng)建新的數(shù)據(jù)庫存儲目錄 

  1. [root@DB-Server ~]# cd /u01  
  2. [root@DB-Server u01]# mkdir mysqldata 

4:移動MySQL數(shù)據(jù)目錄到新位置 

  1. [root@DB-Server ~]# mv /var/lib/mysql /u01/mysqldata/ 

5:修改配置文件my.cnf

并不是所有版本都包含有my.cnf這個配置文件,在MySQL 5.5版本,我就找不到my.cnf這個配置文件, 而有些MySQL版本該文件位于/usr/my.cnf,如果/etc/目錄下沒有my.cnf配置文件,請到/usr/share/mysql/下找到*.cnf文件,拷貝其中一個到/etc/并改名為my.cnf中。命令如下:

 

  1. [root@DB-Server mysql]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf 

編輯/etc/my.cnf文件,修改參數(shù)socket

MySQL 5.5 版本 

  1. # The following options will be passed to all MySQL clients  
  2. [client]  
  3. #password       = your_password  
  4. port            = 3306  
  5. socket          = /u01/mysqldata/mysql/mysql.sock  
  6. # Here follows entries for some specific programs  
  7. # The MySQL server  
  8. [mysqld]  
  9. port            = 3306  
  10. socket          = /u01/mysqldata/mysql/mysql.sock  
  11. skip-external-locking  
  12. key_buffer_size = 16M  
  13. max_allowed_packet = 1M  
  14. table_open_cache = 64  
  15. sort_buffer_size = 512K  
  16. net_buffer_length = 8K  
  17. read_buffer_size = 256K  
  18. read_rnd_buffer_size = 512K  
  19. myisam_sort_buffer_size = 8M 

6:修改啟動腳本/etc/init.d/mysql

將參數(shù)datadir修改為datadir=/u01/mysqldata/mysql/

7:啟動MySQL服務(wù)并驗(yàn)證MySQL數(shù)據(jù)庫路徑 

  1. [root@DB-Server ~]# service mysql start  
  2. Starting MySQL..[  OK  ]  
  3. [root@DB-Server ~]# mysqladmin -u root -p variables | grep datadir  
  4. Enter password:   
  5. | datadir        | /u01/mysqldata/mysql/ 

我的疑問:

1: 在修改數(shù)據(jù)庫的存儲目錄前,/var/lib/mysql/目錄下根本沒有mysql.sock文件,安裝上面配置后,就會生成mysql.sock文件。

關(guān)于mysql.sock文件,搜索了一下資料:mysql.sock是用于socket連接的文件。也就是只有你的守護(hù)進(jìn)程啟動起來這個文件才存在。但是你的mysql程序(這個程序是客戶端,服務(wù)器端是mysqld)可以選擇是否使用mysql.sock文件來連接(因?yàn)檫@個方法只適合在Unix主機(jī)上面連接本地的mysqld),對于非本地的任何類型的主機(jī)。那么這個文件是否一定需要的呢? 這個需要進(jìn)一步了解清楚。

2:我在網(wǎng)上看有些網(wǎng)友總結(jié)的修改MySQL數(shù)據(jù)路徑,有些需要給新建的目錄的權(quán)限做一些處理,而有些有不用對目錄權(quán)限進(jìn)行授權(quán),我沒有處理,也沒有什么問題。到底要不要對新的數(shù)據(jù)庫目錄授權(quán)呢?

3:我在MySQL_5.6.20這個版本測試時,不修改my.cnf,只修改啟動腳本/etc/init.d/mysql,也完全沒有啥問題。也沒有myssql.sock文件生成。

4:注意如果沒有禁用selinux, 修改MySQL的數(shù)據(jù)路徑后啟動MySQL服務(wù)會遇到一些錯誤。關(guān)于這個的解釋是后臺服務(wù)都需要有對相應(yīng)目錄的對應(yīng)權(quán)限,而 mysql 的默認(rèn)路徑/var/lib/mysql 已經(jīng)添加了相應(yīng)的策略,修改路徑后由于沒有相應(yīng)的策略,導(dǎo)致后臺進(jìn)程讀取文件被selinux阻止,從而出現(xiàn)權(quán)限錯誤。 所以要么關(guān)閉Selinux或修改文件安全上下文。 

  1. [root@DB-Server mysql]# /etc/init.d/mysql start  
  2. Starting MySQL....The server quit without updating PID file (/u01/mysqldata/mysql//DB-Server.localdomain.pid).[FAILED]  
  3. [root@DB-Server mysql]#   
  4. [root@DB-Server mysql]# chcon -R -t mysqld_db_t /u01/mysqldata/mysql/  
  5. [root@DB-Server mysql]# /etc/init.d/mysql start  
  6. Starting MySQL.[ OK ]  
  7. [root@DB-Server mysql]#    
責(zé)任編輯:龐桂玉 來源: 數(shù)據(jù)庫開發(fā)
相關(guān)推薦

2011-03-24 16:54:07

數(shù)據(jù)庫名稱

2010-07-05 17:41:37

SQL Server

2018-05-02 08:48:58

Raid存儲MySQL

2011-05-26 12:54:31

數(shù)據(jù)庫數(shù)據(jù)庫名

2009-09-18 15:19:19

LINQ to SQL

2019-06-20 15:25:14

MySQLL數(shù)據(jù)庫存儲

2010-05-04 11:58:38

Oracle數(shù)據(jù)庫

2010-10-14 13:18:55

MySQL存儲過程

2019-08-27 15:00:09

MySQL數(shù)據(jù)庫存儲

2009-04-29 16:10:14

2011-08-29 16:27:16

MySQL時間類型

2010-10-21 14:12:07

SQL Server游

2009-05-27 11:01:29

UbuntuMySQL存儲

2011-08-01 23:08:33

MySQL存儲引擎

2018-07-13 09:20:30

SQLite數(shù)據(jù)庫存儲

2011-05-13 09:42:21

2011-03-03 17:56:52

MySQL數(shù)據(jù)庫優(yōu)化

2010-10-26 15:30:12

連接Oracle數(shù)據(jù)庫

2018-11-05 15:14:42

MySQL編程語言技術(shù)

2019-06-10 14:31:24

MySQL存儲數(shù)據(jù)庫
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號