Ubuntu

virtualbox上的mysql,共享文件夾上的datadir

  • August 4, 2013

我已經在 virtualbox 機器上安裝了 Ubuntu 10.10。使用 apache/php/mysql …現在我正在嘗試將 mysql datadir 移動到主機 os (win7) 共享的文件夾

所以我做了以下工作:1)掛載的共享文件夾:sudo mount -t vboxsf -o uid=103,gid=110 mysql_h /mnt/dbmysql的uid,gid;2)改變/etc/mysql/my.cnf所以datadir看起來像datadir = /mnt/db:3)重新啟動服務。

嘗試連接 mysql 時,出現以下錯誤:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

附言

user            = mysql
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /mnt/db
tmpdir          = /tmp

更新

我已將共享模式從 virtualbox 更改為 samba,並使用:mount -t smbfs -o username=David,password=,uid=103,gid=110,rw //DAVID-PC/mysql /mnt/db. 它可以安裝,以 mysql 使用者/組作為所有者。但是我仍然無法啟動mysql。錯誤日誌:

110121 13:24:38 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
110121 13:24:38 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
110121 13:24:38  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.

更新2

grep mysql /etc/passwd
mysql:x:103:110:MySQL Server,,,:/nonexistent:/bin/false

ls -al /mnt/db/ib*
-rwxr-xr-x 1 mysql mysql 10485760 2011-01-21 13:45 /mnt/db/ibdata1
-rwxr-xr-x 1 mysql mysql  5242880 2011-01-21 13:45 /mnt/db/ib_logfile0
-rwxr-xr-x 1 mysql mysql  5242880 2011-01-21 13:45 /mnt/db/ib_logfile1

更新3a

drwxr-xr-x 1 mysql mysql    4096 2011-01-21 23:08 .
drwxr-xr-x 4 root  root     4096 2011-01-20 23:19 ..
-rwxr-xr-x 1 mysql mysql        4 2011-01-21 20:46 apache-server.pid
-rwxr-xr-x 1 mysql mysql        0 2011-01-21 16:21 debian-5.1.flag
-rwxr-xr-x 1 mysql mysql 10485760 2011-01-21 16:42 ibdata1
-rwxr-xr-x 1 mysql mysql  5242880 2011-01-21 23:12 ib_logfile0
-rwxr-xr-x 1 mysql mysql  5242880 2011-01-21 23:13 ib_logfile1
drwxr-xr-x 1 mysql mysql    20480 2011-01-21 16:21 mysql
-rwxr-xr-x 1 mysql mysql        6 2011-01-11 20:32 mysql_upgrade_info

更新4

