1. Use the mysqldump command to export the database (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 Password
2. Export only the table structure
mysqldump -u username-ppassword-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 the database
1. First create an empty database
mysql>create database abc;
2.Import the database
Method 1:
(1)Select the database
mysql>use abc;
(2)Set database encoding
mysql>set names utf8;
(3)Import data (note the path of the sql file)
mysql>source /home/abc/abc.sql;
Method two:
mysql -u username -p password database name < database name.sql
#mysql -uabc_f -p abc < abc.sql
It is recommended to use the second method method to import.
Note: There is command line mode and sql command
The above is the detailed content of How to import and export mysql database under linux. For more information, please follow other related articles on the PHP Chinese website!