Skip to content
Readerstacks logo Readerstacks
  • Home
  • Softwares
  • Angular
  • Php
  • Laravel
  • Flutter
Readerstacks logo
Readerstacks

How to Import mysql database using command line?

Aman Jain, August 24, 2021February 22, 2024

Mysql has rich features for users like they can easily import and export database, create table, relations, store procedures, triggers etc.

In the same way mysql has own command to import and export the mysql database.

  1. First find the mysql executable.
    you can open the terminal in ubuntu/Mac or command line in windows to check whether mysql is installed globally or not.

    mysql --version

    Output:

    mysql  Ver 8.0.19 for macos10.15 on x86_64 (MySQL Community Server - GPL)

    if the output is same as above then it’s installed globally. If the output is not as above then you need to find the installed mysql version and executable file.

    Steps to find mysql executable in ubuntu

    1. Install mysql-client

    sudo apt-get install mysql-client

    Steps to find mysql executable in windows

    1. Go to the folder of wamp/wamp

    E:\wamp\bin\mysql\

    and run the terminal in the folder.
  2. for Import database type in terminal

    mysql -u username -p database_name < path_of_sql_file

    Example:

    mysql -u root -p test < /var/www/html/test.sql
  3. For export database

    mysql -u username -p database_name > path_to_sql_file

    Example:

    mysql -u root -p test > /var/www/html/test.sql


    If you are getting errors while importing like

    mysql foreign key constraint error

    then you can find the line no. and remove that

    OR

    You can Disable foreign key checks in command line

    mysql --init-command="SET SESSION FOREIGN_KEY_CHECKS=0;"  -u root -p test < /var/www/html/test.sql

    Still getting errors?

    you can force mysql command to import with errors with option —force or -f

    mysql --init-command="SET SESSION FOREIGN_KEY_CHECKS=0;"  -u root -p -f test < /var/www/html/test.sql

Let’s start with quick easy steps:

Related

Mysql

Post navigation

Previous post
Next post

Related Posts

Mysql Mysql insert select

Mastering MySQL Insert-Select: Simplify Data Manipulation Efforts

July 4, 2023March 16, 2024

In the world of database management systems, MySQL Insert Select is fastest tool to imports data from one table to another. MySQL has emerged as one of the most popular choices due to its reliability, performance, and ease of use. One of the powerful features it offers is the ability…

Read More

How to install MySQL in Ubuntu?

September 18, 2021September 18, 2021

MySQL is a most popular and open source relational database. it provides multi user support with a many storage engines. in this tutorial we are going to install MySQL in Ubuntu. Let’s begin with simple steps: Step 1 : Open terminal in Ubuntu and install MySQL package Here, we are…

Read More
Ubuntu How to Reset Root Password of MySQL 8 in Ubuntu 20.04

How to Reset Root Password of MySQL 8 in Ubuntu 20.04 ?

June 1, 2022June 1, 2022

Sometimes we forget or mistakenly type wrong password during the installation of mysql, So in this article i will help you to Reset Root Password of MySQL in Ubuntu 20.04. Mysql 8 has several new features and also it has change the default password algorithm for saving the password. Mysql…

Read More

Aman Jain
Aman Jain

With years of hands-on experience in the realm of web and mobile development, they have honed their skills in various technologies, including Laravel, PHP CodeIgniter, mobile app development, web app development, Flutter, React, JavaScript, Angular, Devops and so much more. Their proficiency extends to building robust REST APIs, AWS Code scaling, and optimization, ensuring that your applications run seamlessly on the cloud.

Categories

  • Angular
  • CSS
  • Dart
  • Devops
  • Flutter
  • HTML
  • Javascript
  • jQuery
  • Laravel
  • Laravel 10
  • Laravel 11
  • Laravel 9
  • Mysql
  • Php
  • Softwares
  • Ubuntu
  • Uncategorized

Archives

  • June 2025
  • May 2025
  • April 2025
  • October 2024
  • July 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • July 2023
  • March 2023
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021

Recent Posts

  • The Resilience of Nature: How Forests Recover After Fires
  • Understanding Laravel Cookie Consent for GDPR Compliance
  • Understanding High Vulnerabilities: A Critical Overview of the Week of May 12, 2025
  • Installing a LAMP Stack on Ubuntu: A Comprehensive Guide
  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version