How to Export & Import mysql Database from Command Line

Browse My Free Website Guides
How to Export & Import mysql Database from Command Line

I was recently working on creating a local instance of a WordPress site and was using Wamp. When I was importing the database it was throwing an error (mysql error 2006 mysql server has gone away) because the packet size was too large. I used the command line to import the database and increase the packet size.

# navigate to your mysql location
cd C:\wamp\bin\mysql\mysql5.7.24\bin

# run mysql
mysql -u root -p

# Show your database
show databases;

# Open a database
use dbname;

# Show the tables inside a database
show tables;

# Show the columns inside a table
show columns;

# export database
mysqldump -u root -p dbname "C:\Users\yourusername\Downloads\dbexport.sql"

# import database and increase packet size
mysql -u root -p --max_allowed_packet=1073741824 dbname < "C:\Users\yourusername\Desktop\dbimport.sql"

# clear commands
\c

# create a database
CREATE DATABASE `project-name`;

Related resources

  • HubSpot CMS vs WordPress: Feature Comparison and Review
  • 25+ Questions to Ask Before Redesigning Your Business Website
  • 5 Things A Business Should Consider Before a Website Redesign
  • How to Get a Responsive Website for Your Manufacturing Company
  • What Is a Good WordPress Alternative for Businesses?
  • Tags: ,

    Want to Get Email Updates of New Posts? Join My Email Newsletter