mysql database in non default location

197 views
Skip to first unread message

claudius

unread,
Apr 22, 2012, 6:41:29 PM4/22/12
to Stacks
Hi,

if anybody knows how to convince mysql to see databases outside of the
default "/var/lib/mysql" folder, I would be very grateful if you could
tell me.

I have tried symlinks and I have tried changing the "datadir" in "/etc/
mysql/my.cnf" as well as changing the paths in "/etc/apparmor.d/usr/
sbin.mysqld". Both doesn't change anything (after restarting mysql and
apparmor).

I am running the mysql Server version 5.1.58-1ubuntu1 on Ubuntu 11.10
(oneiric).

many thanks,

claudius

Benjamin Evans

unread,
Apr 23, 2012, 1:07:56 PM4/23/12
to Stacks
Claudius,

We have a similar setup (last version of Ubuntu and a slightly older
version of mysql server) but it is working. Is your desired directory
on the same drive?

If you think AppArmor is the culprit you might want to switch the
profile for mysqld to complain as described here:
https://help.ubuntu.com/11.10/serverguide/C/apparmor.html
That will make AppArmor only complain and not actually stop any
perceived naughtiness that mysqld is up to.

For reference, I set ours up to deposit all the data onto a separate
drive mounted at "/data" in a directory called mysql. You need to
make sure that mysql has the propper permissions to the desired
directory as well. After disabling AppArmor, I changed our mysqld
AppArmor profile by adding a couple lines to the profile
usr.sbin.mysqld:

/usr/sbin/mysqld {
...
/data/mysql/ r,
/data/mysql/** rwk,
...
}

Then I reloaded AppArmor and the system was happy again.

If you are having issues with the my.cnf file I found it a bit easier
to manipulate them using MySQL Workbench via the server administration
it provides, though all I needed to change in my.cnf was the binding
address (for external access) and the data directory, which you have
already done.

Let me know if you're still having issues!
-Ben

claudius

unread,
Apr 27, 2012, 1:51:22 PM4/27/12
to Stacks
Hi Ben,

many thanks for your hints. However, all your suggestions and all
apparently simple and straightforward instruction that I found on the
web, like this one, for an example:
http://article.my-addr.com/?show=linux_ubuntu_change_datadir-move_mysql_database_to_other_path
or this one:
http://kaliphonia.com/content/linux/how-to-move-mysql-datadir-to-another-drive
... quite simply didn't have any effect.
I even renamed and moved my "/var/lib/mysql" directory to a different
location and mysql would still find this folder and only this one
(after stopping and starting mysql). It seemed like it totally ignored
the option "datadir" under "[mysqld]" in "/etc/mysql/my.cnf".

I had apparmor in complain mode for mysql all the time and also
changed the allowed directory in its mysql profile as you suggested.
So, that most likely wasn't the problem.

After a while a got a cryptic error message in mysql when trying to
show databases. So I removed and reinstalled the mysq-server. Then I
gave the possibility of symbolic links another try, as described here:
http://dev.mysql.com/doc/refman/5.5/en/symbolic-links.html
Now, it worked!

I can now free up disk space on my system partition and do more stacks
runs while storing databases on my data partitions.

cheers,

claudius

On Apr 23, 6:07 pm, Benjamin Evans <benjamin.robert.ev...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages