Export the entire database and restore
# mysqldump-uroot-p123456-b-A--events-x|gzip>/opt/bak_$ (date +%f). sql.gz
# ll/opt/bak_$ (Date +%f). sql.gz
Import the entire database
# cd/opt/
# gzip-d Bak_2015-11-04.sql.gz
# mysql-uroot-p123456 <bak_2015-11-04.sql
==============================================================================
Export a specified library and restore
Method One:
1.1 Exporting a database BBS
# Mysqldump-uroot-p123456-b BBS--events-x|gzip>/opt/bak_$ (date +%f). sql.gz
1.2 Extracting the database
# gzip-d Bak_2016-05-06.sql.gz
1.3 Importing a database
1) Create an empty database
mysql> CREATE DATABASE BBS;
2) Select Database
mysql> use BBS;
3) Set the database encoding
mysql> set names UTF8;
4) Import data
Mysql> Source/opt/bak_2016-05-06.sql
1.4 Checking the imported library files
mysql> show databases;
mysql> use BBS;
Mysql> Show tables;
mysql> desc Pre_bbsucenter_vars;
Method Two:
2.1 Exporting a database
Mysql-u User name-p password database name < database name. sql
# mysqldump-uroot-p123456 Jzh >/opt/bakjzh_$ (date +%f). sql
# mysqldump-uroot-p123456 Oldboy >/opt/bakoldboy_$ (date +%f). sql
2.2 Checking the Export database
# ll/opt/
-rw-r--r--1 root root 1753 May 6 15:13 Bakjzh_2016-05-06.sql
-rw-r--r--1 root root 3022 May 6 15:15 Bakoldboy_2016-05-06.sql
2.3 Creating an empty database
mysql> CREATE DATABASE Jzh;
mysql> CREATE DATABASE Oldboy;
2.4 Importing Data
# mysql-uroot-p123456 Jzh </opt/bakjzh_2016-05-06.sql
# mysql-uroot-p123456 Oldboy </opt/bakoldboy_2016-05-06.sql
2.5 Checking the integrity of the data
mysql> show databases;
mysql> use Oldboy;
Mysql> Show tables;
mysql> desc Student;
The self-accomplishment-ywliyq of Linux operation and maintenance
This article is from the "Linux operations self-cultivation" blog, please be sure to keep this source http://ywliyq.blog.51cto.com/11433965/1770782
Mysqldump backing up the database for import