Skip to content

Instantly share code, notes, and snippets.

@brihter
Last active December 19, 2015 21:09
Show Gist options
  • Save brihter/6018595 to your computer and use it in GitHub Desktop.
Save brihter/6018595 to your computer and use it in GitHub Desktop.
MySQL maintenance snippets
##########
# EXPORT #
##########
# export db (schema only)
mysqldump -u username -ppassword --no-data --add-drop-database --databases db > db.sql
# export db
mysqldump -u username -ppassword --add-drop-database --databases db > db.sql
# export table
mysqldump -u username -ppassword db table > table.sql
# export table (bulk file)
mysqldump -u username -ppassword db table --fields-terminated-by=, --skip-add-drop-table --skip-add-locks --skip-quote-names --no-create-info -T PATH_TO_EXPORT_FOLDER
##########
# IMPORT #
##########
# import db or table
mysql -u username -ppassword db < file.sql
# disable keys
alter table `table` disable keys;
# import table from bulk file
mysqlimport -u username -ppassword db PATH_TO_FOLDER\table.txt --fields-terminated-by=, -f
# fast index rebuild
mysqlcheck -u username -ppassword -q db table
# enable keys
alter table `table` enable keys;
###############
# PERMISSIONS #
###############
# grant remote access to any host
grant all privileges on db.* to ‘username’@'%' identified by 'password';
# grant remote access to a specific host
grant all privileges on db.* to ‘username’@'IP_ADDRESS' identified by 'password';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment