日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

[转帖] mysql 用户 权限 密码等操作记录

發(fā)布時(shí)間:2023/12/20 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [转帖] mysql 用户 权限 密码等操作记录 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前言

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';

?

?

重置管理員密碼

  • 停止mysql服務(wù):service mysqld stop 或 ./mysql.server stop;
  • 以不檢查權(quán)限方式啟動(dòng)mysql:./mysqld –skip-grant-tables –user=mysql &;
  • 以空密碼方式登陸:mysql -h 127.0.0.1 -P 3306 -u root;
  • mysql5.7以前版本——修改root密碼:update mysq.user set password=password(‘newpassword’) where user=’root’;
  • mysql5.7以后版本——修改root密碼:update mysql.user set authentication_string=password(‘newpassword’) where user=’root’;(只能用此種update方法修改)
  • 刷新權(quán)限:flush privileges;
  • 關(guān)閉mysql:shutdown;
  • 以正常方式啟動(dòng)mysql: service mysqld start 或 ./mysql.server start;
  • 參考資料

  • http://www.cnblogs.com/fslnet/p/3143344.html
  • http://www.cnblogs.com/xujishou/p/6306765.html
  • http://www.cnblogs.com/4php/p/4113593.html
  • 轉(zhuǎn)載于:https://www.cnblogs.com/jinanxiaolaohu/p/9329525.html

    總結(jié)

    以上是生活随笔為你收集整理的[转帖] mysql 用户 权限 密码等操作记录的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。