博客如何导出指定租户的用户和权限
如何导出指定租户的用户和权限-c7电子娱乐
2 天前运维管理
问题背景
之前在做mysql运维的时候,经常会用到pt的工具,ob兼容mysql,避免重复造轮子自己写脚本实现,这里主要是记录一下,方便读者参考。
1、下载 percona-toolkit 软件包
这里按照我们自己的环境操作系统,选择一个版本,本次使用当前最新的 percona-toolkit-3.7.0 版本。
2、上传并解压
tar -zxvf percona-toolkit-3.7.0_x86_64.tar.gz
[heshun.lxd@191--2025-01-16 19:31:34 ~/percona-toolkit-3.7.0/bin]$ pwd
/home/heshun.lxd/percona-toolkit-3.7.0/bin
[heshun.lxd@191--2025-01-16 19:44:43 ~/percona-toolkit-3.7.0/bin]$ ls -l pt-show-grants
-rwxr-xr-x 1 heshun.lxd users 82628 dec 20 17:51 pt-show-grants
[heshun.lxd@191--2025-01-16 19:44:59 ~/percona-toolkit-3.7.0/bin]$
3、安装依赖包
按照自己的操作系统类型安装对应的 依赖包
cannot connect to mysql because the perl dbi module is not installed or not found. run 'perl -mdbi' to see the directories that perl searches for dbi. if dbi is not installed, try:
debian/ubuntu apt-get install libdbi-perl
rhel/centos yum install perl-dbi
opensolaris pkg install pkg:/sunwpmdbi
cannot connect to mysql because the perl dbd::mysql module is not installed or not found. run 'perl -mdbd::mysql' to see the directories that perl searches for dbd::mysql. if dbd::mysql is not installed, try:
debian/ubuntu apt-get install libdbd-mysql-perl
rhel/centos yum install perl-dbd-mysql
opensolaris pkg install pkg:/sunwapu13dbd-mysql
4、执行pt-show-grants 命令
参考:
[heshun.lxd@191--2025-01-16 19:47:17 ~/percona-toolkit-3.7.0/bin]$ ./pt-show-grants \
> --host=11.xxx.xxx.192 \
> --port=2883 \
> --user=root@test1 \
> --password='xxxxxx'
-- grants dumped by pt-show-grants
-- dumped from server 11.xxx.xxx.192 via tcp/ip, mysql 5.7.25-oceanbase_ce-v4.3.4.0 at 2025-01-16 19:47:26
-- grants for 'root'@'%'
create user if not exists `root`@`%`;
create user if not exists `root`@`%` identified by password '*163cdf0523fe841232f8ce42a663f21e0f354dd1';
grant all privileges on *.* to 'root' with grant option;
grant all privileges on `__public`.* to 'root';
grant all privileges on `__recyclebin`.* to 'root';
grant all privileges on `information_schema`.* to 'root';
grant all privileges on `mysql`.* to 'root';
grant all privileges on `oceanbase`.* to 'root';
grant all privileges on `test`.* to 'root';
grant execute, alter routine on procedure `test`.`insertnumbers` to 'root';
-- grants for 'user_a'@'10.10.10.10'
create user if not exists `user_a`@`10.10.10.10`;
create user if not exists `user_a`@`10.10.10.10` identified by password '*163cdf0523fe841232f8ce42a663f21e0f354dd1';
grant all privileges on *.* to 'user_a'@'10.10.10.10';
-- grants for 'user_b'@'10.10.10.10'
create user if not exists `user_b`@`10.10.10.10`;
create user if not exists `user_b`@`10.10.10.10` identified by password '*163cdf0523fe841232f8ce42a663f21e0f354dd1';
grant usage on *.* to 'user_b'@'10.10.10.10';
5、验证
mysql [mysql]> show tenant;
---------------------
| current_tenant_name |
---------------------
| test1 |
---------------------
1 row in set (0.08 sec)
mysql [mysql]> select user,host,password from mysql.user ;
-------- ------------- -------------------------------------------
| user | host | password |
-------- ------------- -------------------------------------------
| root | % | *163cdf0523fe841232f8ce42a663f21e0f354dd1 |
| user_a | 10.10.10.10 | *163cdf0523fe841232f8ce42a663f21e0f354dd1 |
| user_b | 10.10.10.10 | *163cdf0523fe841232f8ce42a663f21e0f354dd1 |
-------- ------------- -------------------------------------------
3 rows in set (0.26 sec)
mysql [mysql]> show grants for root@'%';
----------------------------------------------------------------------------
| grants for root@% |
----------------------------------------------------------------------------
| grant all privileges on *.* to 'root' with grant option |
| grant all privileges on `oceanbase`.* to 'root' |
| grant all privileges on `__recyclebin`.* to 'root' |
| grant all privileges on `mysql`.* to 'root' |
| grant all privileges on `test`.* to 'root' |
| grant all privileges on `information_schema`.* to 'root' |
| grant all privileges on `__public`.* to 'root' |
| grant execute, alter routine on procedure `test`.`insertnumbers` to 'root' |
----------------------------------------------------------------------------
8 rows in set (0.00 sec)
mysql [mysql]> show grants for user_a@'10.10.10.10';
-------------------------------------------------------
| grants for user_a@10.10.10.10 |
-------------------------------------------------------
| grant all privileges on *.* to 'user_a'@'10.10.10.10' |
-------------------------------------------------------
1 row in set (0.00 sec)
mysql [mysql]> show grants for user_b@'10.10.10.10';
----------------------------------------------
| grants for user_b@10.10.10.10 |
----------------------------------------------
| grant usage on *.* to 'user_b'@'10.10.10.10' |
----------------------------------------------
1 row in set (0.02 sec)
点赞
收藏