[root@kvm3 ~]# systemctl stop mariadb.service
mysqld_safe
跳過 grant tables,因為接著要下命令,所以讓其背景執行。
[root@kvm3 ~]# mysql_safe --skip-grant-tables & [1] 13549 [root@kvm3 ~]# 230224 17:06:36 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 230224 17:06:36 mysqld_safe Starting mariadbd daemon with databases from /var/lib/mysql
[root@kvm3 ~]# mariadb -uroot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.5.16-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY '123qwe'; ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
MariaDB [(none)]> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
mysql.global_priv
取代 mysql.user
,之前以變更 mysql.user 的方法,在 mysqld_safe --skip-grant-tables
下都無法執行。
MariaDB [mysql]> update user set password=password("123123") where user='root'; ERROR 1348 (HY000): Column 'Password' is not updatable
MariaDB [mysql]> ALTER USER 'root'@'localhost' IDENTIFIED BY '123123'; ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
MariaDB [mysql]> update user set authentication_string=PASSWORD("123123") where User='root'; ERROR 1348 (HY000): Column 'authentication_string' is not updatable
mariadb-secure-installation
腳本,update mysql.global_priv
表格的方式更新 root 密碼。
[root@kvm3 ~]# grep esc_pass /usr/bin/mariadb-secure-installation esc_pass=`basic_single_escape "$rootpass"` echo "password='$esc_pass'" >>$config esc_pass=`basic_single_escape "$password1"` do_query "UPDATE mysql.global_priv SET priv=json_set(priv, '$.plugin', 'mysql_native_password', '$.authentication_string', PASSWORD('$esc_pass')) WHERE User='root';"
mysql.global_priv
表格的方式,更新 root 密碼為 123123。
[root@kvm3 ~]# mariadb -uroot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 10.5.16-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> UPDATE mysql.global_priv SET priv=json_set(priv, '$.plugin', 'mysql_native_password', '$.authentication_string', PASSWORD('123123')) WHERE User='root'; Query OK, 1 row affected (0.034 sec) Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> quit Bye
mysql_safe
還在背景執行,先刪除。
[root@kvm3 ~]# jobs [1]+ Running mysqld_safe --skip-grant-tables & [root@kvm3 ~]# kill %1
[root@kvm3 ~]# systemctl start mariadb.service [1]+ Done mysqld_safe --skip-grant-tables
[root@kvm3 ~]# mariadb -uroot ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@kvm3 ~]# mariadb -uroot -p123123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.5.16-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> quit Bye