Last active
December 19, 2015 21:09
-
-
Save brihter/6018595 to your computer and use it in GitHub Desktop.
MySQL maintenance snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########## | |
# 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