Skip to content

Instantly share code, notes, and snippets.

@djamol
Created May 19, 2018 18:33
Show Gist options
  • Save djamol/0e23a195c7f88770b2b15e83b5bde68b to your computer and use it in GitHub Desktop.
Save djamol/0e23a195c7f88770b2b15e83b5bde68b to your computer and use it in GitHub Desktop.
Backup DATABASE And Restore Database
#Structure With Data Backup
DATABASE_LIST=$(mysql -NBe 'show schemas' | grep -wv 'mysql\|personnel\|buildings\|information_schema\|performance_schema');echo $DATABASE_LIST;mysqldump --databases $DATABASE_LIST > bk.sql
#Structure only backup
DATABASE_LIST=$(mysql -NBe 'show schemas' | grep -wv 'mysql\|personnel\|buildings\|information_schema\|performance_schema');echo $DATABASE_LIST;mysqldump --no-data --databases $DATABASE_LIST > structure.sql
#Restore/Install/Dump sql file
mysql -uroot -p < database_backup.sql
#Dump table backup in gz file
mysqldump db_name table_name | gzip > table_name.sql.gz
#Restore table from gz file
gunzip < table_name.sql.gz | mysql -u username -p db_name
#Drop (i.e. remove tables)
mysql -Nse 'show tables' DATABASE_NAME | while read table; do mysql -e "drop table $table" DATABASE_NAME; done
#Truncate (i.e. empty tables)
mysql -Nse 'show tables' DATABASE_NAME | while read table; do mysql -e "truncate table $table" DATABASE_NAME; done
#Restore Database
Shell> mysql -u root -p < schema.sql
# SQL Commands
#//delete all records/row
# DELETE FROM `table`
#//null value delete rows only example
# DELETE FROM `table` WHERE `gmc` ='null';
# For currently connection working in time mysql con. list show
#show full processlist;
#Find in Files String in( Directory,subdirectory all files )
cd /home/directoy; grep -nr 'yourString*'
grep -r --include=.txt 'searchterm' ./ ...or case-insensitive version...
grep -r -i --include=.txt 'searchterm' ./ // /home/directory location directory, find string,word yourString* (* means after yourString any thing word character)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment