mysql資料庫修改密碼

2022-02-21 20:58:05 字數 4297 閱讀 6479

方法1: 用set password命令

首先登入mysql。

格式:mysql> set password for 使用者名稱@localhost = password('新密碼');

例子:mysql> set password for root@localhost = password('123');

方法2:用mysqladmin

格式:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼

例子:mysqladmin -uroot -p123456 password 123

方法3:用update直接編輯user表

首先登入mysql。

mysql> use mysql;

mysql> update user set password=password('123') where user='root' and host='localhost';

mysql> flush privileges;

方法4:在忘記root密碼的時候,可以這樣

以windows為例:

1. 關閉正在執行的mysql服務。

2. 開啟dos視窗,轉到mysql\bin目錄。

3. 輸入mysqld --skip-grant-tables 回車。--skip-grant-tables 的意思是啟動mysql服務的時候跳過許可權表認證。

4. 再開乙個dos視窗(因為剛才那個dos視窗已經不能動了),轉到mysql\bin目錄。

5. 輸入mysql回車,如果成功,將出現mysql提示符 >。

6. 連線許可權資料庫: use mysql; 。

6. 改密碼:update user set password=password("123") where user="root";(別忘了最後加分號) 。

7. 重新整理許可權(必須步驟):flush privileges; 。

8. 退出 quit。

9. 登出系統,再進入,使用使用者名稱root和剛才設定的新密碼123登入。

方法一: 

(適用於管理員或者有全域性許可權的使用者重設其它使用者的密碼)

進入命令列模式

mysql

-u root -p

mysql>use mysql;

mysql> update user set

password=password("new password") where user='username';

mysql> flush

privileges;

mysql> quit;

方法二:

mysql -u root -p 

mysql>use

mysql; 

mysql> set password for   username=password('new

password');

方法一: 

(適用於管理員或者有全域性許可權的使用者重設其它使用者的密碼)

進入命令列模式

mysql -u

root -p

mysql>use mysql;

mysql> update user set

password=password("new password") where user='username';

mysql> flush

privileges;

mysql> quit;

方法二:

mysql -u root -p 

mysql>use

mysql; 

mysql> set password for   username=password('new

password');

mysql> quit

方法三:

mysqladmin -u root "old

password" "new password"

注:new password請輸入你想要設定的密碼。

關於mysql的使用者管理,筆記

mysql使用者賦許可權操作

1、建立新使用者

通過root使用者登入之後建立

>> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  建立新使用者,使用者名為testuser,密碼為123456 ;

>> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  設定使用者testuser,可以在本地訪問mysql

>> grant all privileges on *.* to testuser@"%" identified by "123456" ;   //  設定使用者testuser,可以在遠端訪問mysql

>>flush privileges ;  //  mysql 新設定使用者或更改密碼後需用flush privileges重新整理mysql的系統許可權相關表,否則會出現拒絕訪問,還有一種方法,就是重新啟動mysql伺服器,來使新設定生效

2、設定使用者訪問資料庫許可權

>> grant all privileges on test_db.* to testuser@localhost identified by "123456" ;  //  設定使用者testuser,只能訪問資料庫test_db,其他資料庫均不能訪問 ;

>> grant all privileges on *.* to testuser@localhost identified by "123456" ;  //  設定使用者testuser,可以訪問mysql上的所有資料庫 ;

>> grant all privileges on test_db.user_infor to testuser@localhost identified by "123456" ;  //  設定使用者testuser,只能訪問資料庫test_db的表user_infor,資料庫中的其他表均不能訪問 ;

3、設定使用者操作許可權

>> grant all privileges on *.* to testuser@localhost identified by "123456" with grant option ;  //設定使用者testuser,擁有所有的操作許可權,也就是管理員 ;

>> grant select on *.* to testuser@localhost identified by "123456" with grant option ;  //設定使用者testuser,只擁有【查詢】操作許可權 ;

>> grant select,insert on *.* to testuser@localhost identified by "123456"  ;  //設定使用者testuser,只擁有【查詢\插入】操作許可權 ;

>> grant select,insert,update,delete on *.* to testuser@localhost identified by "123456"  ;  //設定使用者testuser,只擁有【查詢\插入】操作許可權 ;

>> revoke select,insert on what from testuser  //取消使用者testuser的【查詢\插入】操作許可權 ;

4、設定使用者遠端訪問許可權

>> grant all privileges on *.* to testuser@「192.168.1.100」 identified by "123456" ;  //設定使用者testuser,只能在客戶端ip為192.168.1.100上才能遠端訪問mysql ;

5、關於root使用者的訪問設定

設定所有使用者可以遠端訪問mysql,修改my.cnf配置檔案,將bind-address = 127.0.0.1前面加「#」注釋掉,這樣就可以允許其他機器遠端訪問本機mysql了;

>> grant all privileges on *.* to root@"%" identified by "123456" ;   //  設定使用者root,可以在遠端訪問mysql

>> select host,user from user;   //查詢mysql中所有使用者許可權

關閉root使用者遠端訪問許可權

>> delete from user where user="root" and host="%" ;  //禁止root使用者在遠端機器上訪問mysql

>> flush privileges ;  //修改許可權之後,重新整理mysql的系統許可權相關表方可生效

修改mysql資料庫密碼

1.新增環境變數mysql home d mysql d mysql為mysql資料庫的安裝目錄 接著在已存在的環境變數path後追加 mysql home bin 或 直接進行mysql安裝目錄下的bin目錄執行dos2.在dos下執行 mysql u root p然後輸入舊的mysql資料庫密碼...

修改mysql資料庫密碼

首先登入mysql。mysql set password for 使用者名稱 localhost password 新密碼 mysqladmin u使用者名稱 p舊密碼 password 新密碼 首先登入mysql。mysql use mysql mysql update user set pass...

MySql資料庫修改密碼

1,開啟mysql.exe和mysqld.exe所在的資料夾,複製路徑位址 2,開啟cmd命令提示符,進入上一步mysql.exe所在的資料夾 3,輸入命令 mysqld skip grant tables 回車,此時就跳過了mysql的使用者驗證。注意輸入此命令之後命令列就無法操作了,此時可以再開...