MySQL export of entire or single table data

MySQL export of entire or single table data

Export a single table

mysqldump -u user -p dbname tablename > db.sql

Importing a single table

mysql>drop tablename;

mysql -u user -p dbname < db.sql

Export the entire table

mysqldump --opt -d dbname -u dbuser -p > db.sql

mysqldump dbname -udbuser -p > db_dt.sql

Supplementary knowledge: MySQL import and export sql files: export the entire database, export a table, export a database structure, import a database

mysql import and export sql file

Under the window

1. Export the entire database

mysqldump -u username -p database name > exported file name

mysqldump -u dbuser -p dbname > dbname.sql

2. Export a table

mysqldump -u username -p database name table name > exported file name

mysqldump -u dbuser -p dbname users> dbname_users.sql

3. Export a database structure

mysqldump -u dbuser -p -d --add-drop-table dbname >d:/dbname_db.sql

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

4. Import the database

Common source commands

Enter the mysql database console, such as

mysql -u root -p

mysql>use database

Then use the source command, followed by the script file (such as the .sql file used here)

mysql>source d:/dbname.sql

Import data into the database

mysql -uroot -D database name

Import data into a table in the database

mysql -uroot -D database name table name

D:\APMServ5.2.6\MySQL5.1\bin>mysqldump -u root -p erp lightinthebox_tags > lightinthebox.sql

Under Linux

1. Export the database using the mysqldump command (note the installation path of mysql, which is the path of this command):

1. Export data and table structure:

mysqldump -u username -p password database name> database name.sql

#/usr/local/mysql/bin/mysqldump -uroot -p abc > abc.sql

After pressing Enter, you will be prompted to enter a password

2. Export only the table structure

mysqldump -u username -p password -d database name> database name.sql

#/usr/local/mysql/bin/mysqldump -uroot -p -d abc > abc.sql

Note: /usr/local/mysql/bin/ —> mysql data directory

2. Import database

1. First create an empty database

mysql>create database abc;

2. Import database

Method 1:

(1) Select a database

mysql>use abc;

(2) Set the database encoding

mysql>set names utf8;

(3) Import data (pay attention to the path of the sql file)

mysql>source /home/abc/abc.sql;

Method 2:

mysql -u username -p password database name < database name.sql

#mysql -uabc_f -p abc < abc.sql

The above operation of exporting the entire and single table data of MySQL is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • MySQL uses frm files and ibd files to restore table data
  • Solve the problem that the MySQL database crashes unexpectedly, causing the table data file to be damaged and unable to start
  • Why the disk space is not released after deleting data in MySQL
  • Solution to mysql failure to start due to insufficient disk space in ubuntu
  • Common problems with the MySQL storage engine MyISAM (table corruption, inaccessibility, insufficient disk space)
  • How to turn off MySQL log to protect disk space under lnmp
  • Several suggestions for shrinking MySQL to save disk space
  • How to free up disk space after deleting data in Mysql InnoDB
  • Why is the disk space still occupied after deleting table data in MySQL?

<<:  JavaScript to implement a simple shopping form

>>:  How to deploy a simple c/c++ program using docker

Recommend

HTML Basics: The basic structure of HTML

The basic structure of HTML hypertext documents is...

Several ways to connect tables in MySQL

The connection method in MySQL table is actually ...

JS operation object array to achieve add, delete, modify and query example code

1. Introduction Recently, I helped a friend to ma...

Detailed explanation of common methods of JavaScript Array

Table of contents Methods that do not change the ...

In-depth analysis of MySQL query interception

Table of contents 1. Query Optimization 1. MySQL ...

The difference and usage between div and span

Table of contents 1. Differences and characterist...

Summary of MySQL ALTER command knowledge points

When we need to change the table name or modify t...

A brief analysis of the best way to deal with forgotten MySQL 8 passwords

Preface Readers who are familiar with MySQL may f...

Steps to configure nginx ssl to implement https access (suitable for novices)

Preface After deploying the server, I visited my ...

SQL Optimization Tutorial: IN and RANGE Queries

Preface "High Performance MySQL" mentio...

Several methods to execute sql files under mysql command line

Table of contents The first method: When the MySQ...

Understand the principles and applications of JSONP in one article

Table of contents What is JSONP JSONP Principle J...

jQuery realizes the shuttle box effect

This article example shares the specific code of ...

Docker installation rocketMQ tutorial (most detailed)

RocketMQ is a distributed, queue-based messaging ...