https://www.modb.pro/db/337530

当忘记TiDB root 密码时,可以通过设置skip-grant-table参数来跳过密码验证,登录成功以后再修改root密码。

方法一:

修改tidb-server的配置文件

vi /tidb-deploy/tidb-4000/conf/tidb.toml
# WARNING: This file is auto-generated. Do not edit! All your modification will be overwritten!
# You can use 'tiup cluster edit-config' and 'tiup cluster reload' to update the configuration
# All configuration items you want to change can be added to:
# server_configs:
#   tidb:
#     aa.b1.c3: value
#     aa.b2.c4: value
[security]
skip-grant-table = true
~

直接修改配置文件需要重启tidb-server服务才能生效 连接到中控机,使用tiup关闭该节点的tidb-server服务

[root@node1 ~]# tiup cluster stop  tidb-test -N 192.168.233.82:4000
tiup is checking updates for component cluster ...
Starting component `cluster`: /root/.tiup/components/cluster/v1.9.1/tiup-cluster /root/.tiup/components/cluster/v1.9.1/tiup-cluster stop tidb-test -N 192.168.233.82:4000
Will stop the cluster tidb-test with nodes: 192.168.233.82:4000, roles: .
Do you want to continue? [y/N]:(default=N) y

+ [ Serial ] - SSHKeySet: privateKey=/root/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa, publicKey=/root/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa.pub
....
+ [ Serial ] - StopCluster
Stopping component tidb
      Stopping instance 192.168.233.82
      Stop tidb 192.168.233.82:4000 success
Stopping component node_exporter
Stopping component blackbox_exporter
Stopped cluster `tidb-test` successfully

由于添加了skip-grant-table = true 无法直接通过tiup来启动192.168.233.82上的 tidb-server

[root@node1 ~]# tiup cluster start  tidb-test -N 192.168.233.82:4000
tiup is checking updates for component cluster ...
Starting component `cluster`: /root/.tiup/components/cluster/v1.9.1/tiup-cluster /root/.tiup/components/cluster/v1.9.1/tiup-cluster start tidb-test -N 192.168.233.82:4000
Starting cluster tidb-test...
+ [ Serial ] - SSHKeySet: privateKey=/root/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa, publicKey=/root/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa.pub
....
+ [ Serial ] - StartCluster
Starting component tidb
      Starting instance 192.168.233.82:4000

Error: failed to start tidb: failed to start: 192.168.233.82 tidb-4000.service, please check the instance's log(/tidb-deploy/tidb-4000/log) for more detail.: timed out waiting for port 4000 to be started after 2m0s

Verbose debug logs has been written to /root/.tiup/logs/tiup-cluster-debug-2022-03-05-07-50-08.log.

官方文档说明:设置 skip-grant-table 之后,启动 TiDB 进程会增加操作系统用户检查,只有操作系统的 root 用户才能启动 TiDB 进程。

查看tidb-server的日志

[root@node2 log]# tailf -n 10 tidb_stderr.log
load config file: /tidb-deploy/tidb-4000/conf/tidb.toml
invalid config TiDB run with skip-grant-table need root privilege
load config file: /tidb-deploy/tidb-4000/conf/tidb.toml
invalid config TiDB run with skip-grant-table need root privilege
load config file: /tidb-deploy/tidb-4000/conf/tidb.toml
invalid config TiDB run with skip-grant-table need root privilege
load config file: /tidb-deploy/tidb-4000/conf/tidb.toml
invalid config TiDB run with skip-grant-table need root privilege
load config file: /tidb-deploy/tidb-4000/conf/tidb.toml
invalid config TiDB run with skip-grant-table need root privilege

连接到tidb-server所在的服务器,手工执行启动脚本

/tidb-deploy/tidb-4000/scripts/run_tidb.sh
再打开一个新会话,就可以免密登录了
[root@node2 ~]# mysql -h 192.168.233.82 -P 4000 -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.25-TiDB-v5.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]>

