Skip to content

Instantly share code, notes, and snippets.

@meleyal
Created March 30, 2009 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meleyal/87820 to your computer and use it in GitHub Desktop.
Save meleyal/87820 to your computer and use it in GitHub Desktop.
MySQL recipes
#login
mysql -u <user> -p
# list all databases
show databases;
# 'open' a database
use <database_name>;
# list all tables
show tables;
# list table schema
describe <table_name>;
# show table content (with human-friendly formatting)
select * from <table_name> \G
# ditto, but set a limit
select * from <table_name> limit 1 \G
# delete all tables
mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data [DATABASE] | grep ^DROP | mysql -u[USERNAME] -p[PASSWORD] [DATABASE]
# export a dump file
mysqldump <database_name> > file.sql
# export a dump file from another db server
mysqldump -u <user> -p -h <server> <database_name> > file.sql
# import a dump file
mysql -u <user> -p <database_name> < file.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment