1. Export Database
1. Export complete data: table structure + data
Under Linux, you can usemysqldumpcommand to export the database, the syntax is as follows:mysqldump -u用户名 -p 数据库名 > 数据库名.sql
The following command can exportabcthe data and table structure of the database:
# /usr/local/mysql/bin/mysqldump -uroot -p abc > abc.sql
After pressing Enter, you will be prompted to enter the password; just enter it.
Note:The path of the mysqldump command depends on your MySQL installation path.
2. Only export table structure
If you only need to export the table structure of MySQL, you can use-doption, the format is as follows:
mysqldump -u用户名 -p -d 数据库名 > 数据库名.sql
The following command can exportabcthe table structure of the database:
#/usr/local/mysql/bin/mysqldump -uroot -p -d abc > abc.sql
2. Import Database
Import using the mysql command
The format for importing a database using the mysql command is as follows:
mysql -u用户名 -p 数据库名 < 数据库名.sql
The following example imports the backed-up database abc.sql into the database:
# mysql -uroot -p123456 < abc.sql
Import using the source command
Using the source command requires us to first log into mysql and create an empty database:
mysql> create database abc; # 创建数据库 mysql> use abc; # 使用已创建的数据库 mysql> set names utf8; # 设置编码 mysql> source /home/abc/abc.sql # 导入备份数据库
Pay attention to the path of your backed-up SQL file.