MySQL Command Line

Source: Internet
Author: User

MySQL Command Line

MySQL command line to export the database:

1. Go to the bin folder under the MySQL Directory: directory from cd MySQL to the bin folder

For example, if the command line I entered is cd C: \ Program Files \ MySQL Server 5.5 \ bin
(Or directly add the directory to the path of the windows environment variable)

2. Export Database: mysqldump-u username-p Database Name> exported file name

For example, the command line I entered is mysqldump-u lmapp-p lmapp-P 3308> lmapp. SQL (after entering the command, you will be asked to enter the MySQL password)
(If you export a single table, enter the table name after the database name)

Mysql exports a database table
Mysqldump-u user name-p database name Table Name> exported file name
Mysqldump-u lmapp-p lmapp users> test_users. SQL (no semicolon at the end)

3. The file news. SQL is automatically generated under the binfile.

The above problem occurs during export.

Solution: add the-P 3308 (mysql service port) parameter to solve the problem.

Command Line import database:

1. The. SQL file to be imported is moved to the binfile, which is convenient.
2. Step 1 of the above-mentioned export
3. Enter MySQL: mysql-u username-p
For example, the command line I entered is mysql-u root-p (enter the same password for MySQL)
4. Create the database you want to create in MySQL-Front. An empty database is used, for example, create a target database named "news ".
5. Enter the mysql> use target database name.
For example, the command line I entered is mysql> use news;
6. Import file: the file name imported from mysql> source;

For example, the command line I entered is mysql> source news. SQL;

Note: The import time varies greatly depending on the size and data structure of the imported database. I imported 123 MB of database, which took nearly 5 hours. During this period, I thought the machine was down. I carefully observed the command line interface and found that the import was normal. The imported interface is as follows:


Note: When importing a single data table, use an SQL statement similar to use lmapp lm_area and source lm_area. SQL. The original data table can exist. The imported data table overwrites the existing data table with the same name.

MySQL backup and restoration are completed using mysqldump, mysql, and source commands.

1. MySQL backup and restoration under Win32

1.1 backup

Start Menu | run | cmd | use the "cd \ Program Files \ MySQL Server 5.0 \ bin" command to enter the bin folder | use "mysqldump-u username-p databasename> exportfilename" to export database to file, for example, mysqldump-u root-p voice> voice. SQL, and then enter the password to start exporting.

1.2 restore

Enter the MySQL Command Line Client, enter the password, go to "mysql>", enter the Command "show databases;", Press enter to see what databases are there, and create the database you want to restore, enter "create database voice;", Press ENTER; switch to the database you just created, enter "use voice;", Press ENTER; import data, and enter "source voice. SQL; ", Press enter to start importing, and" mysql> "is displayed again. If no error is returned, the restoration is successful.

2. MySQL backup and restoration in Linux

2.1 backup

[Root @ localhost ~] # Cd/var/lib/mysql (go to the MySQL database directory and adjust the directory based on your MySQL installation)
[Root @ localhost mysql] # mysqldump-u root-p voice> voice. SQL. Enter the password.

2.2 restore

Method 1:

[Root @ localhost ~] # Mysql-u root-p press enter and enter the password to go To the MySQL console "mysql>", which is restored in the same way as 1.2.

Method 2:

[Root @ localhost ~] # Cd/var/lib/mysql (go to the MySQL database directory and adjust the directory based on your MySQL installation)
[Root @ localhost mysql] # mysql-u root-p voice <voice. SQL, enter the password.

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

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.