为一个已存在的账户修改密码,可以通过 SET PASSWORD FOR 或者 ALTER USER 语句完成:

SET PASSWORD FOR 'root'@'%' = 'xxx';

或者:

ALTER USER 'test'@'localhost' IDENTIFIED BY 'mypass';

修改成功以后,在执行启动脚本的会话里执行ctrl+c,然后删除添加的参数

再使用tiup重新启动tidb-server

[root@node1 ~]# tiup cluster start  tidb-test -N 192.168.233.82:4000
tiup is checking updates for component cluster ...
Starting component `cluster`: /root/.tiup/components/cluster/v1.9.1/tiup-cluster /root/.tiup/components/cluster/v1.9.1/tiup-cluster start tidb-test -N 192.168.233.82:4000
Starting cluster tidb-test...
+ [ Serial ] - SSHKeySet: privateKey=/root/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa, publicKey=/root/.tiup/storage/cluster/clusters/tidb-test/ssh/id_rsa.pub
.....
+ [ Serial ] - StartCluster
Starting component tidb
      Starting instance 192.168.233.82:4000
      Start instance 192.168.233.82:4000 success
Starting component node_exporter
      Starting instance 192.168.233.82
      Start 192.168.233.82 success
Starting component blackbox_exporter
      Starting instance 192.168.233.82
      Start 192.168.233.82 success
+ [ Serial ] - UpdateTopology: cluster=tidb-test
Started cluster `tidb-test` successfully

因为密码信息是存储再TiKV中的,所以当密码修改成功以后,所有的TiDB-server节点都可以使用新密码登录

方法二:

使用tiup 来修改配置文件

tiup cluster edit-config tidb-test

global:
user: tidb
ssh_port: 22
ssh_type: builtin
deploy_dir: /tidb-deploy
data_dir: /tidb-data
os: linux
arch: amd64
server_configs:
tidb:
security.skip-grant-table: true
monitored:
node_exporter_port: 9100
blackbox_exporter_port: 9115
deploy_dir: /tidb-deploy/monitor-9100

下面是添加的内容(注意折行)

server_configs:
tidb:
security.skip-grant-table: true

添加完成以后,需要执行reload语句来同步到节点上去。

Please check change highlight above, do you want to apply the change? [y/N]:(default=N) y
Applying changes...
Applied successfully, please use `tiup cluster reload tidb-test [-N <nodes>] [-R <roles>]` to reload config.
[root@node1 ~]# tiup cluster reload tidb-test
 - Generate config pd -> 192.168.233.83:2379 ... Done
 - Generate config tikv -> 192.168.233.81:20160 ... Done
 - Generate config tikv -> 192.168.233.82:20160 ... Done
 - Generate config tikv -> 192.168.233.83:20160 ... Done
 - Generate config tidb -> 192.168.233.82:4000 ... Error
 - Generate config tidb -> 192.168.233.83:4000 ... Error
 - Generate config prometheus -> 192.168.233.81:9090 ... Done
 - Generate config grafana -> 192.168.233.81:3000 ... Done
 - Generate config alertmanager -> 192.168.233.81:9093 ... Done

Error: init config failed: 192.168.233.83:4000: executor.ssh.execute_failed: Failed to execute command over SSH for 'tidb@192.168.233.83:22' {ssh_stderr: load config file: /tidb-deploy/tidb-4000/conf/tidb.toml
invalid config TiDB run with skip-grant-table need root privilege
, ssh_stdout: , ssh_command: export LANG=C; PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin /tidb-deploy/tidb-4000/bin/tidb-server --config-check --config=/tidb-deploy/tidb-4000/conf/tidb.toml }, cause: Process exited with status 1: check config failed

由于权限的问题,并不能是参数生效,不过tidb-server节点还是可用状态

