MySQL data migration under ubuntu

Usually install mysql in ubuntu using apt-get install mysql to install mysql. After installation, it defaults to the ubuntu system drive letter

Due to years of running out of disk space or other reasons to migrate the location

Record your operations today (ubuntu12.04 lts mysql5.5)

 

1. Stop the mysql service

sudo service mysql stop# mysql must be stopped before migration

 

2. Create the migration folder data 

sudo mkdir data #Create a data folder, generally mount an external physical hard disk

 

3. Move the mysql data file

mv /var/lib/mysql /data/ #Before moving, it is recommended to back up the mysql file, in case the operation error cannot be recovered

 

 

 sudo cp -arp /var/lib/mysql /data/mysql_bak #Copy a copy to mysql_bak first to prevent loss of recovery files by misoperation

4. Modify the my.cnf configuration file

my.cnf is under /etc/mysql

sudo vim my.cnf

 

 

5. Modify apparmor.d

sudo vim /etc/apparmor.d/usr.sbin.mysqld



 

 

6. Restart apparmor and mysql

sudo  service  apparmor  reload

sudo service mysql start

 

7. Test whether to connect to mysql

mysql -uroot -p

 

Notice:

1. Be sure to carefully modify the my.cnf and apparmor.d files

2. If the startup fails, please go to /var/log/mysql to view the log in the error.log file, and find the problem according to the error log

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326157610&siteId=291194637