How to export a database from the MySQL command line

Source: Internet
Author: User
Tags localhost mysql table name import database mysql command line

1, into the MySQL directory under the Bin folder: cd MySQL to the Bin folder directory

As I entered the command line: CD C:/Program files/mysql/mysql Server 4.1/bin

(or add the directory directly to the environment variable path of Windows)
2, Export database: Mysqldump-u user name-p database name > exported file name
As I entered the command line: Mysqldump-u root-p News > News.sql (Input will allow you to enter the password into MySQL)
(If you export a single table, enter the table name after the database name)
3, will see the file News.sql automatically generated to the bin file

command-line Import Database

1, to move the imported. sql file to the bin file, this is a convenient path
2, the 1th step with the above export
3, enter mysql:mysql-u user name-P
As I entered the command line: Mysql-u root-p (Enter the same after will let you enter the MySQL password)
4, create the database you want to build in Mysql-front, this is an empty database, such as a new target database named News

5, enter: Mysql>use Target database name

As I entered the command line: Mysql>use news;

6, import file: Mysql>source import of the file name;

As I entered the command line: Mysql>source news.sql;

MySQL backups and restores are done using the mysqldump, MySQL, and source commands.

Backup and restore of MySQL under Linux

2.1 Backup
[Root@localhost ~]# cd/var/lib/mysql (access to MySQL library directory, adjust directory according to your MySQL installation situation)
[Root@localhost mysql]# mysqldump-u root-p voice>voice.sql, enter the password.
2.2 Restore

Law I:

[Root@localhost ~]# mysql-u root-p carriage return, enter password, enter MySQL console "mysql>", restore with 1.2.

Law II:

[Root@localhost ~]# cd/var/lib/mysql (access to MySQL library directory, adjust directory according to your MySQL installation situation)
[Root@localhost mysql]# mysql-u root-p voice<voice.sql, enter the password.

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.