Easy Tutorial
❮ Verilog2 Clock Programmer Without Network ❯

Linux Import and Export MySQL Database Commands

Category Programming Technology

I. Exporting Databases

1. Export Full Data: Table Structure + Data

Use the mysqldump command to export databases. The syntax is as follows:

mysqldump -uusername -p database_name > database_name.sql

The following command can export the data and table structure of the abc database:

# /usr/local/mysql/bin/mysqldump -uroot -p abc > abc.sql

After pressing Enter, you will be prompted to enter your password.

Note: The mysqldump command path depends on your MySQL installation path.

2. Export Only Table Structure

If you only need to export the MySQL table structure, you can use the -d option, as follows:

mysqldump -uusername -p -d database_name > database_name.sql

The following command can export the table structure of the abc database:

#/usr/local/mysql/bin/mysqldump -uroot -p -d abc > abc.sql

II. Importing Databases

Using the mysql Command to Import

The format for importing databases using the mysql command is as follows:

mysql -uusername -p database_name < database_name.sql

The following example imports the backup database abc.sql into the database:

# mysql -uroot -p123456 < abc.sql

Using the source Command to Import

Using the source command requires us to log into mysql first and create an empty database:

mysql> create database abc;      # Create database
mysql> use abc;                  # Use the created database 
mysql> set names utf8;           # Set encoding
mysql> source /home/abc/abc.sql  # Import backup database

Note the path of your backup sql file.


More Articles

MySQL Export Data

MySQL Import Data

** Click to Share Notes

Cancel

-

-

-

❮ Verilog2 Clock Programmer Without Network ❯