一、重設密碼
方法一:
mysql>use mysql
/*進入mysql資料庫,存放user表包括user和密碼的庫
密碼欄位名稱為authentication_string(5.7)、password(5.6)*/
mysql>update user set authentication_string=password('newpass') where user='root'; //5.7版本
mysql> update mysql.user set password=PASSWORD(’新密碼’) where User=’root’; //5.6版本
mysql>flush privileges;#重繪一下
方法二:
#mysqladmin -u 用戶 password ‘newpassword’
[root@server1 ~]# mysqladmin -u lisi -p password '123456';
Enter password: #這里輸入原密碼
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety
方法三:
以root身份進入資料庫
[root@server1 ~]# mysql -uroot -p123456
mysql> SET PASSWORD = PASSWORD('新密碼'); //root用戶
mysql> SET PASSWORD FOR 用戶 = PASSWORD(‘新密碼');//普通用戶
二、忘記密碼
修改mysql的組態檔:
vi /etc/my.cnf
[mysqld] 模塊下
末尾添加
skip_grant_tables 就是在啟動mysql時不啟動grant-tables,授權表,跳過表的加載
重啟資料庫服務
systemctl restart mysqld
默認密碼恢復為空,進入資料庫,再修改密碼欄位
[root@server3 ~]# netstat -anpt | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 1282/mysqld
[root@server3 ~]# mysql -u root -p
Enter password: #回車直接登錄
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20 Source distribution
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#修改密碼
mysql> update user set authentication_string=password('xzf729') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
修改完密碼后,再洗掉添加的組態檔那一行,重啟服務,
vi /etc/my.cnf
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
[root@server1 ~]# systemctl restart mysqld
[root@server1 ~]# mysql -u root -p xzf729 #可登錄成功
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/201858.html
標籤:其他
