1

I'm trying to change the data directory of mysql. i am using 12.04 ubuntu.but i have geting error when mysql start. error is "start: Job failed to start".

I have try following things

Stop the mysql server:

stop mysql

Create the new directory:

mkdir /array2/mysql

Copy over ONLY the database folders:

cp -R /var/lib/mysql /array2/mysql
cp -R /var/lib/mysql/users /array2/mysql

Backup the my.cnf file:

cp /etc/mysql/my.cnf /root/my.cnf.backup

Edit the my.cnf file:

nano /etc/mysql/my.cnf

Change all mentions of the old datadir and socket to your new location

Mine became:

datadir=/array2/mysql
socket=/array2/mysql/mysql.sock

Update the directory permissions:

chown -R mysql:mysql /array2/mysql

Rename the old directory:

mv /var/lib/mysql /var/lib/mysql-old

Create a symlink, just in case:

ln -s /array2/mysql /var/lib/mysql 

Let AppArmor know about the new datadir:

echo "alias /var/lib/mysql/ -> /your/new/datadir/," >> /etc/apparmor.d/tunables/alias

Reload the apparmor profiles

sudo /etc/init.d/apparmor reload

Then start mysql:

start mysql
2
  • Have you tried looking at mysql error log to see why is failing to start? Commented Jan 18, 2018 at 15:20
  • @EstebanGarcia not any error found error.log file Commented Jan 18, 2018 at 15:24

1 Answer 1

3

I've been looking on your changes and it is not necesary to do symlinks, socket changes and/or remove old directory. Please follow this steps.

service mysql stop
cp -R /var/lib/mysql /array2/mysql
chown -R mysql.mysql /array2/mysql

Now take a backup /etc/my.cnf and then edit data dir variable

datadir                                 = /array2/mysql

Edit apparmor rules, usually in /etc/apparmor.d/usr.sbin.mysqld by adding the following lines inside /usr/sbin/mysqld group:

/array2/mysql/ r,
/array2/mysql/** rwk,

Reload app armor and start mysql service

service apparmor restart
service mysql start

Regards,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.