Home  >  Article  >  Database  >  Import and export mysql database commands under linux

Import and export mysql database commands under linux

黄舟
黄舟Original
2017-02-22 10:54:321139browse

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 hitting Enter, you will be prompted to enter the 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/ ---> mysql data directory


2. Import the database
1. First create Empty database
mysql>create database abc;

2. Import database
Method 1:
(1)Select database
mysql>use abc;
(2)Settings Database encoding
mysql>set names utf8;
(3) Import data (note the path of 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 use the second method to import.

Note: There is a command line mode and a sql command.

The above is the content of the import and export mysql database commands under Linux. For more related content, please pay attention to the PHP Chinese website (www.php .cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn