How To Import SQL File Into MySQL Using Command

Websolutionstuff | Nov-10-2022 | Categories : MySQL

In this article, we will see how to import SQL files into MySQL using the command. You can import databases in multiple ways on different types of servers. We will import the SQL file in xampp PHPMyAdmin using the command line. You can directly import the database in PHPMyAdmin. Using the command line you can import large-size databases.

So, let's see how to import the SQL files in PHPMyAdmin using the command line and command line to import the database in MySQL.

Syntax:

mysql -u username -p database_name < file.sql

 

  1. Open XAMPP.
  2. Start Apache Server and MySQL Database.
  3. Create a database via phpMyAdmin.
  4. Open Command Prompt
  5. Go to the SQL file path. Example: if your .sql file is located in the download folder then e.g Go to C:\Users\Websolutionstuff\Downloads.
  6. Type: mysql -u username -p database_name < file.sql
  7. The username refers to your MySQL username.
  8. database_name refers to the database you want to import.
  9. file.sql is your file name.
  10. If you've assigned a password, type it now and press Enter.

 

Example:

In this example, we will import backup_database_file.sql into the new_database_example database in PHPMyAdmin. 

mysql -u root -p new_database_example < backup_databse_file.sql

 

 

Export MySQL or MariaDB Database

In this example, we will export the mysqldump console utility exports databases to SQL text files. This makes it easier to transfer and move databases. You will need your database’s name and credentials for an account whose privileges allow at least full read-only access to the database.

Use mysqldump to export your database:

mysqldump -u username -p database_name > file.sql

 

  • The username refers to your MySQL database username.
  • The database_name refers to the database you want to export.
  • file.sql is your file name.

 

Example:

In this example, we will export tutorial_database with the backup_file.sql file.

mysqldump -u root -p tutorial_database > backup_file.sql

 


You might also like:

Recommended Post
Featured Post
How To Add Toastr Notification In Laravel
How To Add Toastr Notification...

In this tutorial, I will show you how to add toastr notification in laravel application. There are many types of no...

Read More

May-29-2020

How To Two Factor Authentication Using Email In Laravel 10
How To Two Factor Authenticati...

In this article, we will see how to two-factor authentication using email in laravel 10. Here, we will learn about...

Read More

Apr-14-2023

Laravel 10 Multiple Image Upload Example
Laravel 10 Multiple Image Uplo...

In this article, we will see laravel 10 multiple image examples. Here, we will learn about how to upload multiple i...

Read More

Mar-17-2023

How To Use Image Intervention In Laravel 9
How To Use Image Intervention...

In this article, we will see how to use image intervention in laravel 9. Here, we will learn about image intervention an...

Read More

Feb-13-2023