Link to home
Start Free TrialLog in
Avatar of andyd01
andyd01

asked on

How to Change mysql datadir in opensuse 11.1

I need to change the folder into which databases will be created for a new, clean MySql installation on OpenSuSe 11.1.  I've found a million articles about changing the datadir, but none of them seem to work on OpenSuSe.  I'm sure it doesn't help that I'm pretty new to MySql AND Linux!
Avatar of snoyes_jw
snoyes_jw
Flag of United States of America image

You have two places to specify the datadir - either as a command line parameter at startup, or in the configuration file.

On the command line, you'd do something like this (although you may be using some different startup script):
mysqld --datadir=/path/to/dir

In the config file (which is preferable), you'd find the [mysqld] section and do this:
datadir=/path/to/dir

If you're not sure which config file is in use, try this:

mysqld --help --verbose

There should be a section in the output that tells you the order in which MySQL will read the config files at startup.
ASKER CERTIFIED SOLUTION
Avatar of Umesh
Umesh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andyd01
andyd01

ASKER

Thanks for the responses.  I'm close, but mysql won't start up again.  I verified that all files in the new directory are owned by mysql.  The error (warning) I get is:

Starting service MySQL warning: /home/sql/mysql.sock didn't appear within 30 seconds
                                                                     done

Here's the [mysqld] section of the my.cnf:

# The MySQL server
[mysqld]
port            = 3306
socket            = /var/lib/mysql/mysql.sock
skip-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
datadir=/home/sql

The obvious suspect is the line
socket            = /var/lib/mysql/mysql.sock
but I tried changing that too (not knowing what the h*** I was doing).  Didn't work :-)

Thanks for your help!
Can you pls post error log contents here..  did you hard-code /home/sql/mysql.sock in any of the config files or in start-up file? where is your config file (in etc/my.cnf or in some other location..if so pls remove all my.cnf and make sure only one my.cnf exists in /etc)
Avatar of andyd01

ASKER

Thanks ushastry.  

I didn't hard code /home/sql/mysql.sock anywhere.  I tried it but when it didn't work I reverted to the original /var/lib/mysql/mysql/mysql.sock.

Here's the data from the error log:

090604 23:59:08  mysqld started
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
090604 23:59:08  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
090604 23:59:08  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
090604 23:59:08  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
090604 23:59:08  InnoDB: Started; log sequence number 0 0
090604 23:59:08 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
090604 23:59:08  mysqld ended

My configuration file is /etc/my.cnf and there aren't any others.

Thanks again!
Avatar of andyd01

ASKER

Correction, I reverted to the original socket entry:

/var/lib/mysql/mysql.sock
Did you copy the mysql database to the new location? because the MySQL is not starting because its unable to locate mysql.hosts table ...  also if its a clean installation then did you run mysql_install_db at the end? also can you post these from config file

basedir
datadir
Avatar of andyd01

ASKER

Working, thanks!
Avatar of andyd01

ASKER

While the solution above did ultimately work, the cleanest way turned out for me to:

1. Install mysql but don't start it up.  
2. Then add datadir=/home/sql (or whatever) to the [mysqld] section of /etc/my.cnf.
3. Create /home/sql
4. chown -R mysql:mysql /home/sql
5. start mysql
6. create databases

All databases being created will end up /home/sql.  Obviously this won't work if you've already got databases, but on a new install it worked perfectly for me.