How to change the default database storage location of MySQL in Ubuntu

Source: Internet
Author: User

The default database file storage location for MySQL installed in Ubuntu is/var/lib/MySQL,

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 uses 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 $ sudo gedit or $ gksu.
Run commands like gedit to edit the configuration file USR. sbin. mysqld. The two graphic interface text editors will generate
USR. 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.

 

This article Reprinted from: http://www.examda.com/ncre/three/db/fudao/20090531/083919323.html

 

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.