Mysql backs up and transfers data, mysql backs up and transfers data

Source: Internet
Author: User

Mysql backs up and transfers data, mysql backs up and transfers data

I. Back up data using mysqldump

Directly enter the command mysqldump and you will find that the prompt command does not exist because the system will find the command under/usr/bin by default. If this command is not in this directory, the command will naturally not be found, and an error is reported. If you know where the problem is located, you can handle it directly, first use the find command to find the path contained in mysqldump. find/-name mysql-print // find the file named mysql, and then use the ln command to link to/usr/bin. Ln-fs/usr/local/mysql/bin/mysqldump/usr/bin

Note: The following error occurs:

mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when trying to connect

Solution:

Use find/-name mysql-print to view the mysql. sock path
Check vim/etc/my. cnf and check whether the specified path of socket =/var/lib/mysql. sock is correct or not.
Restart service mysqld restart
If the preceding error is reported, you can use a soft connection to establish a connection ln-s/var/lib/mysql. sock/tmp/mysql. sock.

 

Test migration for Logon Test

Mysql-h Server IP address-P 3306-u root-p

  

Database lock table: After this command is executed, all tables in the database are locked to read-only (if the session is closed, it is automatically unlocked). The unlock Command unlock tables

mysql> flush tables with read lock;  Query OK, 0 rows affected (0.00 sec)

 

Start backup

[root@localhost ~]# mysqldump -u root -p -A -B --master-data=1 | gzip > /123/test.sql.gz

 

Transmit the backup to the new database for recovery

[root@localhost ~]# scp /123/test.sql.gz 192.168.3.101:/root/

 

Restore data

[root@localhost ~]# gunzip test.sql.gz

[Root @ localhost ~] # Mysql-u root-p <test. SQL

 

Note: The following error indicates that slave is not disabled. Disable the command stop slave.

This operation cannot be performed with a running slave; run STOP SLAVE first

 

The recovery is successful and can be viewed visually.

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.