waiwai933
waiwai933

Reputation: 14559

Getting MySQL Schemas for All Tables

I want to download/backup the schema of an entire MySQL database. Is there a way to easily do this? I haven't had much luck using a wildcard, but that could be an error on my part.

Upvotes: 16

Views: 41071

Answers (4)

Vipul Verma
Vipul Verma

Reputation: 123

If you want to see all the tables from a schema in MySQL then you can use

SHOW TABLES FROM MY_DATABASE;

Upvotes: -1

Sol
Sol

Reputation: 1005

I would use the --no-data option to mysqldump to dump the schema and not table data.

 mysqldump --no-data [db_name] -u[user] -p[password] > schemafile.sql

Upvotes: 20

Jim Garrison
Jim Garrison

Reputation: 86754

Login as root, then

show databases; # lists all databases
use information_schema; # connect to the mysql schema
show tables;   
select * from tables;

Everything you need is in the information_schema schema. If all you want to do is backup the db, use the builtin dump/restore capabilities.

Upvotes: 18

Milind Ganjoo
Milind Ganjoo

Reputation: 1280

How about using mysqldump?

mysqldump -u root -p[password] [db_name] > backupfile.sql

Upvotes: 6

Related Questions