Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-23-2007, 03:01 PM   #1
Registered: Jun 2003
Location: Currently Denmark
Distribution: Ubuntu 11.10
Posts: 334

Rep: Reputation: 30
MySQL - Needed enforcing of a user defined directory for the database.

Doing a MySQL Java DB project and I would like to be able to decide on where MySQL creates it's databases for backup purposes.

I have tried to go into the /etc/mysql/my.cnf file and have altered the line datadir = /var/lib/mysql to /home/ep/5sem/database as I have seen this suggested.

It did not work.

Tried to save the file as .my.cnf, didn't work either as suggested.

Tried to rename the my.cnf to mmy.cnf also so that it would not interfere with the previously changed file, sadly I could start MySQL, but the database file was created in the /var/lib/mysql directory.... So here I am...

Reebooted the system every time I made a change.

Also tried mysqladmin -u root -p shutdown
Enter password: ***

The DB stopped - But the changes in the datadir = had the following effect when I tried to restart.

mysql -u root -p
Enter password: ***

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Version info: mysql Ver 14.12 Distrib 5.0.38, for pc-linux-gnu (i486) using readline 5.2

Excerpt from my.cnf

# * Basic Settings
user = mysql
pid-file = /var/run/mysqld/
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
# datadir = /var/lib/mysql
datadir = /home/ep/5sem/database
tmpdir = /tmp
language = /usr/share/mysql/english

Any suggestions on how to force MySQL to use the directory /home/ep/5sem/database to save all information to ?

Last edited by Nimoy; 10-23-2007 at 05:04 PM. Reason: Adding additional information
Old 10-25-2007, 09:25 AM   #2
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 199

Rep: Reputation: 30
Hmmm, not exactly a programming question but wth. You are doing it right. All that needs to be done is datadir parameter changed and all the data files moved to the new location. Though, you must keep in mind these few things :

- new directory exists at the moment you start db
- your mysql database was copied to the new directory (just copy the files)
- your server really uses the file that you are modifying

In the case you have already deleted your old mysql db - which basically means that you lost all your users and settings - you need to recreate it. Use mysql_install_db script to do it. Once done, make sure you have proper ownership on these drectories (mysql.mysql). If none of above works - call ghostbusters


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mySQL deny user access to database blizunt7 Programming 3 10-10-2007 09:34 AM
MySQL won't change database directory techker Linux - Software 2 10-04-2006 01:11 PM
creat MySQL database for each user ? Data-Base SUSE / openSUSE 3 03-07-2005 02:42 PM
FYI: Creating User Defined Functions for MySQL mchirico Member Success Stories 1 06-11-2004 08:51 PM
MySQL database directory GATTACA Programming 7 12-06-2003 11:54 PM

All times are GMT -5. The time now is 03:47 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration