First, export:
using the mysqldump command line
command Format
mysqldump-u user name-p database name > database name. SQL
Example:
mysqldump-u root-p ABC > Abc.sql
(Export database ABC to abc.sql file)
when prompted for a password, enter the password for the database user name.
Second, import:
using the MySQL command line
command Format
mysql-u user name-p database name
third, direct copy
if the database is larger, you can consider the method of direct copy, but different versions and operating systems may be incompatible between the use of caution.
3.1 Package The original database with tar as a file
TAR-ZCVF mydb.tar.gz mydb
3.2 Creating an empty database
3.3 Decompression
unzip in the temp directory, such as:
cd/tmp
TAR-ZXVF mydb.tar.gz
3.4 Copy
Copy the extracted database files to the relevant directory
CD mydb/
CP */var/lib/mysql/mydb/
for FreeBSD:
CP */var/db/mysql/mydb/
3.5 Permission Settings
Change the owner of the copy of the previous file to Mysql:mysql and change the permission to 660
chown mysql:mysql/var/lib/mysql/mydb/*
chmod 660/var/lib/mysql/mydb/*
//--------------------------------------------------------------------------------------------------------
1.mysqldump-u user name-p database name > exported filename mysqldump-u wcnc-p smgp_apps_wcnc > Wcnc.sql
2.mysql Export Database One table mysqldump-u user name-P database name Table name > exported file name mysqldump-u wcnc-p smgp_apps_wcnc users> wcnc_users.sql
3.mysql Export a database structure mysqldump-u wcnc-p-D--add-drop-table smgp_apps_wcnc >d:wcnc_db.sql-d no data--add-drop-table in each C Add a drop table before the reate statement
4.mysql Import Database The common source command enters the MySQL database console, such as the Mysql-u root-p mysql>use database and then uses the source command, followed by the script file (as used here. sql)
Mysql>source D:wcnc_db.sql
//-------------------------------------------------------------------------------------------------------------
First, export the database with the mysqldump command (note the installation path of MySQL, which is the path to this command):
1. Export Data and table structure:
Mysqldump-u User name-p password database name > database name. sql
#/usr/local/mysql/bin/mysqldump-uroot-p ABC > Abc.sql
You will be prompted to enter your password after hitting enter
2. Export table structure only
Mysqldump-u User name-p password-d database name > database name. sql
#/usr/local/mysql/bin/mysqldump-uroot-p-D ABC > Abc.sql
Second, import the database
1, first build empty database
Mysql>create database ABC;
2. Import the database
Method One:
(1) Select database
Mysql>use ABC;
(2) Setting the database encoding
Mysql>set names UTF8;
(3) Import data (note the path to the SQL file)
mysql>source/home/abc/abc.sql;
Method Two:
Mysql-u User name-p password database name < database name. sql
#mysql-UABC_F-P ABC < Abc.sql
Note: There is a command-line mode with SQL command
MySQL database import and Export