Friday, January 14, 2011

Starting MySQL failed while changing datadir from /var/lib/mysql to /root/metro1/mysql

I created a volume on my IBM Storwize V7000, and presented to my host running Red Hat Enterprise Linux Server release 5.5 (Tikanga)

I then mounted an ext3 file system on a 10 GB partition of the volume.
/dev/mapper/mpath32p              19.9G  171M  9.2G   2% /root/metro1

I had initially installed MySql on the Linux host, and the datadir for my installation was /var/lib/mysql
I now thought that it would be a good idea to move my datadir from /var/lib/mysql to /root/metro1

It seemed a rather straight forward thing to do, so I edited /etc/my.cnf file and changed
[mysqld]
#datadir=/var/lib/mysql
datadir=/root/metro1/mysql

changed the ownership of /root/metro1/mysql to mysql
[root@isvx3 lib]# chown mysql:mysql /root/metro1/mysql
[root@isvx3 lib]# chmod 755 /root/metro1/mysql
When I tried to start mysqd as follows, I got the message that it FAILED
[root@isvx3 lib]# /etc/init.d/mysqld start
Timeout error occurred trying to start MySQL Daemon.
Starting MySQL:                                            [FAILED]


In the log file under /var/lib/mysql/mysqld.log I noticed the following message:
InnoDB: Foreign key constraint system tables created
110114 11:23:25  InnoDB: Started; log sequence number 0 0
110114 11:23:25 [ERROR] bdb:  /root/metro1/mysql: Permission denied
110114 11:23:25 [ERROR] bdb:  /root/metro1/mysql/log.0000000001: Permission denied
110114 11:23:25 [ERROR] bdb:  PANIC: Permission denied
110114 11:23:25 [ERROR] bdb:  PANIC: DB_RUNRECOVERY: Fatal error, run database recovery
110114 11:23:25 [ERROR] bdb:  fatal region error detected; run recovery
110114 11:23:25 [ERROR] bdb:  /root/metro1/mysql: Permission denied
110114 11:23:25 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
110114 11:23:25  mysqld ended

I then changed datadir from /var/lib/mysql to /var/lib/test , and made the ownership and permission changes
to /var/lib/test. I then started the mysqld again, this time mysqld started fine.

Everything seemed the same between the /root/metro1/mysql where mysqld failed, and /var/lib/mysql where mysqld started.

On digging further I noticed the following difference in the permission:
[root@isvx3 lib]# ls -l /
drwxr-xr-x  24 root   root  4096 Sep  1 11:16 var
drwxr-x---  31 root   root  4096 Jan 12 17:37 root

Created a new mount point /home/mysql and mounted the file system on it, intead of /root/metro1
Then I updated the /etc/my.cnf file with the new datadir ie. /home/mysql/mysql

/dev/mapper/mpath32p1          9.9G  171M  9.2G   2% /home/mysql

[root@isvx3 ~]# mkdir -p /home/mysql/mysql
[root@isvx3 ~]# chown mysql:mysql /home/mysql/mysql
[root@isvx3 ~]# chmod 755 /home/mysql/mysql
[root@isvx3 ~]#


After when I started mysqld with the below mentioned command, MySQL started fine.
[root@isvx3 ~]# /etc/init.d/mysqld start
Starting MySQL:                                            [  OK  ]

Also, under /home/mysql/mysql I could see the newly created files

[root@isvx3 mysql]# pwd

/home/mysql/mysql

[root@isvx3 mysql]# ls

ibdata1  ib_logfile0  ib_logfile1  mysql  test

[root@isvx3 mysql]# ls -lh

total 21M

-rw-rw---- 1 mysql mysql  10M Jan 14 14:19 ibdata1

-rw-rw---- 1 mysql mysql 5.0M Jan 14 14:19 ib_logfile0

-rw-rw---- 1 mysql mysql 5.0M Jan 14 14:19 ib_logfile1

drwx------ 2 mysql mysql 4.0K Jan 14 14:19 mysql

drwx------ 2 mysql mysql 4.0K Jan 14 14:19 test

[root@isvx3 mysql]#



Moral of the story is that the error stemmed from the permission of the /root director. I didn't to change the permissions of the /root but instead created the datadir under /home/mysql/mysql to fix the issue.

No comments: