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

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

how to add multiple select in laravel eloquent ?

December 29, 2021February 22, 2024

Laravel eloquent builder has rich features to modify the query. In some cases we wanted to add multiple select in laravel and modify the select statement on basis of few conditions and wanted to add some select statement on condition. so in this article we will learn to add multiple…

Read More
Laravel Create database connection in laravel

How to make database connection in Laravel 8 ?

December 14, 2021February 22, 2024

Laravel comes with first party support for several database drivers. Laravel gives much better flexibility in terms of using the RDBMS based databases. Laravel supports MySQL, PostgreSQL, SQLite and SQL Server by default but if you want to make connection with Mongo or other database then you need to install…

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

  • 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

  • Understanding High Vulnerabilities: A Deep Dive into Recent Security Concerns
  • Understanding High Vulnerabilities in Software: A Week of Insights
  • Blocking Spam Requests with LaraGuard IP: A Comprehensive Guide
  • Enhancing API Development with Laravel API Kit
  • Exploring the Future of Web Development: Insights from Milana Cap
©2023 Readerstacks | Design and Developed by Readerstacks
Go to mobile version