MySQL Data migration method under CentOS

Source: Internet
Author: User

The first type:

The original database does not need to be reinstalled:

The default mysql will be installed in /var/lib/mysql Here, if the data is migrated to the /data/mysql directory, the steps are as follows:

1. stop MySQL service

2, #cp/var/lib/mysql/*/data/mysql/

#chown-R Mysql.mysql/data/mysql

3. Modify the my.cnf file

Basedir =/usr

DataDir =/data/mysql

Socket =/data/mysql/mysql.sock

Pid-file =/data/mysql/hostname.pid

if it is a third-party mysql-rpm package installation, the default profile is in the /usr/my.cnf directory

if yum is installed, the configuration file is /etc/my.cnf

4, modify the/etc/init.d/mysqld(yum installation with this,rpm third-party installation here to change / Etc/init.d/mysql) The datadir directory

5, after the migration mysql-u root-p is not in, need to reset the root password

#mysqld_safe--skip-grant-tables &

#mysql ( Open another window execution )

>use MySQL;

>update user Set Password=password (' New password ') where user= ' root '

>flush privileges;

6. Restart Service

#/etc/init.d/mysql start

at this point in the execution #mysql-uroot-p can go in, but show databases will first let set once password, Follow the prompts to do so.

Until this database migration is complete, the previous database can be operated properly.

The second Kind

The database needs to be reinstalled (must be the same version):

1, Reinstall after the default path or /var/lib/mysql, if you want to migrate to the /data directory, follow the first step to operate it.

2, the previous database recovery steps are as follows:

A) stop the MySQL service

b) Copy the previous /var/lib/msyql/order2017 to the /data/mysql directory. Modify Permissions chown-r mysql.mysql/data/mysql/order2017 This time the database and the table exist, but when viewing the data will be reported 1146 this error ; Continue with the following actions

c) Copy the previous /var/lib/mysql/ibdata1 cover /data/mysql/ibdata1

d) restart MySQL service

The previous database can also be accessed after reinstalling here

MySQL Data migration method under CentOS

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.