首页 > 数据库 > MySQL > 阿里云 Mysql RDS 在 私有环境的恢复测试。
阿里云 RDS 做一定的技术屏蔽,这是必须的。
那么从阿里云 下载一个备份集, 是否可以顺利的恢复成一个数据库实例, 是一件技术活。
我们做了一个测试。
下载一个 RDS 实例备份。
一般后缀为 “xb”
第一步:
需要安装解压软件:
安装 qpress
安装 xtrabackup
cat data_20221019045743_qp.xb | xbstream -x -v -C /usr/local/mysql/data_common_xtrabackup
innobackupex --decompress --remove-original /usr/local/mysql/data_common_xtrabackup
innobackupex --default-files=/usr/local/mysql/data_common_xtrabackup/backup-my.cnf --apply-log /usr/local/mysql/data_common_xtrabackup
第二步:
把 backup-my.cnf
innodb_log_files_in_group=2
innodb_log_file_size=1572864000
innodb_log_buffer_size=8388608
innodb_page_size=16384
innodb_undo_tablespaces=2
这几个参数放到我们自己的参数文件里面 不同 RDS 肯能参数值不一样, 自己搞定就行了。
第三步: 启动没问题。 但是发现权限不够啊。 没有root 。
关闭数据库会成为问题。 需要修复。
第四步: 启动参数加 skip-grant-tables 用root 可以登录了。
添加root 用户吧。
mysql> update mysql.user set authentication_string = password('新的密码') where user='用户名' and host='%';
修改用户密码,报错“Unknown trigger has an error in its body: ‘Unknown system variable ‘maintain_user”
报错。 无法执行。
第五步: mysql 库下面有两个trigger 坐在数据库级别上。 先在数据库目录里面, 把这俩trigger 的文件名改了。
mv 命令直接改。
第六步: 再修改 用户名密码:
mysql> update mysql.user set authentication_string = password('新的密码') where user='用户名' and host='%';
ERROR 1064 (42000): Unknown trigger has an error in its body: 'Unknown system variable 'maintain_user_list''
报错,但是可以改了。
添加用户, 权限。
然后就可以愉快的测试了。
第七步: 如果要做slave 同步 RDS 可以 开始搭建 slave GTID 相关的动作了。 这里不表。
第八步: 总结:
把 backup-my.cnf
innodb_log_files_in_group=2
innodb_log_file_size=1572864000
innodb_log_buffer_size=8388608
innodb_page_size=16384
innodb_undo_tablespaces=2
这几个参数放到我们的参数文件里面
然加
--skip-grant-tables
恢复目录里面 将2个 user.TRG proxies_priv.TRG 先重命名
然后启动
然后修改user 表 ,把 aliyun_root 那个修改成 root localhost 以及我们自己的密码。
退出去掉
--skip-grant-tables
重启。
再做set gtid_pureged
第九步:
trigger :
proxies_priv.TRG
TYPE=TRIGGERS triggers='CREATE DEFINER=`aliyun_root`@`127.0.0.1` trigger protect_aliroot_insert_proxy before insert on mysql.proxies_priv for each row begin select user() into @current_user_host; select reverse(substring_index(reverse(@current_user_host), \'@\', -1)) into @current_user; select @@global.maintain_user_list into @maintain_list; set @cnt= 1 + LENGTH(@maintain_list) - LENGTH(REPLACE(@maintain_list, \',\', \'\')); SET @i=1 ; SET @allowed=0; WHILE @i <= @cnt DO SET @result = REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(@maintain_list,\',\',@i)),\',\',1)); SET @i= @i + 1; if @result=@current_user then SET @allowed=1; end if; end while; if @allowed=0 then signal sqlstate \'45003\' set message_text = \'can not modify mysql.proxies_priv\'; end if; end' 'CREATE DEFINER=`aliyun_root`@`127.0.0.1` trigger protect_aliroot_update_proxy before update on mysql.proxies_priv for each row begin select user() into @current_user_host; select reverse(substring_index(reverse(@current_user_host), \'@\', -1)) into @current_user; select @@global.maintain_user_list into @maintain_list; set @cnt= 1 + LENGTH(@maintain_list) - LENGTH(REPLACE(@maintain_list, \',\', \'\')); SET @i=1 ; SET @allowed=0; WHILE @i <= @cnt DO SET @result = REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(@maintain_list,\',\',@i)),\',\',1)); SET @i= @i + 1; if @result=@current_user then SET @allowed=1; end if; end while; if @allowed=0 then signal sqlstate \'45003\' set message_text = \'can not modify mysql.proxies_priv\'; end if; end' 'CREATE DEFINER=`aliyun_root`@`127.0.0.1` trigger protect_aliroot_delete_proxy before delete on mysql.proxies_priv for each row begin select user() into @current_user_host; select reverse(substring_index(reverse(@current_user_host), \'@\', -1)) into @current_user; select @@global.maintain_user_list into @maintain_list; set @cnt= 1 + LENGTH(@maintain_list) - LENGTH(REPLACE(@maintain_list, \',\', \'\')); SET @i=1 ; SET @allowed=0; WHILE @i <= @cnt DO SET @result = REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(@maintain_list,\',\',@i)),\',\',1)); SET @i= @i + 1; if @result=@current_user then SET @allowed=1; end if; end while; if @allowed=0 then signal sqlstate \'45003\' set message_text = \'can not modify mysql.proxies_priv\'; end if; end' sql_modes=0 0 0 definers='aliyun_root@127.0.0.1' 'aliyun_root@127.0.0.1' 'aliyun_root@127.0.0.1' client_cs_names='utf8' 'utf8' 'utf8' connection_cl_names='utf8_general_ci' 'utf8_general_ci' 'utf8_general_ci' db_cl_names='utf8_general_ci' 'utf8_general_ci' 'utf8_general_ci' created=165113905344 165113905344 165113905344
user.TRG:
TYPE=TRIGGERS triggers='CREATE DEFINER=`aliyun_root`@`127.0.0.1` trigger protect_aliroot_insert before insert on mysql.user for each row begin select user() into @current_user_host; select reverse(substring_index(reverse(@current_user_host), \'@\', -1)) into @current_user; select @@global.maintain_user_list into @maintain_list; set @cnt= 1 + LENGTH(@maintain_list) - LENGTH(REPLACE(@maintain_list, \',\', \'\')); SET @i=1 ; SET @allowed=0; SET @modify_maintain=0; WHILE @i <= @cnt DO SET @result = REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(@maintain_list,\',\',@i)),\',\',1)); SET @i= @i + 1; if @result=@current_user then SET @allowed=1; end if; if @result=new.user then SET @modify_maintain=1; end if; end while; if (\'Y\' = new.Shutdown_priv or \'Y\' = new.Show_db_priv or \'Y\' = new.Super_priv or \'Y\' = new.Create_tablespace_priv or \'Y\' = new.File_priv) then SET @modify_maintain=1; end if; if @allowed=0 and @modify_maintain=1 then signal sqlstate \'45002\' set message_text = \'can not insert reserved users or privileges\'; end if; end' 'CREATE DEFINER=`aliyun_root`@`127.0.0.1` trigger protect_aliroot_update before update on mysql.user for each row begin select user() into @current_user_host; select reverse(substring_index(reverse(@current_user_host), \'@\', -1)) into @current_user; select @@global.maintain_user_list into @maintain_list; set @cnt= 1 + LENGTH(@maintain_list) - LENGTH(REPLACE(@maintain_list, \',\', \'\')); SET @i=1 ; SET @allowed=0; SET @modify_maintain=0; WHILE @i <= @cnt DO SET @result = REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(@maintain_list,\',\',@i)),\',\',1)); SET @i= @i + 1; if @result=@current_user then SET @allowed=1; end if; if @result=new.user or @result=old.user then SET @modify_maintain=1; end if; end while; if (old.Shutdown_priv <> new.Shutdown_priv or old.Show_db_priv <> new.Show_db_priv or old.Super_priv <> new.Super_priv or old.Create_tablespace_priv <> new.Create_tablespace_priv or old.File_priv <> new.File_priv ) then SET @modify_maintain=1; end if; if @allowed=0 and @modify_maintain=1 then signal sqlstate \'45001\' set message_text = \'can not update reserved users or privileges\'; end if; end' 'CREATE DEFINER=`aliyun_root`@`127.0.0.1` trigger protect_aliroot_delete before delete on mysql.user for each row begin select user() into @current_user_host; select reverse(substring_index(reverse(@current_user_host), \'@\', -1)) into @current_user; select @@global.maintain_user_list into @maintain_list; set @cnt= 1 + LENGTH(@maintain_list) - LENGTH(REPLACE(@maintain_list, \',\', \'\')); SET @i=1 ; SET @allowed=0; SET @modify_maintain=0; WHILE @i <= @cnt DO SET @result = REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(@maintain_list,\',\',@i)),\',\',1)); SET @i= @i + 1; if @result=@current_user then SET @allowed=1; end if; if @result=old.user then SET @modify_maintain=1; end if; end while; if @allowed=0 and @modify_maintain=1 then signal sqlstate \'45000\' set message_text = \'can not delete reserved users or privileges\'; end if; end' sql_modes=0 0 0 definers='aliyun_root@127.0.0.1' 'aliyun_root@127.0.0.1' 'aliyun_root@127.0.0.1' client_cs_names='utf8' 'utf8' 'utf8' connection_cl_names='utf8_general_ci' 'utf8_general_ci' 'utf8_general_ci' db_cl_names='utf8_general_ci' 'utf8_general_ci' 'utf8_general_ci' created=165113905344 165113905344 165113905344
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/133735/viewspace-2919163/ ,如需转载,请注明出处,否则将追究法律责任。