——廢話先不羅嗦了,就讓這篇草草完成的部落格文章全且當做個記錄吧。
以前我使用的是centos上的mysql,後來因為測試需要,需要将網站以及在資料庫存儲的資料遷移到新的系統中進行測試,目标系統為redhat enterprise linux server(rhel)。
由于以前從來沒有遷移過資料庫,是以馬上就遇到了難題。
還有其他問題沒有列出,僅僅就權限的問題在下面的指令以及執行結果中展示。
注:部分顯示被屏蔽。
sun 25 mar 2012 05:07:30 pm cst
在遷移mysql時出現的錯誤/usr/bin/mysqlshow: cannot list tables in ********: can't read dir of './********/' (errno: 13)
google關鍵詞:mysql errno: 13
解決方案:mysql資料庫的子資料庫必須是mysql使用者和mysql組所有,否則mysql無法讀取遷移過來的資料庫。
[root@localhost mysql]# ls -al
total
drwxr-xr-x. 7 root root 4096 mar 24 02:44 .
drwxr-xr-x. 48 root root 4096 mar 24 02:45 ..
-rw-r-----. 1 root root 27262976 mar 24 02:44 ibdata1
-rw-r-----. 1 root root 5242880 mar 24 02:44 ib_logfile0
-rw-r-----. 1 root root 5242880 mar 24 02:44 ib_logfile1
drwx------. 2 root root 4096 mar 24 02:44 ********
drwx------. 2 root root 4096 mar 24 02:44 mysql
drwx------. 2 root root 4096 mar 24 02:44 performance_schema
[root@localhost mysql]# ls /var/lib/mysql/ -al
drwxr-xr-x. 5 mysql mysql 4096 mar 25 16:33 .
drwxr-xr-x. 54 root root 4096 mar 24 04:27 ..
-rw-rw----. 1 mysql mysql 10485760 mar 25 16:23 ibdata1
-rw-rw----. 1 mysql mysql 5242880 mar 25 16:23 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 mar 25 16:23 ib_logfile1
drwx------. 2 root root 4096 mar 25 16:33 ********
drwx------. 2 mysql mysql 4096 mar 25 16:23 mysql
srwxrwxrwx. 1 mysql mysql 0 mar 25 16:23 mysql.sock
[root@localhost mysql]# chown -r mysql:mysql ./********/
[root@localhost mysql]# chown -r mysql:mysql ./********/
[root@localhost mysql]# service mysqld restart
stopping mysqld: [ ok ]
starting mysqld: [ ok ]
drwxr-xr-x. 7 root root 4096 mar 24 02:44 .
drwxr-xr-x. 48 root root 4096 mar 24 02:45 ..
-rw-r-----. 1 root root 27262976 mar 24 02:44 ibdata1
-rw-r-----. 1 root root 5242880 mar 24 02:44 ib_logfile0
-rw-r-----. 1 root root 5242880 mar 24 02:44 ib_logfile1
drwx------. 2 mysql mysql 4096 mar 24 02:44 ********
drwx------. 2 root root 4096 mar 24 02:44 mysql
drwx------. 2 root root 4096 mar 24 02:44 performance_schema
drwx------. 2 root root 4096 mar 24 02:44 ********
[root@localhost mysql]# cd /var/lib/mysql/
total
drwxr-xr-x. 5 mysql mysql 4096 mar 25 17:12 .
-rw-rw----. 1 mysql mysql 10485760 mar 25 17:11 ibdata1
-rw-rw----. 1 mysql mysql 5242880 mar 25 17:12 ib_logfile0
srwxrwxrwx. 1 mysql mysql 0 mar 25 17:12 mysql.sock
drwx------. 2 mysql mysql 4096 mar 25 16:33 ********
[root@localhost mysql]#
其實說的白了,就是需要注意權限指派。因為mysql的資料庫必須由mysql建立和擁有。因為一般來說,遷移過來的都是隻具有root的權限——664。是以隻有使用chown指令了。
附錄:
chown的用法:
chown -r 使用者名:使用者組 目标檔案或目錄
其中r表示遞歸執行。