Realization Method of Importing and Exporting mysql Database Command under linux
- 2021-09-24 23:54:05
- OfStack
1. Export the database using the mysqldump command (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
You will be prompted to enter your password after typing Enter
2. Export only 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 for mysql
2. Import the database
1. First, build an empty database
mysql>create database abc;
2. Import the database
Method 1:
(1) Select a database
mysql>use abc;
(2) Set the database code
mysql>set names utf8;
(3) Import data (note the path to the 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
It is recommended to import using the second method.
Note: There is command line mode and sql command