Backup restore. sql/zip/sql.zip/gzip file method in MySQL

Source: Internet
Author: User
Tags character set zip

Importing data under Windows

(i) Export

Command: Mysqldump-u user name-p database name > filename

If the username requires a password, you need to enter a password check after this command is executed, and if the database username does not require a password, do not add the "-P" parameter and import the same. Note The user name you enter needs to have operational rights to the corresponding database, or you cannot export the data. As a result of system maintenance and the export of all databases, we usually use root and other super user rights.

For example, to export the ABC database to a database file named Db_abc.sql in the current directory, enter the following command:

#mysqldump-u root-p ABC > Db_abc.sql

If you want to export sql.zip or gzip format files directly, the following commands are:

Enter the mysqlbin> directory: mysqldump-u root-p b766951_apple >gzip > XX.sql.gzip
Enter Password: ********

Next, enter the root user's password to export the database.

(ii) Import

Command: Mysql-u user name-p database name < filename

The same as the mysqldump command, the meaning of each parameter with mysqldump.

For example, to import data from the/root/backup/db_abc.sql file into the ABC database, use the following command:

#mysql-u root-p ABC </root/backup/db_abc.sql or back <gzip < XX.sql.gzip

Importing data in Linux


If the database is large, consider using a direct copy method, but the different versions and operating systems may be incompatible, and should be used with caution.
3.1 Prepare original file
with tar package for a file
3.2 create empty database
3.3 Extract
Extract in temp directory, such as:
cd/tmp
Tar zxf mydb.tar.gz
3.4 copy copies the extracted database files to the related directory
CD mydb/
CP */var/lib/mysql/mydb/
for FreeBSD:
CP */var/db/mysql/mydb/
3.5 permission Settings change the owner of the file that copied the past to Mysql:mysql, change the permission to 660
Chown mysql:mysql/var/lib/mysql/mydb/*
chmod 660/var/lib/mysql/mydb/*
Change the mysqldump data. In addition to adding the table) Type=myisam CHARACTER set GBK, add a set NAMES GBK below;
This way, the data can be smoothly imported into 4.1 without fear of garbled characters.

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.