Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Main Support Categories > Server Platforms
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Server Platforms
Discussion regarding the Ubuntu Server Edition. For more information on the Ubuntu Server Team, please visit their wiki page or Launchpad page.

 
Thread Tools Display Modes
Old June 16th, 2008   #1
christonabike
First Cup of Ubuntu
 
Join Date: Dec 2007
Beans: 2
MySQL won't start after changing datadir

I'm attempting to change the datadir of a fresh MySQL install. After changing the datadir, MySQL will no longer start. It doesn't give any reasons, it simply says [fail]. When I change the datadir back to the default (/var/lib/mysql), MySQL starts fine. Ultimately, I would like the datadir to be a folder on a different partition and disk, but for testing purposes I have tried using a folder on the same partition and disk (/home/jeremy/test) but cannot get it to work.

Things I have tried:
  • Following the directions in this thread, to the letter.
  • Copying the files from /var/lib/mysql to /home/jeremy/test and running chown -R mysql:mysql on the folder. I've also tried various permutations of permissions and ensured the permissions and owners match exactly between the 2 directories.
  • Both copying and not copying the ib_log* and ibdata* files.

I've also made sure that mysql is stopped before making any changes to any files whatsoever. Once again, this is a fresh install with nothing created. It starts/works fine when the datadir is set to the default but not when I change it to anything else.

Any help is greatly appreciated!
christonabike is offline   Reply With Quote
Old June 19th, 2008   #2
christonabike
First Cup of Ubuntu
 
Join Date: Dec 2007
Beans: 2
Re: MySQL won't start after changing datadir

After spending way, way, way, way, way, way, way (each way equals ~ an hour of my time) on this, the solution was disgustingly simple.

Basically, you need to add the directories you want MySQL to be able to access to MySQL's apparmor profile. These steps, in order, should allow you to change MySQL's datadir even if you have existing databases.

Run the following commands (as root when necessary):

/etc/init.d/mysql stop
cp -rp /var/lib/mysql /new/mysql/dir
vi /etc/apparmor.d/usr.sbin.mysqld

Add the following two lines to the bottom:
/new/mysql/dir r,
/new/mysql/dir/** rwk,

/etc/init.d/apparmor restart
vi /etc/mysql/my.cnf

Change datadir from:
datadir=/var/lib/mysql
to:
datadir=/new/mysql/dir

/etc/init.d/mysql restart


Why does this seem so easy retrospectively?
christonabike is offline   Reply With Quote
Old September 8th, 2008   #3
sandboy10000
First Cup of Ubuntu
 
Join Date: Sep 2008
Beans: 2
Re: MySQL won't start after changing datadir

hi christonabike. I follow your thread step by step.
But still can't start mysql after changing datadir.

My ubuntu version is
Linux version 2.6.24-16-server (buildd@palmer) (gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)) #1 SMP Thu Apr 10 13:58:00 UTC 2008.
sandboy10000 is offline   Reply With Quote
Old September 8th, 2008   #4
sandboy10000
First Cup of Ubuntu
 
Join Date: Sep 2008
Beans: 2
Re: MySQL won't start after changing datadir

this is my error log in /var/log/syslog

Sep 9 00:41:54 www kernel: [46577.909134] audit(1220892114.838:76): type=1503 operation="inode_create"
requested_mask="w::" denied_mask="w::" name="/ape/mysqldata/www.lower-test" pid=10522 profile="/usr/sbin
/mysqld" namespace="default"
Sep 9 00:41:54 www mysqld[10524]: 080909 0:41:54 [Warning] Can't create test file /ape/mysqldata/www.l
ower-test
Sep 9 00:41:54 www mysqld[10524]: 080909 0:41:54 [Warning] Can't create test file /ape/mysqldata/www.l
ower-test
Sep 9 00:41:54 www kernel: [46577.931154] audit(1220892114.858:77): type=1503 operation="inode_permissi
on" requested_mask="rw::" denied_mask="rw::" name="/ape/mysqldata/ibdata1" pid=10522 profile="/usr/sbin/
mysqld" namespace="default"
Sep 9 00:41:54 www mysqld[10524]: 080909 0:41:54 InnoDB: Operating system error number 13 in a file o
peration.
Sep 9 00:41:54 www mysqld[10524]: InnoDB: The error means mysqld does not have the access rights to
Sep 9 00:41:54 www mysqld[10524]: InnoDB: the directory.
Sep 9 00:41:54 www mysqld[10524]: InnoDB: File name ./ibdata1
Sep 9 00:41:54 www mysqld[10524]: InnoDB: File operation call: 'open'.
Sep 9 00:41:54 www mysqld[10524]: InnoDB: Cannot continue operation.
Sep 9 00:41:54 www mysqld_safe[10530]: ended
Sep 9 00:42:08 www /etc/init.d/mysql[10680]: 0 processes alive and '/usr/bin/mysqladmin --defaults-file
=/etc/mysql/debian.cnf ping' resulted in
Sep 9 00:42:08 www /etc/init.d/mysql[10680]: ^G/usr/bin/mysqladmin: connect to server at 'localhost' fa
iled
Sep 9 00:42:08 www /etc/init.d/mysql[10680]: error: 'Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2)'
Sep 9 00:42:08 www /etc/init.d/mysql[10680]: Check that mysqld is running and that the socket: '/var/ru
n/mysqld/mysqld.sock' exists!
Sep 9 00:42:08 www /etc/init.d/mysql[10680]:
sandboy10000 is offline   Reply With Quote
Old October 12th, 2008   #5
shosta
First Cup of Ubuntu
 
shosta's Avatar
 
Join Date: Mar 2007
Beans: 4
Ubuntu 7.04 Feisty Fawn
Re: MySQL won't start after changing datadir

Thank you for your information.
I run into this problem and solved with this thread.
I was running mysql installed through the synaptic - edit - mark packages by task - LAMP Server in Hardy.
shosta is offline   Reply With Quote
Old August 27th, 2009   #6
4835jack
First Cup of Ubuntu
 
Join Date: Jun 2009
Beans: 2
Re: MySQL won't start after changing datadir

Moving Mysql Databases to a different drive.

Open the Terminal
Root -i This makes you the root user.
/etc/inin.d/mysql stop This stops MYSQL
mv -rp /var/lib/mysql /Path to where you want the database to reside/mysql

This command moves your database.

Now we need to edit some files so that MYSQL can find the database.
We will be using the VI editor so if you don't know how to use it, please do a google search before you begin.
vi /etc/apparmor.d/usr.sbin.mysqld

Go to the bottom of this file and add these two lines.

/the new patth to your database/ r,
/the new path to your database/** rwk,

Save the file and quit the VI editor

/etc/init.d/apparmor restart

vi /etc/mysql/my.cnf

Look for the line that starts with datadir
change this line to
datadir = the path to the new location of your database.

Save the file and quit the VI editor

/etc/init.d/mysql restart

exit

If you have made it to the end with no errors your databases will now be accesable in there new location.
4835jack is offline   Reply With Quote

Bookmarks

Tags
datadir, mysql, mysqld

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:22 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry