我正在尝试在默认硬盘以外的其他硬盘上创建 MySQL 表。当 MySQL 尝试创建文件时,我收到权限错误。我想我可以将其归结为以下几行 shell 命令,它们会在 shell 中重现错误:
scott@landscapesrv01:/mnt/datadrive/globot/mysql$ ls -lha
total 8.0K
drwxr-xr-x 2 mysql mysql 4.0K 2011-06-06 14:47 .
drwxrwsr-x 3 scott www-data 4.0K 2011-06-06 14:22 ..
-rw-rw-rw- 1 mysql mysql 0 2011-06-06 14:47 globot_tick_spies.MYD
scott@landscapesrv01:/mnt/datadrive/globot/mysql$ sudo sudo -u mysql echo hi > /mnt/datadrive/globot/mysql/globot_tick_spies.MYD
scott@landscapesrv01:/mnt/datadrive/globot/mysql$ sudo chmod 664 globot_tick_spies.MYD
scott@landscapesrv01:/mnt/datadrive/globot/mysql$ ls -lha
total 12K
drwxr-xr-x 2 mysql mysql 4.0K 2011-06-06 14:47 .
drwxrwsr-x 3 scott www-data 4.0K 2011-06-06 14:22 ..
-rw-rw-r-- 1 mysql mysql 3 2011-06-06 14:48 globot_tick_spies.MYD
scott@landscapesrv01:/mnt/datadrive/globot/mysql$ sudo sudo -u mysql echo hi > /mnt/datadrive/globot/mysql/globot_tick_spies.MYD
bash: /mnt/datadrive/globot/mysql/globot_tick_spies.MYD: Permission denied
scott@landscapesrv01:/mnt/datadrive/globot/mysql$
为什么用户不能编辑用户拥有所有权和用户级别权限的mysql
文件?mysql
更新
好吧,上面的命令是有缺陷的......我可以以用户身份编辑文件mysql
scott@landscapesrv01:/mnt/datadrive/globot/mysql$ sudo sudo -u mysql bash
mysql@landscapesrv01:/mnt/datadrive/globot/mysql$ ls -alh
total 8.0K
drwxrwxr-x 2 mysql mysql 4.0K 2011-06-06 15:18 .
drwxrwsr-x 3 scott www-data 4.0K 2011-06-06 14:22 ..
mysql@landscapesrv01:/mnt/datadrive/globot/mysql$ touch test
mysql@landscapesrv01:/mnt/datadrive/globot/mysql$ ls -alh
total 8.0K
drwxrwxr-x 2 mysql mysql 4.0K 2011-06-06 15:50 .
drwxrwsr-x 3 scott www-data 4.0K 2011-06-06 14:22 ..
-rw-r--r-- 1 mysql mysql 0 2011-06-06 15:50 test
mysql@landscapesrv01:/mnt/datadrive/globot/mysql$ echo hi > test
mysql@landscapesrv01:/mnt/datadrive/globot/mysql$ echo hi > test2
mysql@landscapesrv01:/mnt/datadrive/globot/mysql$ ls -alh
total 16K
drwxrwxr-x 2 mysql mysql 4.0K 2011-06-06 15:51 .
drwxrwsr-x 3 scott www-data 4.0K 2011-06-06 14:22 ..
-rw-r--r-- 1 mysql mysql 3 2011-06-06 15:50 test
-rw-r--r-- 1 mysql mysql 3 2011-06-06 15:51 test2
这样就可以正常工作...但是为什么我不能按照我喜欢的方式创建表格?
mysql> CREATE TABLE `globot_tick_spies` ( `test` datetime NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DATA DIRECTORY = '/mnt/datadrive/globot/mysql';
ERROR 1 (HY000): Can't create/write to file '/mnt/datadrive/globot/mysql/globot_tick_spies.MYD' (Errcode: 13)
(抱歉造成上述混淆。)
答案1
Bash 认为您正在尝试将 的输出重定向"sudo sudo -u mysql echo h"
到而不是通过/mnt/datadrive/globot/mysql/globot_tick_spies.MYD
发送全文。"mysql echo hi > /mnt/datadrive/globot/mysql/globot_tick_spies.MYD"
sudo
因此,重定向发生在 之外sudo
,因此作为您,scott
而不是mysql
。
尝试使用如下引号:
sudo sudo -u mysql "echo hi > /mnt/datadrive/globot/mysql/globot_tick_spies.MYD"
答案2
我曾经遇到过类似的问题,最终通过 chowning mysql 文件夹本身得到解决,即
chown mysql /mnt/datadrive/globot/mysql
我猜你不能以 mysql-user 身份创建文件夹?