14

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.

waiwai933
  • 14,133
  • 21
  • 62
  • 86

4 Answers4

20

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
Sol
  • 985
  • 2
  • 10
  • 20
15

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.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
6

How about using mysqldump?

mysqldump -u root -p[password] [db_name] > backupfile.sql
Milind Ganjoo
  • 1,260
  • 11
  • 13
-1

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

SHOW TABLES FROM MY_DATABASE;
Vipul Verma
  • 115
  • 1
  • 7
  • 1
    This question is specifically about getting the schemas (think "create table" output) of all of the tables. Not simply listing the tables. – erik.weathers May 26 '22 at 09:00