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

歡迎訪問 生活随笔!

生活随笔

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

数据库

linux下Mysql命令

發(fā)布時(shí)間:2024/10/12 数据库 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux下Mysql命令 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1,進(jìn)入mysql,終端中輸入 mysql -u 用戶名 -p ? 。enter鍵后,提示輸入密碼。

2,執(zhí)行g(shù)rant all privileges on xxxdb.* to usertest@"%" identified by "passdtest"; 增加用戶usertest,密碼為passdtest。其對(duì)數(shù)據(jù)庫xxxdb有所有權(quán)限。可以外網(wǎng)訪問。

3,show databases; ?顯示此用戶下的數(shù)據(jù)庫

4,select host,user from mysql.user; ?查看用戶的權(quán)限

?

1、創(chuàng)建新用戶

  通過root用戶登錄之后創(chuàng)建

  >>?grant all privileges on *.* to?testuser@localhost identified by?"123456"?;  //  創(chuàng)建新用戶,用戶名為testuser,密碼為123456 ;

  >>?grant all privileges on *.* to?testuser@localhost identified by?"123456"?;  //  設(shè)置用戶testuser,可以在本地訪問mysql

  >>?grant all privileges on *.* to?testuser@"%" identified by?"123456"?;   //  設(shè)置用戶testuser,可以在遠(yuǎn)程訪問mysql

  >>?flush privileges?;  //  mysql 新設(shè)置用戶或更改密碼后需用flush privileges刷新MySQL的系統(tǒng)權(quán)限相關(guān)表,否則會(huì)出現(xiàn)拒絕訪問,還有一種方法,就是重新啟動(dòng)mysql服務(wù)器,來使新設(shè)置生效

  

  2、設(shè)置用戶訪問數(shù)據(jù)庫權(quán)限

  >>?grant all privileges on?test_db.*?to?testuser@localhost identified by "123456" ;  //  設(shè)置用戶testuser,只能訪問數(shù)據(jù)庫test_db,其他數(shù)據(jù)庫均不能訪問?;

  >>?grant all privileges on?*.*?to?testuser@localhost identified by "123456" ;  //  設(shè)置用戶testuser,可以訪問mysql上的所有數(shù)據(jù)庫 ;

  >>?grant all privileges on?test_db.user_infor?to?testuser@localhost identified by "123456" ;  //  設(shè)置用戶testuser,只能訪問數(shù)據(jù)庫test_db的表user_infor,數(shù)據(jù)庫中的其他表均不能訪問?;

  

  3、設(shè)置用戶操作權(quán)限

  >>?grant?all privileges?on *.* to?testuser@localhost identified by "123456" WITH GRANT OPTION?;  //設(shè)置用戶testuser,擁有所有的操作權(quán)限,也就是管理員 ;

  >> grant?select?on *.* to?testuser@localhost identified by "123456" WITH GRANT OPTION?;  //設(shè)置用戶testuser,只擁有【查詢】操作權(quán)限 ;

  >>?grant?select,insert?on *.* to?testuser@localhost identified by "123456" ?;  //設(shè)置用戶testuser,只擁有【查詢\插入】操作權(quán)限 ;

  >>?grant?select,insert,update,delete?on *.* to?testuser@localhost identified by "123456" ?;  //設(shè)置用戶testuser,只擁有【查詢\插入】操作權(quán)限 ;

  >>?REVOKE?select,insert?ON what FROM?testuser  //取消用戶testuser的【查詢\插入】操作權(quán)限 ;

  

  4、設(shè)置用戶遠(yuǎn)程訪問權(quán)限

  >>?grant all privileges on *.* to?testuser@“192.168.1.100”?identified by?"123456"?;  //設(shè)置用戶testuser,只能在客戶端IP為192.168.1.100上才能遠(yuǎn)程訪問mysql ;

  

  5、關(guān)于root用戶的訪問設(shè)置

  設(shè)置所有用戶可以遠(yuǎn)程訪問mysql,修改my.cnf配置文件,將bind-address = 127.0.0.1前面加“#”注釋掉,這樣就可以允許其他機(jī)器遠(yuǎn)程訪問本機(jī)mysql了;

  >>?grant all privileges on *.* to?root@"%" identified by?"123456"?;   //  設(shè)置用戶root,可以在遠(yuǎn)程訪問mysql

  >>?select host,user from user;   //查詢mysql中所有用戶權(quán)限

  關(guān)閉root用戶遠(yuǎn)程訪問權(quán)限

  >>?delete from user where user="root" and host="%" ;  //禁止root用戶在遠(yuǎn)程機(jī)器上訪問mysql

  >>?flush privileges?;  //修改權(quán)限之后,刷新MySQL的系統(tǒng)權(quán)限相關(guān)表方可生效  

?

轉(zhuǎn)載于:https://www.cnblogs.com/Bonker/p/5552577.html

與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的linux下Mysql命令的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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