Importing MySQL Databases Via SSH Command Line On Self Managed Servers

SANGKRIT.net not only offers you Managed and Fully Managed servers but it also lets you subscribe self-managed server option which is only recommended for command line experts. Because self-managed servers are without a control panel such as cPanel, Plesk, or Simple Control Panel.

These self-managed servers do not have phpMyAdmin installed which is used for managing MySQL databases. So in order to manage databases, you are required to use the SSH command line to import .SQL backup files.

This post guides you through importing MySQL databases via SSH.

How to import MySQL Database via SSH?

First of all open the .SQL file in a text editor to ensure it is formatted to use the correct database. There should be a use database command at the top, and it should reference the database that is receiving the imported data. If this command is not included, you can add or use it once you log in to MySQL.

Now log in to SSH as the root user:

  1. Log on to your server.
  2. At the command line, type su -. This gives you root access.
  3. At the command line, type mysql -uroot -p
  4. Enter your MySQL root password.

MySQL’s default root password is an empty string, no password is set here.

Time to log in to MySQL – type mysql -u username -p, here database username will be used as your username to login. You will see Enter password, enter your password for that MySQL user.

Now follow the given steps:

  1. If you did not include the use database command in the .SQL file, select the target database of the import.
  2. This is done by typing use database_name and then press Enter.
  3. Type SOURCE /path/to/sql/file.sql, and then press Enter.
  4. Monitor the running import log to check for errors.

To confirm the data was imported correctly, type show tables; and then press Enter. Then type select * from the table, and press Enter. This will display the imported MySQL database tables.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.