July 14, 2015

How to Change the Location of MySQL on cPanel

There may be some situations where you have to move the location of MySQL, for example, if you’re out of disk space or perhaps looking to host it on another device to increase performance. Whatever the reason, moving MySQL is simple and has no impact ct on cPanel’s functionality.

1) Create a backup

This should go without saying, but never mess with your data without making a backup of it. One simple way:
tar -cvf mysql.tar /var/lib/mysql

2) Modify my.cnf

In the [mysqld] section of /etc/my.cnf, add/modify this line:

datadir=/new/path/to/mysql

For example, if you are moving MySQL from /var/lib/mysql to /home2/mysql:

datadir=/home2/mysql

Don’t restart MySQL yet.

3) Sync the data

Now migrate the data to the new location using rsync. Typically you’ll want to stop MySQL, sync the data, then start it up again. If you have a lot of data and know the sync will take a while, do several syncs while the server is running, until they take less time. However, your last sync should always be done with MySQL stopped, especially if you have InnoDB tables. Here’s the command to sync with the example of MySQL being moved to /home2/mysql:
rsync -av /var/lib/mysql /home2
Now, relink the socket:
ln -sf /home2/mysql/mysql.sock /tmp

4) Restart MySQL

Since you already added the datadir entry to my.cnf, all you need to do is restart again and everything should be working.

or…
stop mysql
cd /var/lib
mv mysql /home
ln -s /home/mysql mysql
start mysql

Related Posts:

  • Installing Custom MySQL Versions If at all possible, you should use WHM to install MySQL, however, if you need a version of MySQL outside of what they are offering in current cPanel versions, it is possible to install your own versions. These instructions … Read More
  • Restoring Database Privileges I’ve seen several cases in the last few months where database users seemingly “disappear” or privileges appear to become invalid when restoring MySQL data or an entire server from raw backups. This may commonly be attributed… Read More
  • phpMyAdmin - Error You should upgrade to MySQL 5.5.0 or later I installed phpMyAdmin-4.2.9.1-english on a Centos 6.5 platform. 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux When I login I get the following screen: phpMyAdmin - Error … Read More
  • How to Change the Location of MySQL on cPanel There may be some situations where you have to move the location of MySQL, for example, if you’re out of disk space or perhaps looking to host it on another device to increase performance. Whatever the reason, moving MySQL i… Read More
  • Chạy lệnh mysql không cần password Thủ thuật này dành cho những người lười thôi. Còn nếu bạn lo ngại đến vấn đề bảo mật thì tốt nhất không nên sử dụng. Tạo file nano ~/.my.cnf rồi điền thông tin MySQL username và password tương ứng: [client] u… Read More

0 comments:

Post a Comment