Centos7 修改mysql指定使用者的密碼

阿豪聊乾貨發表於2016-09-15

1.登陸mysql或者mariadb(兩種任選其一)

[root@localhost ~]# mysql -u root 
[root@localhost ~]# mysql -uroot -p

2.切換到儲存使用者名稱和密碼的資料庫

MariaDB [mysql]> 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

3.修改密碼,適用password()函式進行加密,實際上就是執行sql語句來更新指定使用者的密碼

MariaDB [mysql]> update user set password=password('新密碼') where user='要更新密碼的使用者名稱';回車
  -> ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5 Changed: 0 Warnings: 0

4.重新整理使用者許可權列表

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

5.退出mysql登陸

MariaDB [mysql]> quit
Bye

6.重啟mysql或者mariadb服務

[root@localhost ~]# service mysqld restart(重啟mysql)
[root@localhost ~]# service mariadb restart(重啟mariadb)

相關文章