While reading this heading everybody things like, yeah its pretty old topic, we can get many articles by googling. But you know what sometimes well known things never work for us. This time it happened for me, my bad. I have done this many times. But most of us changed the default Data Directory only. Only a few of us thinking about change MySQL default data,binlog, error log directories.
I can easily change the Data directory, But while enabling binlog, and error log I got an error.
mysqld: File '/mysql/binlog/mysql-bin.index' not found (Errcode: 13)
So this is the reason for wrote this blog.
My Server Setup:
OS: Ubuntu 14.04LTS 64Bit
Create the Directories:
mkdir -p /mysql/data mkdir -p /mysql/binlog mkdir -p /mysql/error mkdir -p /mysql/sowlog
chown -R mysql:mysql /mysql/ chmod -R 600 /mysql
Sync the data from old data directory to the new directory.
service mysql stop sudo rsync -av /var/lib/mysql/* /mysql/data/
Edit the my.cnf file
[mysqld] #Data datadir = /mysql/data/ #Binlog log_bin = /mysql/binlog/mysql_bin #Errorlog log_error = /mysql/error/mysql_error.log #slowlog slow_query_log_file = /mysql/sowlog/mysql_slow.log [mysql] port = 3306 socket = /mysql/data/mysql.sock
Now its time to modify the apparmor files.
vi /etc/apparmor.d/usr.sbin.mysqld #fine the below lines /var/lib/mysql r, /var/lib/mysql/** rwk, #replace with /mysql r, /mysql/** rwk,
Thats it, now start mysql.
service mysql start