How to Export & Import mysql Database from Command Line


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:wampbinmysqlmysql5.7.24bin

# 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:UsersyourusernameDownloadsdbexport.sql"

# import database and increase packet size
mysql -u root -p --max_allowed_packet=1073741824 dbname < "C:UsersyourusernameDesktopdbimport.sql"

# clear commands
c

# 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.

Topic:

Related posts

Tags: ,

Want to Get Email Updates of New Articles?

Join My Email Newsletter