Get the App
SLTechnology News&Howtos  ›  Database  › 

MySQL data export and import instance under Ubuntu command line

Shulou Source: shulou.com Published: 2022-05-31 18:48:39 10月04日 Update

This article introduces the relevant knowledge of "MySQL data export and import examples under the Ubuntu command line". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Mysqldump-h host-u user name-p name > exported database name. sql

Dump-h host-u user name-p database name table name > exported table name .sql

Some of the more commonly used parameters are

-P or-- the server port to which port is connected. This parameter is required if the port of MySQL is not 3306.

-d or-- no-data do not have detailed data, just export the structure of the data

-- when creating a database, add-drop-database first drop the existing database with the same name [usually followed by the-d parameter]

-- when creating a table, add-drop-table first drop the existing table with the same name [usually followed by the-d parameter]

Let's take the database of emlog as an example to do an export example.

one. Export all data (including data structures, including data) from the entire emlog database

Mysqldump-h227.0.0.1-u root-p emlog > emlog_all.sql

two. Export emlog_ blog tables (including table structure and table data)

Mysqldump-h 127.0.0.1-u root-p peerrecom > peerrecom.sql

three. Just export the structure of the database

Mysqldump-h227.0.0.1-uroot-p-d-- add-drop-table emlog > emlog_all_structure.sql

four. Just export the structure of the table

Mysqldump-h227.0.0.1-uroot-p-d-- add-drop-table emlog emlog_blog > emlog_blog_structure.sql

Import, there are many ways, the most simple is the source command, first use the mysql command to connect to the database. Then use source to import the file with the specified path.

Connect to MySQL

Mysql-h227.0.0.1-uroot-p

Create the database first, because there is no statement to create the database in the exported file. If the database has been built, you don't have to create it again.

CREATE DATABASE emlog COLLATE 'utf8_general_ci'

Switch database

Use emlog

Import the specified sql file

Mysql > source / path/.../source.sql

This is the end of the introduction of "MySQL data export and import examples under the Ubuntu command line". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Data database structure commands parameters files instances hosts content more users user names knowledge ports practical successful learning and then no dilemma actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Apple macOS Linux