Mysql Database Export Methods

Source: Internet
Author: User
Tags gz file mysql tutorial import database

Mysql tutorial exporting database tutorial Methods

Method 1

Run mysqldump -- opt-h192.168.0.156-uusername-ppassword -- skip-lock-tables databasename> database. SQL In the mysql bin directory.

You can change the ip address to localhost.

If navicate is installed, it is easier to connect to the database first, select the database, and then select the dump SQL.

Method 2

Go to cmd (note that in OS cmd, instead of mysql)

==============================

1. Export the database (SQL script)

Mysqldump-u username-p Database Name> exported file name

Mysqldump-u root-p db_name> test_db. SQL

2. mysql exports a database table

Mysqldump-u user name-p database name Table Name> exported file name

Mysqldump-u wcnc-p test_db users> test_users. SQL (no semicolon at the end)

Method 3

Start mysql Service

/Etc/init. d/mysql start

Export the entire database

Mysqldump dbname> c: mydb. SQL-u root-p

Import Database

Source mydb. SQL

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

More detailed import database tutorial

2.1. Export an SQL script

On the original database server, you can use the myadmin tool in the php tutorial or the mysqldump command line (the mysqldump command is located in the mysql/bin/directory) 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 full 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.

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.