Mysql – how to change thesql data directory

freebsdMySQL

I use FreeBSD 8.2, mysql 5.1.58. I want change mysql default directory. I config datadir= /path OR my-data-dir= /path on my.cnf but not done. Note: i permission for /path is 755 and owner mysql:mysql. By another way, i set in /etc/rc.conf but not done

This is error, when restart mysql services.

usr/local/etc/rc.d/mysql-server restart
mysql not running? (check /var/db/mysql/bsd1.abc.com.pid).

Help me.

Best Answer

I assume your current MySQL data directory is the default /var/db/mysql.

  1. Stop MySQL (service mysql-server stop)
  2. Change the datadir in rc.conf (mysql_dbdir="/another/directory")
  3. mv /var/db/mysql /another/directory
  4. Start MySQL again (service mysql-server start)

If there are still problems, ensure that the directory itself and all directories inside belong to user and group mysql. (chown -R mysql:mysql /another/directory; chmod 600 /another/directory)