[转帖] mysql 用户 权限 密码等操作记录
前言
From :https://blog.csdn.net/yu12377/article/details/78214336
mysql5.7版本中用戶管理與以前版本略有不同,在此記錄,以備忘
登陸
[root@ver ~]# mysql -h 127.0.0.1 -P 3316 -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.7.17 Source distributionCopyright (c) 2000, 2016, 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>?
?
參數(shù)說明:
-h: 指定數(shù)據(jù)庫(kù)IP地址;
-P: 指定端口,默認(rèn)的3306時(shí),可以忽略;
-u: 指定登陸用戶名;
-p: 指定登陸密碼(小寫,注意與指定端口的大寫P區(qū)分);
指定操作數(shù)據(jù)庫(kù)
mysql> show databases; # 查看所有數(shù)據(jù)庫(kù) +--------------------+ | Database | +--------------------+ | information_schema | | fhgk | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.01 sec)mysql> use mysql # 指定當(dāng)前操作的數(shù)據(jù)庫(kù) Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -ADatabase changed mysql>?
創(chuàng)建用戶
# 創(chuàng)建用戶 mysql> CREATE USER 'username'@'host' IDENTIFIED BY 'password';# 刪除用戶 mysql> DROP USER 'username'@'host';?
host參數(shù)說明:
% 匹配所有主機(jī)
localhost localhost不會(huì)被解析成IP地址,直接通過UNIXsocket連接
127.0.0.1 會(huì)通過TCP/IP協(xié)議連接,并且只能在本機(jī)訪問;
::1 ::1就是兼容支持ipv6的,表示同ipv4的127.0.0.1
此時(shí)還沒有授權(quán),只能登陸,無法做其余操作
用戶授權(quán)
# 用戶授權(quán) mysql> grant privileges ON databasename.* TO 'username'@'host';# 創(chuàng)建用戶的同時(shí)授權(quán) mysql> grant all privileges on databasename.* to 'username'@'host' identified by '1234';# 授權(quán)刷新 mysql> flush privileges;# 查看用戶擁有權(quán)限 mysql> show grants for dev@'%'; +----------------------------------------------------------------------+ | Grants for dev@% | +----------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'dev'@'%' | | GRANT SELECT, INSERT, UPDATE, DELETE, ALTER ON `fhgk`.* TO 'dev'@'%' | +----------------------------------------------------------------------+ 2 rows in set (0.00 sec)# 撤消用戶授權(quán),撤消要求各參數(shù)與授權(quán)時(shí)使用的一致,可以相查看授權(quán)再撤消 mysql> revoke privileges ON databasename.* FROM 'username'@'host';?
privileges參數(shù)說明: all privileges: 所有權(quán)限; select: 查詢; insert: 新增記錄; update: 更新記錄; delete: 刪除記錄; create: 創(chuàng)建表; drop: 刪除表; alter: 修改表結(jié)構(gòu); index: 索引相關(guān)權(quán)限; execute: 執(zhí)行存儲(chǔ)過程與call函數(shù) references: 外鍵相關(guān); create temporary tables:創(chuàng)建臨時(shí)表; lock tables 鎖表; create view 創(chuàng)建視圖; show view 查看視圖結(jié)構(gòu); create routine alter routine: event: trigger: 觸發(fā)器相關(guān);?
databasename.*參數(shù)說明:
此處可以針對(duì)具體的某個(gè)庫(kù),如:【zjims.*】;
也可以針對(duì)具體庫(kù)中的某個(gè)對(duì)象,如:【zjims.t_user】;
還可以針對(duì)所有數(shù)據(jù)庫(kù),如:【.】;
修改密碼
# 修改自己的密碼 mysql> set password=password('newpassword');# 修改別人密碼——方法1 mysql> set password for 'username'@'host' = password('newpassword');# 修改別人密碼——方法2: 適用mysql5.7以前的版本,5.7以后的版本中mysql.user表沒有了password字段 mysql> update mysq.user set password=password('newpassword') where user='user' and host='host'; # 修改別人密碼——方法3:適用mysql5.7 mysql> update mysql.user set authentication_string=password('newpassword') where user='root';# 修改別人密碼——方法4 mysql> alter user 'test'@'%' identified by 'newpassword';?
?
重置管理員密碼
參考資料
轉(zhuǎn)載于:https://www.cnblogs.com/jinanxiaolaohu/p/9329525.html
總結(jié)
以上是生活随笔為你收集整理的[转帖] mysql 用户 权限 密码等操作记录的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (开源)微信小程序实时控制stc89c5
- 下一篇: java gui 连接mysql数据库