mariadb 重置密码

如果忘记数据库密码,可以做下面的操作进行重置

停止数据库

root@Techs-Public:~# /etc/init.d/mariadb start

重置密码

root@Techs-Public:~# mysqld_safe --skip-grant-tables &
[2] 21207
root@Techs-Public:~# 170719 13:39:43 mysqld_safe Logging to '/usr/local/mariadb/var/mariadb.err'.
170719 13:39:43 mysqld_safe A mysqld process already exists
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.1.23-MariaDB Source distribution

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)]> use mysql;
Database changed
MariaDB [mysql]>

MariaDB [mysql]> update user set password=PASSWORD('upyun@#techs') where user="root";
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]>quit

启动数据库

root@Techs-Public:~# /etc/init.d/mariadb start
[ ok ] Starting mariadb (via systemctl): mariadb.service.
root@Techs-Public:~# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.1.23-MariaDB Source distribution

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)]>