[root@node1 ~]# tiup cluster display tidb-test
tiup is checking updates for component cluster ...
Starting component `cluster`: /root/.tiup/components/cluster/v1.9.1/tiup-cluster /root/.tiup/components/cluster/v1.9.1/tiup-cluster display tidb-test
Cluster type:       tidb
Cluster name:       tidb-test
Cluster version:   v5.0.0
Deploy user:       tidb
SSH type:           builtin
Dashboard URL:     http://192.168.233.83:2379/dashboard
ID                   Role         Host           Ports       OS/Arch       Status Data Dir                     Deploy Dir
--                    ----          ----            -----        -------       ------  --------                      ----------
192.168.233.81:9093   alertmanager  192.168.233.81  9093/9094   linux/x86_64 Up     /tidb-data/alertmanager-9093 /tidb-deploy/alertmanager-9093
192.168.233.81:3000   grafana       192.168.233.81  3000         linux/x86_64 Up      -                             /tidb-deploy/grafana-3000
192.168.233.81:2379   pd            192.168.233.81  2379/2380   linux/x86_64 Up     /tidb-data/pd-2379           /tidb-deploy/pd-2379
192.168.233.82:2379   pd            192.168.233.82  2379/2380   linux/x86_64 Up|L   /tidb-data/pd-2379           /tidb-deploy/pd-2379
192.168.233.83:2379   pd            192.168.233.83  2379/2380   linux/x86_64 Up|UI   /tidb-data/pd-2379           /tidb-deploy/pd-2379
192.168.233.81:9090   prometheus    192.168.233.81  9090         linux/x86_64 Up     /tidb-data/prometheus-9090   /tidb-deploy/prometheus-9090
192.168.233.82:4000   tidb          192.168.233.82  4000/10080   linux/x86_64 Up      -                             /tidb-deploy/tidb-4000
192.168.233.83:4000   tidb          192.168.233.83  4000/10080   linux/x86_64 Up      -                             /tidb-deploy/tidb-4000
192.168.233.81:20160 tikv          192.168.233.81  20160/20180 linux/x86_64 Up     /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
192.168.233.82:20160 tikv          192.168.233.82  20160/20180 linux/x86_64 Up     /tidb-data/tikv-20160         /tidb-deploy/tikv-20160
192.168.233.83:20160 tikv          192.168.233.83  20160/20180 linux/x86_64 Up     /tidb-data/tikv-20160         /tidb-deploy/tikv-20160

还是需要跟方法一样,将一个tidb-server节点关闭以后,手动使用root用户执行启动脚本。

[转帖]TiDB之修改root密码的更多相关文章

  1. RedHat/Centos修改root密码

    Linux主机忘记密码,只要你能接触物理主机都可以修改root密码的!   Redhat6.x 5.x  / Centos6.x  5.x 01.开机-空格/enter 02.e-编辑模式 CentO ...

  2. ansible非root用户批量修改root密码

    前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...

  3. phpmyadmin修改root密码

    很多人利用phpmyadmin或者命令行来修改了mysql的root密码,重启 后发现mysql登录错误,这是为什么呢?修改mysql的root的密码要在mysql软件中mysql数据库里修改root ...

  4. mysql修改root密码和设置权限

    整理了以下四种在MySQL中修改root密码的方法,可能对大家有所帮助! 方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR ' ...

  5. MySQL下载、安装和修改root密码

    一.下载地址:MySQL_5.6.22_winx64_XiaZaiBa :http://rj.baidu.com/soft/detail/12585.html?ald 二.安装软件,安装到指定的路径, ...

  6. mysql给root开启远程访问权限,修改root密码

    1.MySql-Server 出于安全方面考虑只允许本机(localhost, 127.0.0.1)来连接访问. 这对于 Web-Server 与 MySql-Server 都在同一台服务器上的网站架 ...

  7. CentOS单用户模式下修改ROOT密码和grub加密

    Linux 系统处于正常状态时,服务器主机开机(或重新启动)后,能够由系统引导器程序自动引导 Linux 系统启动到多用户模式,并提供正常的网络服务.如果系统管理员需要进行系统维护或系统出现启动异常时 ...

  8. windows 环境下mysql 如何修改root密码

    windows 环境下mysql 如何修改root密码 以windows为例: 无法开启服务,将mysql更目录下的data文件夹清空,然后调用 mysqld --initialize 开启mysql ...

  9. Mac OS X 10.9 Mavericks 修改root密码

    Mac10.9忘记密码后有两种方式可以进去:  代码如下 复制代码 1.sudo passwd 重新输入密码即可,此方法修改了root的密码  代码如下 复制代码 2.sudo bash 输入当前用户 ...

  10. centos单用户模式:修改ROOT密码和grub加密

    centos单用户模式:修改ROOT密码和grub加密 CentOSLinux网络应用配置管理应用服务器  Linux 系统处于正常状态时,服务器主机开机(或重新启动)后,能够由系统引导器程序自动引导 ...

