Mysql SQL statement for exporting data using commands-mysql tutorial

Source: Internet
Author: User
Next I will introduce in detail how to use mysqldump to export data backups in mysql and use the source command to import data. if you need it, please refer.

Next I will introduce in detail how to use mysqldump to export data backups in mysql and use the source command to import data. if you need it, please refer.

Command line source import database:

The code is as follows:

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 (after entering the same command, you will be asked to enter the ySQL password)
4. create the database you want to create in MySQL-Front. an empty database is used, for example, create a target database named blog (mysql> create database blog ;)
5. enter the mysql> use target database name.
For example, the command line I entered is mysql> use blog;
6. Import File: The file name imported from mysql> source;
For example, the command line I entered is mysql> source blog. SQL;

Other import methods

1. mysql imports files or data or executes related SQL statements

Mysql-h host address-u user name-p user password

1. file format. (Shell command line)

1

The code is as follows:
Mysql-u root-p dbname <filename. SQL

2. execute an SQL statement directly on the command line (shell command line ).

The code is as follows:

1 mysql-hhostname-uusername-p dbname-e 'select * from tbname limit 1'
After the command is executed, the command line prompts you to enter the database password. :)

3. use SQL as an input to MYSQL (shell command line)

The code is as follows:

1 echo 'Select id from dbname. tbname where id = 1; '| mysql-hhostname-ureadonly-preadonly dbname> xxxx. SQL


Export the database using the command line:

MySQL mysqldump is used for export. The basic usage is as follows:

Shell> mysqldump [OPTIONS] database [tables]

If you do not specify any tables, the entire database will be exported.

Run mysqldump-help to obtain the option table supported by your mysqldump version.

1. go to the bin folder under the MySQL Directory: Directory from cd MySQL to the bin folder
For example, run the following command line: cd F: Program FilesMySQLMySQL Server 5.1bin (bin folder in the mysql installation path)

2. export Database: mysqldump-u username-p database name> exported file name
For example, the command line I entered is mysqldump-u root-p bolg> blog. SQL (you will be prompted to enter the MySQL password after entering)

Some common SQL statements for exporting data

The code is as follows:

Mysqldump-u username-p database name> exported file name
Mysqldump-u wcnc-p smgp_rj_wcnc> wcnc. SQL

2. export a table

The code is as follows:

Mysqldump-u user name-p database name table name> exported file name
Mysqldump-u wcnc-p smgp_rj_wcnc users> wcnc_users. SQL

3. export a database structure

The code is as follows:

Mysqldump-u wcnc-p-d-add-drop-table smgp_apps_wcnc> d: wcnc_db. SQL

-D no data-add-drop-table add a drop table before each create statement

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.