MariaDB密碼重置

MariaDB密碼重置mysql

若是記得root的密碼:linux

mysqladmin -uroot -paminglinux password "aming-linux"  //用此方式將原密碼aminglinux重置爲aming-linux

若是不記得原密碼:sql

# vi /etc/my.cnf

[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
skip-grant   //添加這一行

此時登陸root就不須要密碼了socket

# mysql -uroot
> use mysql  //切換到mysql庫
> desc user;    //查看user表的全部字段
密碼存在了authentication_string字段裏,所以修改此字段
> update user set authentication_string=password("wangzb") where user='root' and host='localhost';   //update該字段修改密碼
退出MariaDB,刪除/etc/my.cnf裏面的skip-grant  重啓服務

# vi /etc/my.cnf

修改普通用戶密碼:code

# mysql -uroot -pmysql
> use mysql;
> select user,host from user;
+------+-----------+
| user | host      |
+------+-----------+
| bbs  | 127.0.0.1 |
| blog | 127.0.0.1 |
| root | 127.0.0.1 |
| root | ::1       |
|      | localhost |
| root | localhost |
|      | wangzb01  |
| root | wangzb01  |
+------+-----------+

> update user set authentication_string=password("wangzb") where user='root' and host='localhost';   //update用戶及對應主機的密碼
相關文章
相關標籤/搜索