Home > Operation and Maintenance > Linux 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
Release: 2019-04-09 11:54:03
forward
3587 people have browsed it

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 the Ubuntu 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
Copy after login

2. Export only Table structure

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

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
Copy after login

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;(数据库名可以不一样)
Copy after login

Switch database:

use example;
Copy after login

Import the specified sql file:

mysql>source /path/example.sql;
Copy after login

[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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template