MySQL database backup and remote transfer files

Source: Internet
Author: User

One, backup and import of database

1), Backup of the database

1. Export the entire database
Mysqldump-u user name-p database name > exported file name
Example: Mysqldump-u dbadmin-p myblog >/home/zhangy/blog/database_bak/myblog.sql

2. Export a table
Mysqldump-u user name-P database name Table name > exported file name
Example: Mysqldump-u dbadmin-p myblog wp_users>/home/zhangy/blog/database_bak/blog_users.sql

3. Export a database structure
Mysqldump-u Dbadmin-p-D--add-drop-table myblog >/home/zhangy/blog/database_bak/blog_struc.sql
Description:-D has no data--add-drop-table add a drop table before each CREATE statement

4. Export the database a table structure
Mysqldump-u Dbadmin-p-D--add-drop-table myblog wp_users>/home/zhangy/blog/database_bak/blog_users_struc.sql
Description:-D has no data--add-drop-table add a drop table before each CREATE statement

2), Import the database

1, the file backed up with Mysqldump is a SQL script that can be poured directly, there are two ways to import data.
For example:
#/usr/local/mysql/bin/mysql-u root-p * * * * * MyBlog

This way, I used to be very rarely used now, because it is easy to produce garbled, because:

A, when you export the database, if you forget to set the export character sets, when the import, there may be problems.

b, if you set the export setting when the UTF8 encoding, but you have your database now the character set is changed to gb2312. This will be garbled.

2, using the source statement
For example:

Mysql-u dbadmin-p

Use MyBlog;

Set names UTF8; #这里的字符集根你的将要导入的数据库的字符集一至.

Source/home/zhangy/blog/database_bak/myblog.sql;

Instance

1. Copy from local to remote
Command format:

SCP Local_file [Email Protected]_ip:remote_folder
Or
SCP Local_file [Email protected]_ip:remote_file
Or
SCP Local_file Remote_ip:remote_folder
Or
SCP Local_file Remote_ip:remote_file

MySQL database backup and remote transfer files

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.