How to import SQL file to MySQL using Command Line - TechvBlogs

How to import SQL file to MySQL using Command Line

In this article, I'll give you a detailed tutorial on importing SQL files through the command-line interface. You will discover how to accomplish this by utilizing the online MySQL server, the provided shell, the offline WAMP and XAMPP servers, and other tools.


Suresh Ramani - Author - TechvBlogs
Suresh Ramani
 

1 year ago

TechvBlogs - Google News

Importing database tables or updating data with SQL queries are regular operations in software development. Through the use of data dumps, which are SQL queries stored inside of files, the structure or records can be modified. Additionally, they can be used to transfer data to an alternative server or testing environment.

In this article, I'll give you a detailed tutorial on importing SQL files through the command-line interface. You will discover how to accomplish this by utilizing the online MySQL server, the provided shell, the offline WAMP and XAMPP servers, and other tools.

How to import SQL files to MySQL using Command Line

In this article, We will cover 3 topics for importing SQL files into MySQL.

  1. Import SQL Files Using MySQL using Command Line
  2. Import SQL Files Using WAMP MySQL using Command Line
  3. Import SQL Files Using XAMPP MySQL using Command Line

1. Import SQL Files Using MySQL using Command Line

You may manage your databases by utilizing a series of commands through a shell if you use any web hostings services like VPS, Cloud Hosting, or Dedicated Hosting.

Use the following command to import any accessible SQL queries from a file you may have.

mysql -u username -p database_name < path_to_mysql_file.sql
  • username, replace it with the name you use to log in to your database.
  • database_name, replace it with the name of the target database where you want to import the SQL dump.
  • path_to_mysql_file.sql, replace it with the complete path to the SQL dump file to be imported.
    e.g: /home/techvblogs/downloads/users.sql

If the command runs successfully, it won’t display any output in the CLI. If any errors occur during the import process, MySQL will display them in the Command Prompt.

2. Import SQL Files Using WAMP MySQL using Command Line

Follow the steps below if you're using the WAMP offline server.

  1. Launch the WAMP server.
  2. Select the WAMP icon from the taskbar by left-clicking.
  3. See the "MySQL" link found in the "Default DBMS: MySQL" Section.
  4. You can see the version of MySQL you are currently using on the right.

To import the SQL file into the database, open a command prompt and type the following command:

C:\wamp64\bin\mysql\mysql8.0.30\bin\mysql -u username -p database_name < path_to_mysql_file.sql
  • mysql8.0.30, replace it with your MySQL version number.
  • username, replace it with the name you use to log in to your database.
  • database_name, replace it with the name of the target database where you want to import the SQL dump.
  • path_to_mysql_file.sql, replace it with the complete path to the SQL dump file to be imported.
    e.g: /home/techvblogs/downloads/users.sql

3. Import SQL Files Using XAMPP MySQL using Command Line

To import the SQL file into the database when using the XAMPP offline server, launch the command prompt and enter the following command:

C:\xampp\mysql\bin>mysql -u username -p database_name < path_to_mysql_file.sql
  • username, replace it with the name you use to log in to your database.
  • database_name, replace it with the name of the target database where you want to import the SQL dump.
  • path_to_mysql_file.sql, replace it with the complete path to the SQL dump file to be imported.
    e.g: /home/techvblogs/downloads/users.sql

You have finished learning how to import SQL files using different environments' command-line interfaces.

Thank you for reading this blog.

Read Also: How To Install PHP 8.2 on Ubuntu 22.04

If you want to manage your VPS / VM Server without touching the command line go and  Checkout this linkServerAvatar allows you to quickly set up WordPress or Custom PHP websites on VPS / VM in a  matter of minutes.  You can host multiple websites on a single VPS / VM, configure SSL certificates, and monitor the health of your server without ever touching the command line interface.

If you have any queries or doubts about this topic please feel free to contact us. We will try to reach you.

Comments (0)

Comment


Note: All Input Fields are required.