資料庫新增使用者,授予許可權,修改密碼

2021-09-27 03:42:57 字數 1809 閱讀 1235

一、資料庫新增使用者:

#允許本地 ip訪問localhost的mysql資料庫:

create user 'test'@'localhost' identified by 'test123456';

#允許外網ip訪問資料庫test,本命令包含上面的命令,是所有的ip都可以訪問該資料庫

create user 'test'@'%' identified by 'test123456';

test:使用者名稱

test123456:使用者密碼

重新整理許可權:flush privileges;

二、新增許可權:

#允許本地ip訪問資料庫testdb授予許可權

grant all privileges on `testdb`.* to 'test'@'localhost' identified by 'test123456' with grant option;

#允許外網ip訪問資料庫testdb授予許可權

grant all privileges on `testdb`.* to 'test'@'%' identified by 'test123456' with grant option;

testdb:資料庫名

test:使用者名稱

itest123456:使用者密碼

重新整理許可權:flush privileges;

三、mysql如何修改root使用者的密碼

方法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

mysql> use mysql; 

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

mysql> flush privileges;

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

以windows為例:

關閉正在執行的mysql服務。

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

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

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

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

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

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

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

退出 quit。

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

修改資料庫密碼和新增資料庫使用者許可權

一 mysql修改密碼方法總結 首先要說明一點的是 一般情況下,修改mysql密碼是需要有mysql裡的root許可權的,這樣一般使用者是無法更改密碼的,除非請求管理員幫助修改。方法一使用phpmyadmin 圖形化管理mysql資料庫的工具 這是最簡單的,直接用sql語句修改mysql資料庫庫的u...

MySQL資料庫常用的授予許可權和撤銷許可權的命令講解

mysql 賦予使用者許可權命令的簡單格式可概括為 一 grant 普通資料使用者,查詢 插入 更新 刪除 資料庫中所有表資料的權利 1 2 3 4grant select on testdb.to common user grant insert on testdb.to common user ...

MySql授予使用者指定資料庫許可權

授予使用者通過外網ip對於該資料庫的全部許可權 grant all privileges on test to test 授予使用者在本地伺服器對該資料庫的全部許可權 grant all privileges on test to test localhost grant select on tes...