Vincent Teyssier
Vincent Teyssier

Reputation: 2217

Ubuntu: changing mysql datadir issue

I need to change my datadir and I have succeeded to do so on the main HDD. I tried the same manipulation on another mounted HDD and restarting the mysql fails, I don't understand why. Here is the manipulation I made:

  1. editing the my.cnf :

    datadir         = /var/lib/mysql   ->  datadir = /media/user/BCB3A.../mysql
    
  2. copying mysql data to the new folder:

    sudo -s  
    /etc/init.d/mysql stop  
    cp -pr /var/lib/mysql/* /media/user/BCB3A.../mysql  
    
  3. editing apparmor:

    /var/lib/mysql/ r,                -> /media/user/BCB3A.../mysql/ r,  
    /var/lib/mysql/** rwk,       ->  /media/user/BCB3A/mysql/** rwk,  
    
  4. restarting the services :

    sudo /etc/init.d/apparmor restart  
    sudo /etc/init.d/mysql start  
    

Apparmor restarts properly, but mysql fails.

Looks like I have an issue in the mounting parameters of HDD2 but I don't know what, any idea?

Upvotes: 2

Views: 1362

Answers (1)

Vincent Teyssier
Vincent Teyssier

Reputation: 2217

The answer is pretty simple actually....

The mysql folder needs to be owned by mysql:mysql. sudo chown mysql:mysql /your_new_mysql_dir/

In my case this command was not changing the ownership for the simple reason that the file system of the secondary hard disk drive was NTFS, and permissions/ownership is not applyable on NTFS, so a format into FAT32 fixed the issue. Thanks to @hek2mgl for the big help!

Upvotes: 2

Related Questions