Published by: admin, date of publication: December 11, 2020

In this post I will take a note to myself and possibly others. Sometimes you have to import or export large databases. But doing it through third-party programs or scripts, it comes down to the limitations of POST data, the size of uploaded files to the server, or, ultimately, the speed of the Internet. Here I will describe the way to import / export Mysql database via ssh (console, terminal).

Database import.

In principle, you can use the command:

mysql -uroot -proot_pass db_name <db_name.sql

but it contains pitfalls in the form of the fact that if, for example, the database has already been created, then the import may fail.

The best way out of the situation is to import directly via the MySQL cli:

We go into MySQL:

mysql -uLogin -pPassword

(instead of Login and Password, enter data for authorizing the database user)
Select the database:

use db_name

(instead of db_name, enter the name of the database)
We import the file into the selected database :

source db_name.sql

(instead of db_name.sql, enter the name of the database dump file or the path to the file if you find it in the wrong folder where the file is located)

Database export.

We export using the convenient mysqldump:


Other materials from our site:

Leave a Reply

Your email address will not be published. Required fields are marked *