mysql鹽 MySQL5 7 常用使用者操作

2021-10-17 17:11:01 字數 1814 閱讀 3207

mysql5.7 常用使用者操作

之前的一篇博文講述了安裝mysql,但是我們在安裝後mysql之後的操作中一般不使用root使用者來進行相應的操作,所以要新建使用者,並賦予相應的許可權後,才能更好的使用和管理資料庫。

mysql版本:5.7

1. 新建使用者

create user 'username'@'host' identified by 'password';

例子:create user 'user'@'localhost' identified by '123456';

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

username : 你將建立的使用者名稱

host : 指定該使用者在哪個主機上可以登陸,此處的"localhost",是指該使用者只能在本地登入,不能在另外一台機器上遠端登入,如果想遠端登入的話,將"localhost"改為"%",表示在任何一台電腦上都可以登入;也可以指定某台機器可以遠端登入;

password : 該使用者的登陸密碼,密碼可以為空,如果為空則該使用者可以不需要密碼登陸伺服器。

mysql5.7 mysql.user表password欄位改為 authentication_string;

2. 授權

grant privileges on databasename.tablename to 'username'@'host';

privileges : 使用者的操作許可權,如select , insert , update 等。如果要授予所的許可權則使用all。

databasename : 資料庫名

tablename : 表名

如果要授予該使用者對所有資料庫和表的相應操作許可權則可用*表示, 如*.*.

## 賦予user對資料庫store下的所有表的檢視和增添權利

grant select, insert on store.* to 'user'@'localhost';

3. 建立使用者時授權

grant all privileges on store.* to user@'%' identified by '123456';

flush privileges;

4. 設定與更改使用者密碼(root)

update mysql.user set authentication_string=password("新密碼") where user="test" and host="localhost";

flush privileges;

5. 撤銷使用者許可權

## 具體資訊可以用命令show grants for 'username'@'host'; 檢視.

revoke privilege on databasename.tablename from 'username'@'host';

6. 刪除使用者

drop user 'username'@'host';

7. 檢視使用者的授權

show grants for user@localhost;

8. 顯示當前使用者資訊

select user();

9. 重置root密碼

在my.cnf的[mysqld]字段加入skip-grant-tables,然後重啟mysql服務,這時的mysql不需要密碼即可登入資料庫。然後進入mysql:

use mysql;

update user set password=password('新密碼') where user='root';

flush privileges;

執行之後最後去掉my.cnf中的skip-grant-tables,重啟mysqld即可。

Mysql 5 7 常用配置

客戶端最大併發連線限制數 根據 threads connected 和 max used connections 來調整 預設值 151 mysql 暫存連線數,短時間得到大量連線時,能夠被暫時存到堆疊的連線數 不能超過系統設定 proc sys net ipv4 tcp max syn backl...

mysql5 7學習 mysql 5 7 學習

mysql uroot proot mysql5.7 mysql.user表沒有password欄位改 authentication string 一.建立使用者 命令 create user username host identified by password 例子 create user d...

mysql5 7如何開啟 mysql57怎麼開啟

開啟mysql57的方法 首先開啟winodws執行視窗 然後在開啟編輯框中輸入cmd命令 最後在終端介面中輸入 mysql hlocalhost uroot p123 即可顯示開啟mysql資料庫。windows下用命令列啟動mysql5.7 win菜單鍵即是在鍵盤左下角 ctrl控制 鍵與 al...