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

CocosCreator Universal Framework Design Network

Table of contents Preface Using websocket Constru...

Nginx reverse proxy springboot jar package process analysis

The common way to deploy a springboot project to ...

How to connect to MySQL remotely through Navicat

Using Navicat directly to connect via IP will rep...

Simple Mysql backup BAT script sharing under Windows

Preface This article introduces a simple BAT scri...

MySQL Database Basics SQL Window Function Example Analysis Tutorial

Table of contents Introduction Introduction Aggre...

Docker creates MySQL explanation

1. Download MySQL Image Command: docker pull mysq...

js implements axios limit request queue

Table of contents The background is: What will ha...

An example of elegant writing of judgment in JavaScript

Table of contents Preface 1. Monadic Judgment 1.1...

MYSQL METADATA LOCK (MDL LOCK) MDL lock problem analysis

1. Introduction MDL lock in MYSQL has always been...

Problems and solutions when installing and using VMware

The virtual machine is in use or cannot be connec...

An Incomplete Guide to JavaScript Toolchain

Table of contents Overview Static type checking C...

Problems with installing mysql and mysql.sock under linux

Recently, I encountered many problems when instal...

Summary of 7 reasons why Docker is not suitable for deploying databases

Docker has been very popular in the past two year...

Incredible CSS navigation bar underline following effect

The first cutter in China github.com/chokcoco Fir...