After I setup mysql 5.5, I changed the data dir to another folder and modify the related config in my.cnf. This is quite simple, but mysql cannot start anymore even if reinstall or not change data dir.
The error log has no useful information, so I cannot find any reason.
111207 16:28:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 111207 16:28:02 mysqld_safe mysqld from pid file /var/lib/mysql/localhost.localdomain.pid ended
But if I use the command as the start script, mysql starts normally.
/usr/bin/mysqld_safe --datadir=/data/mysql/ --pid-file=/data/mysql/localhost.localdomain.pid> /dev/null 2>&1
Much more strange, I use /usr/share/mysql/mysql.server start instead of /etc/init.d/mysql start, mysql also can start without error, while these two files are the same. So in the end I have to use cp -l /usr/share/mysql/mysql.server /etc/init.d/mysql to fix the problem.
I really want to know why and if there is a better solution!
-
There seems to be some change in the way datadir is defined in 5.0 and 5.5 versions. Simply changing it in my.cnf does not help. MySQL will still look for data in /var/lib/mysql/ I usually uninstall and reinstall mysql to "fix" this!shantanuo– shantanuo2011年12月15日 13:56:16 +00:00Commented Dec 15, 2011 at 13:56
3 Answers 3
In the first one it is looking for a DB in /var/lib/mysql
(the default) and in the second, it is looking in /data/mysql
, where you have moved to.
Based on the observation by @Gaius (+1), you have two options
OPTION 1
Create a symlink /var/lib/mysql to point to /data/mysql
ln -s /data/mysql /var/lib/mysql
OPTION 2
Change the following in my.cnf
[mysqld]
datadir = /data/mysql
CAVEAT
Make sure all of /data/mysql is owned by mysql
chown -R mysql:mysql /data/mysql
Give it a Try !!!
-
1Also if you have moved where
my.cnf
lives, then you would need to set the environment variableMYSQL_HOME
to that directory.Gaius– Gaius2011年12月09日 15:37:29 +00:00Commented Dec 9, 2011 at 15:37
The following commands should fix your problem if you have the same problem I had:
cp /etc/init.d/mysql /etc/init.d/mysqlnew
rm /etc/init.d/mysql
mv /etc/init.d/mysqlnew /etc/init.d/mysql
I just ran in to the same issue. In my case it turned out to be something wrong with the startup script file that was in the init.d path.
The /etc/init.d/mysql file was the binary equivalent of /usr/share/mysql/mysql.server The permissions, owner, and group, were the exact same
I moved the bad file, and renamed it mysqlwtf, and replaced the init.d script with a good copy.
See this snippet from my shell session to see the proof that the problem was the file itself(but not the content):
[root@myserver ~]# ./mysqlwtf start
Starting MySQL.. ERROR! The server quit without updating PID file (/mysql/myserver.mydomain.local.pid).
[root@myserver ~]# cp mysqlwtf mysqlwtf2
[root@myserver ~]# ./mysqlwtf2 start
Starting MySQL... SUCCESS!