我在虚拟机上安装了 Ubuntu 10.10。使用 apache/php/mysql ...现在我试图将 mysql datadir 移动到主机操作系统 (win7) 共享的文件夹
所以我做了以下工作:1)挂载共享文件夹:sudo mount -t vboxsf -o uid=103,gid=110 mysql_h /mnt/db
mysql 的 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
答案1
最后,它是另一个具有 datadir 位置的 conf. 文件。修复后,一切正常。
/etc/apparmor.d/usr.sbin.mysqld
答案2
这个错误再清楚不过了。这是一个权限问题。您可以以自己的用户身份读取/写入文件夹,但用户 mysql 呢?Mysqld 使用用户 mysql 的权限运行,因此您需要确保用户“mysql”可以读取和写入您的数据目录。
您的日志片段
InnoDB:错误意味着 mysqld 没有对
InnoDB:目录的访问权限。InnoDB
:文件名 ./ibdata1
InnoDB:文件操作调用:'open'。InnoDB
:无法继续操作。
答案3
大卫:
首先,感谢您运行上述所有测试。我很高兴 touch/rm as mysql 可以在没有 sudo 的情况下工作,因为这就是我们正在测试的。我同意其他人的观点,即所有迹象都指向权限问题,但我几乎看不到任何迹象。
作为通过的测试,我还可以从中获得输出吗
ls -la /mnt/db/mysql
?
您提供的数据中唯一奇怪的是来自的输出sum /mnt/db/ibdata1
,它曾经位于上方,但似乎已经消失了,如果我没记错的话,它是这样的
00000 320
这很奇怪,因为通常只有全是零的文件才会产生这样的输出。这种情况可能会随机发生,但概率只有十万分之一。我的直觉是,即使是新创建的 mysql 数据文件也不应该完全为空。
是否有可能你被允许列出目录、打开文件等,但当请求文件内容时,后端服务器只给你零?你能否通过制作一个已知内容的小文本文件来测试这个假设在 Windows 服务器端,然后尝试
cat /mnt/db/SmallTextFile
在 Linux 端,以用户 mysql 的身份?在 Linux 端创建和读取文件(在两种情况下都以用户 mysql 的身份)的类似测试也会很有帮助。我想不出任何其他方法来确认文件系统将返回放入其中的数据。
如果这不是我的想法,抱歉。不过,我很高兴你在我们进行所有这些测试时感觉自己学到了新东西!