mysql@apache-server:/$ ls -la /mnt/db/mysql
total 970
drwxr-xr-x 1 mysql mysql  20480 2011-01-24 07:54 .
drwxr-xr-x 1 mysql mysql   4096 2011-01-24 07:54 ..
-rwxr-xr-x 0 mysql mysql   8820 2011-01-24 07:54 columns_priv.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 columns_priv.MYD
-rwxr-xr-x 0 mysql mysql   4096 2011-01-24 07:54 columns_priv.MYI
-rwxr-xr-x 0 mysql mysql   9582 2011-01-24 07:54 db.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 db.MYD
-rwxr-xr-x 0 mysql mysql   2048 2011-01-24 07:54 db.MYI
-rwxr-xr-x 0 mysql mysql  10223 2011-01-24 07:54 event.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 event.MYD
-rwxr-xr-x 0 mysql mysql   2048 2011-01-24 07:54 event.MYI
-rwxr-xr-x 0 mysql mysql   8665 2011-01-24 07:54 func.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 func.MYD
-rwxr-xr-x 0 mysql mysql   1024 2011-01-24 07:54 func.MYI
-rwxr-xr-x 0 mysql mysql     35 2011-01-24 07:54 general_log.CSM
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 general_log.CSV
-rwxr-xr-x 0 mysql mysql   8776 2011-01-24 07:54 general_log.frm
-rwxr-xr-x 0 mysql mysql   8700 2011-01-24 07:54 help_category.frm
-rwxr-xr-x 0 mysql mysql  22078 2011-01-24 07:54 help_category.MYD
-rwxr-xr-x 0 mysql mysql   3072 2011-01-24 07:54 help_category.MYI
-rwxr-xr-x 0 mysql mysql   8612 2011-01-24 07:54 help_keyword.frm
-rwxr-xr-x 0 mysql mysql  89044 2011-01-24 07:54 help_keyword.MYD
-rwxr-xr-x 0 mysql mysql  16384 2011-01-24 07:54 help_keyword.MYI
-rwxr-xr-x 0 mysql mysql   8630 2011-01-24 07:54 help_relation.frm
-rwxr-xr-x 0 mysql mysql   8937 2011-01-24 07:54 help_relation.MYD
-rwxr-xr-x 0 mysql mysql  17408 2011-01-24 07:54 help_relation.MYI
-rwxr-xr-x 0 mysql mysql   8770 2011-01-24 07:54 help_topic.frm
-rwxr-xr-x 0 mysql mysql 425616 2011-01-24 07:54 help_topic.MYD
-rwxr-xr-x 0 mysql mysql  20480 2011-01-24 07:54 help_topic.MYI
-rwxr-xr-x 0 mysql mysql   9510 2011-01-24 07:54 host.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 host.MYD
-rwxr-xr-x 0 mysql mysql   2048 2011-01-24 07:54 host.MYI
-rwxr-xr-x 0 mysql mysql   8778 2011-01-24 07:54 ndb_binlog_index.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 ndb_binlog_index.MYD
-rwxr-xr-x 0 mysql mysql   1024 2011-01-24 07:54 ndb_binlog_index.MYI
-rwxr-xr-x 0 mysql mysql   8586 2011-01-24 07:54 plugin.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 plugin.MYD
-rwxr-xr-x 0 mysql mysql   1024 2011-01-24 07:54 plugin.MYI
-rwxr-xr-x 0 mysql mysql   9996 2011-01-24 07:54 proc.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 proc.MYD
-rwxr-xr-x 0 mysql mysql   2048 2011-01-24 07:54 proc.MYI
-rwxr-xr-x 0 mysql mysql   8875 2011-01-24 07:54 procs_priv.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 procs_priv.MYD
-rwxr-xr-x 0 mysql mysql   4096 2011-01-24 07:54 procs_priv.MYI
-rwxr-xr-x 0 mysql mysql   8838 2011-01-24 07:54 servers.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 servers.MYD
-rwxr-xr-x 0 mysql mysql   1024 2011-01-24 07:54 servers.MYI
-rwxr-xr-x 0 mysql mysql     35 2011-01-24 07:54 slow_log.CSM
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 slow_log.CSV
-rwxr-xr-x 0 mysql mysql   8976 2011-01-24 07:54 slow_log.frm
-rwxr-xr-x 0 mysql mysql   8955 2011-01-24 07:54 tables_priv.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 tables_priv.MYD
-rwxr-xr-x 0 mysql mysql   4096 2011-01-24 07:54 tables_priv.MYI
-rwxr-xr-x 0 mysql mysql   8636 2011-01-24 07:54 time_zone.frm
-rwxr-xr-x 0 mysql mysql   8624 2011-01-24 07:54 time_zone_leap_second.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 time_zone_leap_second.MYD
-rwxr-xr-x 0 mysql mysql   1024 2011-01-24 07:54 time_zone_leap_second.MYI
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 time_zone.MYD
-rwxr-xr-x 0 mysql mysql   1024 2011-01-24 07:54 time_zone.MYI
-rwxr-xr-x 0 mysql mysql   8606 2011-01-24 07:54 time_zone_name.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 time_zone_name.MYD
-rwxr-xr-x 0 mysql mysql   1024 2011-01-24 07:54 time_zone_name.MYI
-rwxr-xr-x 0 mysql mysql   8686 2011-01-24 07:54 time_zone_transition.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 time_zone_transition.MYD
-rwxr-xr-x 0 mysql mysql   1024 2011-01-24 07:54 time_zone_transition.MYI
-rwxr-xr-x 0 mysql mysql   8748 2011-01-24 07:54 time_zone_transition_type.frm
-rwxr-xr-x 0 mysql mysql      0 2011-01-24 07:54 time_zone_transition_type.MYD
-rwxr-xr-x 0 mysql mysql   1024 2011-01-24 07:54 time_zone_transition_type.MYI
-rwxr-xr-x 0 mysql mysql  10466 2011-01-24 07:54 user.frm
-rwxr-xr-x 0 mysql mysql    468 2011-01-24 07:54 user.MYD
-rwxr-xr-x 0 mysql mysql   2048 2011-01-24 07:54 user.MYI

mysql@apache-server:/$ sum /mnt/db/ibdata1
02939 10240

mysql@apache-server:/$ cat /mnt/db/small.txt
very small text file from windows

mysql@apache-server:/$ ls -la /mnt/db/small.txt
-rwxr-xr-x 1 mysql mysql 33 2011-01-24 07:59 /mnt/db/small.txt

mysql@apache-server:/$ ls -la /mnt/db/mysql > /mnt/db/small
mysql@apache-server:/$ ls -la /mnt/db
total 20517
drwxr-xr-x 1 mysql mysql     4096 2011-01-24 08:03 .
drwxr-xr-x 4 root  root      4096 2011-01-20 23:19 ..
-rwxr-xr-x 1 mysql mysql        0 2011-01-24 07:54 debian-5.1.flag
-rwxr-xr-x 1 mysql mysql 10485760 2011-01-24 07:54 ibdata1
-rwxr-xr-x 1 mysql mysql  5242880 2011-01-24 07:54 ib_logfile0
-rwxr-xr-x 1 mysql mysql  5242880 2011-01-24 07:54 ib_logfile1
drwxr-xr-x 1 mysql mysql    20480 2011-01-24 07:54 mysql
-rwxr-xr-x 1 mysql mysql        6 2011-01-24 07:54 mysql_upgrade_info
-rwxr-xr-x 1 mysql mysql     4562 2011-01-24 08:03 small

最後,這是另一個conf。帶有 datadir 位置的文件。修復後 - 一切正常。

/etc/apparmor.d/usr.sbin.mysqld

錯誤再清楚不過了。這是一個權限問題。您可以以自己的使用者身份讀取/寫入文件夾,但使用者 mysql 呢?mysqld 以使用者 mysql 的權限執行,因此您需要確保使用者“mysql”可以讀取和寫入您的數據主管。

您的日誌片段

**InnoDB:錯誤意味著 mysqld 沒有對

InnoDB:目錄的訪問權限。

InnoDB:文件名./ibdata1

InnoDB:文件操作呼叫:‘open’。

InnoDB:無法繼續操作。**

引用自:https://serverfault.com/questions/224890