Is it possible to somehow get structure of MySQL database, or just some table with simple query?
Or is there another way, how can I do it?
Is it possible to somehow get structure of MySQL database, or just some table with simple query?
Or is there another way, how can I do it?
using this:
SHOW CREATE TABLE `users`;
will give you the DDL for that table
DESCRIBE `users`
will list the columns in that table
I think
DESCRIBE table;
is what you're after. You can also use
SHOW TABLES;
to get a list of the tables in your database.
That's the SHOW CREATE TABLE query. You can query the SCHEMA TABLES, too.
SHOW CREATE TABLE YourTableName;
Take a look at the information_schema
.tables
table. It contains metadata about all your tables.
example:
select * from `information_schema`.`tables`
where table_name like 'table1'
The advantage of this over other methods is that you can easily use queries like the one above as subqueries in your other queries.
To get the whole database structure as a set of CREATE TABLE statements, use mysqldump:
mysqldump database_name --compact --no-data
For single tables, add the table name after db name in mysqldump. You get the same results with SQL and SHOW CREATE TABLE:
SHOW CREATE TABLE table;
Or DESCRIBE if you prefer a column listing:
DESCRIBE table;