How to import and export a MySQL database

Source: Internet
Author: User
Tags gz file import database
Welcome to the Linux community forum and interact with 2 million technical staff. there are two ways to import a MySQL database: 1) Export the database SQL script and import it again; 2) directly copy the database directory and files. In different operating systems or MySQL versions, the method of directly copying files may be incompatible. Institute

Welcome to the Linux community forum and interact with 2 million technical staff> enter 1. there are two ways to import a MySQL database: 1) Export the database SQL script and import it again; 2) directly copy the database directory and files. In different operating systems or MySQL versions, the method of directly copying files may be incompatible. Institute

Welcome to the Linux community forum and interact with 2 million technicians>

1. Overview

There are two ways to import a MySQL database:

1) Export the database SQL script first and then import it;

2) directly copy database directories and files.

In different operating systems or MySQL versions, the method of directly copying files may be incompatible.

Therefore, we recommend that you use SQL scripts to import data. The following describes two methods.

2. Method 1: SQL script

The procedure is as follows:

2.1. Export an SQL script

On the original database server, you can use the phpMyAdmin tool or the mysqldump command (the mysqldump command is located in the mysql/bin/directory) command line to export the SQL script.

2.1.1 phpMyAdmin

Select "structure" and "data" to export. Do not add the "Drop DATABASE" and "Drop TABLE" options.

Select the "Save As file" option. If you have more data, select the "gzipped" option.

Save the exported SQL file.

2.1.2 use mysqldump command line

Command Format

Mysqldump-u username-p Database Name> database name. SQL

Example:

Mysqldump-uroot-p abc> abc. SQL

(Export the database abc to the abc. SQL file)

Enter the password of the Database User Name When prompted.

2.2. Create an empty Database

Create a database on the master page/control panel. Assume that the database name is abc and the database user is abc_f.

2.3. Import and execute SQL scripts

You can use either phpMyAdmin or mysql command line.

2.3.1 use phpMyAdmin

From the control panel, select the created empty database and click "manage" to go to the management tools page.

In the "SQL" menu, browse and select the exported SQL file, and click "run" to load and execute.

Note: phpMyAdmin has a limit on the size of the uploaded file, and php itself has a limit on the size of the uploaded file. If the original SQL File

Relatively large, you can use gzip to compress it. For text files such as SQL files, you can obtain a compression rate of or higher.

Gzip usage:

# Gzip xxxxx. SQL

Get

Xxxxx. SQL .gz file.

2.3.2 use mysql Command Line

Command Format

Mysql-u username-p database name <database name. SQL

Example:

Mysql-uabc_f-p abc <abc. SQL

(Import database abc from abc. SQL file)

Enter the password of the Database User Name When prompted.

Method 2: Enter mysql, create a database, select a database, and run the following code: d: \ 112121. SQL is the database directory.

Mysql> source d: \ mongo121. SQL

[1] [2]

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.