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