Change the MySQL database storage location in Ubuntu

Source: Internet
Author: User

The database file storage location in the default configuration of MySQL installed in Ubuntu is/var/lib/mysql. If you have not mounted/var to a large enough partition, then/var will share the available space with the root directory/in the same partition.

The database file storage location in the default configuration of MySQL installed in Ubuntu is/var/lib/mysql. If you have not mounted/var to a large enough partition, then/var will share the available space with the root directory/in the same partition. Most users usually mount an independent partition for/home, so this article is about how to change the MySQL database storage location to another mount location.

What is the file structure of the MySQL database? For the Database Command created in this way:

Create database mysqldb

The default database storage location contains a folder named mysqldb. To operate the database, you must stop the database process first:

$ Sudo/etc/init. d/mysql stop

The following command transfers the original database to the new location by taking the location of/home/mysql as an example:

$ Sudo cp-R-p/var/lib/mysql/home/mysql

Edit the MySQL configuration file:

$ Gksu gedit/etc/mysql/my. cnf

Find the datadir line in gedit, change the content after the equal sign to/home/mysql, and save and exit. Since Ubuntu 7.10, Ubuntu has started to use a security software called AppArmor, which creates a region in your file system that allows application access (Terminology: application access control ). If you do not modify the AppArmor configuration file for MySQL, you will never be able to start the Database Service for the newly set database storage location. Configure AppArmor:

$ Sudo nano/etc/apparmor. d/usr. sbin. mysqld

Find/var/lib/mysql/In gedit, comment out the two lines, and add a symbol "#" before the two lines to comment out, add the following content before or after the two rows:

/Home/mysql/r,

/Home/mysql/** rwk,

Save and exit. Run the following command:

$ Sudo/etc/init. d/apparmor reload

Return Reloading AppArmor profiles: done. You can restart the MySQL service:

$ Sudo/etc/init. d/mysql start

Now the storage location of the MySQL database has been changed.

FAQ:

Q: When I run $ sudo/etc/init. d/apparmor reload, information is returned.

Skipping profile/etc/apparmor. d/usr. sbin. mysqld ~

: Warning.

MySQL service cannot be started. What should I do?

A: This problem may occur because you used commands like $ sudo gedit or $ gksu gedit to edit usr. sbin. for the configuration file mysqld, the two graphic interface text editors will generate a usr at the same location. sbin. mysqld ~ This affects AppArmor's reading of the configuration file. If this problem occurs, delete usr. sbin. mysqld ~ File:

$ Sudo rm/etc/apparmor. d/usr. sbin. mysqld ~

Then, use the terminal text editor $ sudo nano to edit the configuration file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.