How to Export & Import mysql Database from Command Line

Download FREE Marketing 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

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

Written by: Jake Lett
I share digital marketing tips and HubSpot tutorials to help marketers and business owners grow their business.

Related posts

Tags: ,

Want to Get Email Updates of New Articles?

Join My Email Newsletter