forked from mysql/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup_tables_priv_and_users.inc
38 lines (33 loc) · 1.06 KB
/
backup_tables_priv_and_users.inc
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
# ==== Purpose ====
#
# To backup/restore contents of the tables: mysql.tables_priv and mysql.user
#
# ==== Usage ====
#
# # Backup mysql.user & mysql.tables_priv tables
# --let $backup=1
# --source include/backup_tables_priv_users.inc
#
# # Restore mysql.user & mysql.tables_priv from backup
# --let $restore=1
# --source include/backup_tables_priv_users.inc
if ($backup)
{
# Save a copy of the user/tables_priv tables, to restore later
CREATE TEMPORARY TABLE tmp_backup_tables_priv AS SELECT * FROM mysql.tables_priv;
CREATE TEMPORARY TABLE tmp_backup_user AS SELECT * FROM mysql.user;
# Reset the backup flag
--let $backup= 0;
}
if ($restore)
{
# Restore the saved contents of mysql.tables_priv and mysql.user
TRUNCATE TABLE mysql.tables_priv;
INSERT INTO mysql.tables_priv (SELECT * FROM tmp_backup_tables_priv);
DROP TEMPORARY TABLE tmp_backup_tables_priv;
TRUNCATE TABLE mysql.user;
INSERT INTO mysql.user (SELECT * FROM tmp_backup_user);
DROP TEMPORARY TABLE tmp_backup_user;
# Reset the restore flag
--let $restore= 0;
}