-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_backup.sh
41 lines (21 loc) · 1.2 KB
/
database_backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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
# 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;