【安装】
参考:https://amon.org/ubuntu-mariadb
参考:https://amon.org/centos-mariadb
【重置密码】
参考:https://blog.csdn.net/qq_42048263/article/details/118964075
1、确认mysql的版本号信息
mysql --version
2、停止Mariadb服务
systemctl stop mariadb
3、以安全的方式启动mariadb
mysqld_safe --skip-grant-tables --skip-networking &
4、以root用户登录Mariadb数据库
mysql -u root
5、设置root的新密码
(1)刷新权限将权限表加载到内存中
MariaDB [(none)]> flush privileges;
(2)修改root的密码
MariaDB [(none)]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MY_NEW_PASSWORD');
输出:
Query OK, 0 rows affected (0.06 sec)
(3)刷新权限将权限表加载到内存中
MariaDB [(none)]> flush privileges; [shell] (4)退出CLI命令行 [shell] MariaDB [(none)]> exit; [shell] 其他补充说明:mysql或Mariadb版本不同,设置密码的命令可能有所差异, MySQL 5.7.6 and later or MariaDB 10.1.20 and later: [shell] ALTER USER 'root'@'localhost' IDENTIFIED BY 'MY_NEW_PASSWORD';
若不生效则使用如下命令
UPDATE mysql.user SET authentication_string = PASSWORD('MY_NEW_PASSWORD')WHERE User = 'root' AND Host = 'localhost';
MySQL 5.7.5 and earlier or MariaDB 10.1.20 and earlier:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MY_NEW_PASSWORD');
6、关闭安全运行的Mariadb
mysqladmin -u root -p shutdown 【或者使用kill杀进程】 Enter password: 【此处要求输入刚设置的新密码】 [1]+ Done mysqld_safe --skip-grant-tables --skip-networking
7、启动Mariadb服务进程
systemctl start mariadb
8、登录Mariadb服务器验证新设置的密码是否生效
mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.56-MariaDB MariaDB Server Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>