Spread the love

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


    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


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

    mysql -u username -p database_name < path_of_sql_file


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

    mysql -u username -p database_name > path_to_sql_file


    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


    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:

Leave a Reply