"chown mysql:mysql /data/tmp" command

5,491

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.

Share:
5,491

Related videos on Youtube

Mellon
Author by

Mellon

Software Engineer

Updated on September 18, 2022

Comments

  • Mellon
    Mellon over 1 year

    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?

  • Mellon
    Mellon over 12 years
    What is the full path to /data/tmp ?? I just do not know where can I find it... and where is my.cnf??
  • Mellon
    Mellon over 12 years
    You talked about two ways to change, are they both need to be done or either one is ok?
  • loislo
    loislo over 12 years
    @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
  • Mellon
    Mellon over 12 years
    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
    Mellon over 12 years
    @ 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/ ?
  • loislo
    loislo over 12 years
    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.
  • Mellon
    Mellon over 12 years
    @ 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.
  • loislo
    loislo over 12 years
    @Mellon Without any other context, it means mkdir -p /data/tmp && cp cars.dat /data/tmp
  • Mellon
    Mellon over 12 years
    But it mentioned "/data/tmp on database server", it must be something more than just create the directory, because it said "on database server"
  • loislo
    loislo over 12 years
    @Mellon You don't understand the bounds of the problem you're given, and I don't have the context to help you out. I would assume that you would have shell access to the db server, but that may not be the case. You need to ask your prof or a classmate.
  • Flash
    Flash over 12 years
    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.