How To Change MySQL Default Data,Binlog,Error Log Directories
MySQL Change default directories
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
MySQL: 5.5.58
Destination Directories: #
Data: /mysql/data
**Binlog: **/mysql/data
ErrorLog: /mysql/error
SlowLog: /mysql/sowlog
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
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
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,
service mysql start