MySQL import and export database under Linux

Under linux

1. Use the mysqldump command to export the database (note the installation path of mysql, that 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. Only export 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/ ---> data directory of mysql


Second, import the database
1, first create an empty database
mysql>create database abc;

2. Method 1 of importing database
:
(1) Select database
mysql>use abc;
(2) Set database code
mysql>set names utf8;
(3) Import data (pay attention to the path of 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

 

You can query the foreign key check before importing the file. Before importing the
sql file, cancel the foreign key check: set foreign_key_checks=0;
after importing the sql file, add the foreign key check: set foreign_key_checks=1;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324953911&siteId=291194637