How to change the MySQL database storage location in Ubuntu

Source: Internet
Author: User

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 begins 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 new database storage location.

Database Service. 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, before the two rows, or

Add the following content:

/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.

  1. Difference between ms SQL Server and MySQL
  2. How to break through 4G restrictions in a single MySQL table
  3. Comparison between datetime and timestamp in MySQL

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.