Copy mysql schema to new database
I recently wanted to test changing database character-encoding settings on a production RDS database, so I created a new local database mimicking the schema of my production database. The two-step process made it easy to tear down and recreate as I tuned my migration script.
All commands are executed on your local machine.
mysqldump -u my_username -pmy_password -h my_host -P my_port -d my_database > dbschema.sql
mysql -u root -e "create database encoding_test"
mysql -u root encoding_test < dbschema.sql
At this point, run any schema-modifying scripts you wish against your local database (encoding_test
, in my case).
To start over:
mysql -u root -e "drop database encoding_test"
mysql -u root -e "create database encoding_test"
mysql -u root encoding_test < dbschema.sql
The -d
in the mysqldump
command is critical - it tells the process to exclude data and only dump the schema.
Written by Steve McHail
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mysql
Authors
Related Tags
#mysql
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#