Linux migration MySQL Database storage directory

Source: Internet
Author: User

Method One:

Refer to the method under Windows, move the/var/lib/mysql to the desired directory, modify the/etc/my.cnf file, and specify the data directory. This aspect of the tutorial online a lot, you can go to search.

Shut down MySQL Service

There are three settings in My.ini [Mysqld], and the path is changed to the path after the move

The code is as follows Copy Code

Basedir= "d:/mysql-5.0.15b/"

Datadir= "D:/mysql-5.0.15b/data"

Innodb_data_home_dir= "D:/mysql-5.0.15b/data"

It would be nice to restart the MySQL service.

Here are the corresponding folders and files in the folders that were just moved.

Basedir, will affect the bin directory, affecting services;

DataDir, affecting the database storage path;

The basedir must be set when migrating, or it will basically cause the service to fail to start, ibdata1 typically on the upper level of the Data folder.

Another InnoDB data file ibdata1 if not placed in the default location, then be sure to set up, otherwise the first time the service can be started, and will be in the path should be stored ibdata1 a new initial ibdata1 file, looks normal, However, the data for all databases using the InnoDB storage engine will be lost and may fail to start, or all sorts of unexpected errors, when restarted again.


Method Two:

Using the soft connection method under Linux, the following actions are as follows: (to migrate to the/home/mysql/directory for example)
Stop MySQL First:

The code is as follows Copy Code

/etc/init.d/mysqld stop

Move data:

mv/var/lib/mysql/*/home/mysql/

To create a soft connection:

Ln-s/home/mysql//var/lib/mysql/

Start MySQL:

/etc/init.d/mysqld start


Move data:
Mv/var/lib/mysql/home/mysql
To create a soft connection:
Ln-s/home/mysql/var/lib/mysql

The two commands mean: To move the MySQL in the/var/lib/directory to the/home/directory and keep the original directory properties
Create a soft connection MySQL directory that links to the/home/mysql/directory under the/var/lib/directory.

Summarize

Have a lot of friends on the internet said to use

Move data:
mv/var/lib/mysql/*/home/mysql/
To create a soft connection:
Ln-s/home/mysql//var/lib/mysql/

People need to pay attention to Ah, this method is not not to be unsafe.

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.