MySQL常用陳述句
剛入手資料庫小白,自己的一些筆記,踩過的坑都記錄下來,方便之后復習和幫助一些同樣遇到坑的朋友,
一.修改root密碼:
1.MySQL5.7版本
方法1:用set psssword 修改
例如:
set password for ‘root’@‘localhost’=password(‘123456’);
方法2:用update更改
update mysql.user set password=password(‘123456’) where user =‘root’ and host =‘localhost’;
方法3:用mysqladmin修改
mysqladmin -uroot -p原來的密碼 password ‘123456’;
2.MySQL8.0以上版本沒有了password欄位,所以修改root密碼用另外一種方式:
alter user’root’@‘localhost’ identified by ‘123456’;
二.增加新用戶
create user ‘test1’@‘localhost’ identified by ‘123’;
注意這里的test1是新創建用戶的用戶名,123為密碼(可不設定)localhost代表必須在這臺主機上才能登陸,這也是一種比較安全的添加方法,
create user ‘test2’@’%’ identified by ‘123’;
同理這里的test2和123為賬號密碼,%代表在任何主機上都可以訪問這個資料庫,并且進行增刪改查操作,有風險所以不提倡,
三.給新用戶分配權限
首先我們可以查看這個用戶擁有哪些權限:
select * from user where user = ‘test2’;#我們用來查看用戶名為test2的這個用戶擁有哪些權限,

接下來我們給這個用戶分配權限
grant all privileges on . to test2@‘localhost’;#給test2這個用戶分配所有權限,對于所有資料庫,且只能在localhost這臺主機上,
接下來需要重繪權限
flush privileges;
再查詢該用戶的權限
select * from user where user=‘test2’;

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/250170.html
標籤:其他
上一篇:卷積神經網路訓練CIFAR100