随机推荐

  1. 聊一聊如何整合Microsoft.Extensions.DependencyInjection和Castle.Core(三)

    前言 今天的第三篇,感觉没啥人看呀,难道没有兄弟跟我有同样的整合需求吗???手动 , 本文会简短一些,介绍下 CastleCore 作为代理库的一些缺点甚至是硬伤 异步支持 先上代码 /// < ...

  2. LeetCode 947. 移除最多的同行或同列石头 并查集

    传送门 思路 干货太干就不太好理解了,以下会有点话痨( ̄▽ ̄)" 首先题目给了一个二维stones数组,存储每个石子的坐标,因为在同行或者同列的石子最终可以被取到只剩下一个,那么我们将同行同 ...

  3. LeetCode 回溯篇(46、77、78、51)

    46. 全排列 给定一个 没有重复 数字的序列,返回其所有可能的全排列. 示例: 输入: [1,2,3] 输出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1, ...

  4. LeetCode 栈与队列篇(12、155、84、239)

    20. 有效的括号 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. ...

  5. 当 BACnet 遇上 IoT,你将体验到不一样的大楼

    本文分享自华为云社区<当 BACnet 遇上 IoT>,作者:美码师zale . 引言 在十四五规划中,"新基建"无疑是倍受关注的重点领域.而关于"新基建&q ...

  6. 大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术

    摘要:通过这篇文章,我们了解了GaussDB(DWS)并行计算技术的原理以及调优策略.希望广大开发者朋友们能够在实践中尝试该技术,更好地进行性能优化. 随着硬件系统的越来越好,数据库运行的CPU.磁盘 ...

  7. 解读8大场景下Kunpeng BoostKit 使能套件的最佳能力和实践

    摘要:本次鲲鹏 BoostKit 训练营为开发者介绍如何基于鲲鹏 BoostKit 使能套件实现应用性能的加速,并重点剖析性能优化技术和关键能力. 本文分享自华为云社区<[云驻共创]" ...

  8. 带你掌握不同平台下,探索JDK源码所需的native方法

    摘要:要探索JDK的核心底层源码,那必须掌握native用法.文章中会以"获取系统的默认时区"为例,介绍说明如何查看native对应方法的源码. 本文分享自华为云社区<要探索 ...

  9. Vue混淆与还原

    ​ 引言 Vue是一种流行的JavaScript框架,用于构建用户界面.它简单易用且功能强大,备受开发者喜爱.然而,在传输和存储过程中,我们需要保护Vue代码的安全性.混淆是一种有效的保护措施,可以加 ...

  10. 接通率维持 66% 以上,为什么火山引擎 VeDI 能让企业智能外呼不再难?

    更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 智能机器人在企业级市场的应用更加深入了. 随着人工智能技术的进一步发展,包括智能外呼.财务审核.自助客服等在内的智 ...