Home>Article>Operation and Maintenance> MySQL data export and import statements under Ubuntu command line

MySQL data export and import statements under Ubuntu command line

little bottle
little bottle forward
2019-04-09 11:54:03 3469browse

Do you know how to export and import MySQL data under the Ubuntu command line? The following is the method compiled by the editor for importing and exporting databases under theUbuntu command line. Let’s learn it together!

mysqldump -h host -u username -p database name> Exported database name.sql


Several commonly used parameters are:

-p or --port The server port to be connected. If the MySQL port is not 3306, you must use this parameter-d or -- no-data No detailed data, just export the structure of the data
--add-drop-table When creating a table, first drop the existing table with the same name [usually followed by the -d parameter]
The following is example Take the database as an example to do an export example:
1. Export all data of the entire example database (including table structure, including data)

mysqldump -h 127.0.0.1 -u root -p example > example.sql

2. Export only Table structure

mysqldump -h 127.0.0.1 -u root -p -d --add-drop-table example > example.sql

There are many ways to import, the simplest of which is the source command. First connect to the database. Then use source to import the file with the specified path. That’s it.

Connect to MySQL:

mysql -u root -p

Create the database first, because there is no statement to create a database in the exported file. If the database If it has already been built, there is no need to create it again.

CREATE DATABASE example;(数据库名可以不一样)

Switch database:

use example;

Import the specified sql file:

mysql>source /path/example.sql;

[Recommended course:

Linux video tutorial

]

The above is the detailed content of MySQL data export and import statements under Ubuntu command line. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete
Previous article:How to check Linux version? Next article:How to check Linux version?