Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to create a MySQL table on a different hard drive than the default. I get a permissioning error when MySQL tries to create the file. I think I can boil it down to the following lines of shell commands, which reproduce the error in the 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$

Why can't the user mysql edit the file that user mysql has ownership and user level permissions for?

UPDATE

Okay, the commands above are flawed... I can edit files fine as user 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

So that works fine... But why can't I create my table the way I like?

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)

(Sorry for the confusion above.)

share|improve this question
1  
Please don't double-post questions. Extend one using the edit functionality and then delete the other. You also don't have to accept an answer that didn't help (in case you still experience problems). That way your question will likely get more views or attention. –  slhck Jun 6 '11 at 20:02

2 Answers 2

up vote 2 down vote accepted

Bash thinks you're trying to redirect the output of "sudo sudo -u mysql echo h" to /mnt/datadrive/globot/mysql/globot_tick_spies.MYD instead of sending the full text "mysql echo hi > /mnt/datadrive/globot/mysql/globot_tick_spies.MYD" through sudo.

The redirection is thus happening outside of the sudo and therefore as you, scott, not as mysql.

Try using quotes like this:

sudo sudo -u mysql "echo hi > /mnt/datadrive/globot/mysql/globot_tick_spies.MYD"
share|improve this answer
    
Okay thanks, I got around that problem. See my edits above... –  Scott Jun 6 '11 at 19:54

I used to have similar problems which were ultimately resolved by chowning the mysql-folder itself, i.e.

chown mysql /mnt/datadrive/globot/mysql

I'm guessing you're not able to create folders as mysql-user?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.