How to Import Database in Mysql Command Line Ubuntu

How to Import Database in Mysql Command Line Ubuntu

To import a database from a SQL dump file in MySQL server, you have to login into MySQL server, which you can do with the help of mysql -u -p command, and now you have to use SOURCE /path/to/file.sql command on the ubuntu command line to import the database into MySQL server, It will import the database into MySQL.

Here are steps on how to import database SQL dump file in MySQL command line ubuntu:

Step 1: Connect to MySQL Server

To login into your MySQL server, you need to type the command mysql -u <username> -p on the command line, press Enter:

mysql -u <username> -p

Replace <username> with your MySQL username. You will be prompted to enter your MySQL password after running this command. Enter your password and press Enter.

Step 2: Create a New Database

If you already have a database in which you want to import SQL database dump file, skip this step, Otherwise, You type CREATE DATABASE <database_name> command on the command line and press Enter, so that a new database is created, In which you can import database from the SQL dump file in mysql:

CREATE DATABASE <database_name>;

Replace with the DB name, want to create new database.

Step 3: Select the Database

To select the database, type USE <database_name>; command on the command line, so that import the database from SQL dump file:

USE <database_name>;

Replace <database_name> with the name of the database you just created or the one you want to import the SQL file into.

Step 4: Import SQL Database Dump File to MySQL in Command Line Ubuntu

To import database from SQL dump file in MySQL, Type SOURCE /path/to/file.sql command on ubuntu command line, and press enter, it will be import db in just few seconds:

SOURCE /path/to/file.sql;

In the command, replace /path/to/file.sql with where your SQL file is stored.

Note: Make sure that the SQL file is in a location that is accessible from the MySQL server. If the SQL file is on your local machine, you may need to transfer it to the server using a file transfer protocol such as FTP or SCP.

Step 5: Verify the Import

To verify that the database was imported successfully, just type SELECT * FROM <table_name>; command on command line and enter press:

SELECT * FROM <table_name>;

Replace <table_name> with the name of the table you want to verify.

Here is the video guide on how to import database from SQL file in MySQL command line:

Conclusion

That’s it; In this tutorial, you have learned how to import an database from SQL dump file using the command line in MySQL with ubuntu server.

Recommended Tutorials

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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