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

Deploy Varnish cache proxy server based on Centos7

1. Varnish Overview 1. Introduction to Varnish Va...

Markup language - web application CSS style

Click here to return to the 123WORDPRESS.COM HTML ...

HTML Web Page List Tags Learning Tutorial

HTML web page list tag learning tutorial. In HTML ...

Nginx reverse proxy and load balancing practice

Reverse Proxy Reverse proxy refers to receiving t...

mysql installer web community 5.7.21.0.msi installation graphic tutorial

This article example shares the specific code for...

How to use nginx to block a specified interface (URL)

1. Introduction Sometimes, after the web platform...

Mysql | Detailed explanation of fuzzy query using wildcards (like,%,_)

Wildcard categories: %Percent wildcard: indicates...

Understanding of CSS selector weight (personal test)

Copy code The code is as follows: <style type=...

Navicat for MySQL 11 Registration Code\Activation Code Summary

Recommended reading: Navicat12.1 series cracking ...

What is web design

<br />Original article: http://www.alistapar...

How to configure the same domain name for the front and back ends of nginx

This article mainly introduces the method of conf...

Vue component to realize carousel animation

This article example shares the specific code of ...