I am on a Linux ubuntu machine with MySQL installed.

If there is a MySQL installation on a Ubuntu machine, I saw some people doing the following thing:

sudo chown mysql:mysql /data/tmp

I get confused, I know the meaning of the above command, which is to change the owner of /data/tmp to user 'mysql' and change the group of it to 'mysql' group.

But (my questions):

1. Why would one run the above command? If I create a table in my_db database, by default, there will be .frm, .MYD, and .MYI files (data files) be created automatically by MySQL under /var/lib/mysql/my_db/ . So, does the above command changes the default MySQL data directory to /data/tmp/ instead of /var/lib/mysql/my_db/?

Basically, I would like to know the purpose and effect of the above command. (better with examples)

2. Where does the 'mysql' owner and group come from? Does the installation of MySQL on a Linux machine automatically create the 'mysql' user and group? or People need to manually create a mysql account for the linux machine?


The Command

The User Account

On Ubuntu (which you tagged this), MySQL is usually installed by apt-get. The MySQL APT package includes script that automatically create the MySQL user when the software is installed.

  • What is the full path to /data/tmp ?? I just do not know where can I find it... and where is my.cnf?? – Mellon Nov 30 '11 at 16:31
  • @Mellon the path literally is /data/tmp. At least on my Ubuntu configuration, that's not a default path (nor does /data exist as a directory). The default Ubuntu location for my.cnf is /etc/mysql/my.cnf – Jeff Ferland Nov 30 '11 at 16:37
  • @ Jeff, so you mean I have to manually first create /data/tmp, and it can be an arbitrary path right?? Besides, in the my.cnf file, if I change the mysql directory to /data/tmp , does it means in future all the database related files .frm, .MYD and .MYI will be created under /data/tmp/ ? – Mellon Nov 30 '11 at 16:41
  • Why are you focusing on /data/tmp? If you don't know why you're doing that, stop. Unless you have a specific need you can explain for changing the default directories, don't do it. You're asking a question that is above your understanding -- you don't yet know why /data/tmp might matter to you (and I'm guessing it won't), so take a step back from trying to do the work to move there. – Jeff Ferland Nov 30 '11 at 16:42
  • @ Jeff, the reason why I am focusing on /data/tmp is because my teacher gave out an assignment which mentioned "copy cars.dat to /data/tmp on the database server" without any explanations, I do not know what is the "/data/tmp on database server" means? Appreicate if you can explain. – Mellon Nov 30 '11 at 16:50

When you install mysql from a package manager like apt-get, the mysql user will be automatically created and the permissions and ownership should be setup automatically also.

When a running process (like mysql) creates a file, the file should be owned also by the same effective user mysql.


The home directory of mysql is set in the /etc/passwd file:

mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash

if you change this to /data/tmp (or any other dir) that dir becomes the home folder for mysql.

on top of that you can change datadir= under [mysqld] in the mysql config file "my.cnf" which will be the place the actual data files are stored


obviously whatever these 2 point to, the mysql user needs access.


The reason for changing the home directory and/or data directorys would obviously be space. one 'best practice' is to keep the /var directory rather small on a *nix server however sql databases tend to grow big, easiest thing to do then is move them on another partition.

  • You talked about two ways to change, are they both need to be done or either one is ok? – Mellon Nov 30 '11 at 16:36
  • Also, if I change the passwd file, and change the mysql dir to /data/tmp , does it means in future all the database related files .frm, .MYD and .MYI will be created under /data/tmp/ ? – Mellon Nov 30 '11 at 16:38
  • the home folder change (in /etc/passwd) will make files like ibdata1, ib_logfile0 and mysql.sock go into the dir specified. the change to the datadir in my.cnf will make the databases go there, Every database will have its own subdir like before with the files that belong to that database in that folder. – Flash Dec 1 '11 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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