溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

數(shù)據(jù)庫基本使用

發(fā)布時間:2020-07-31 05:27:05 來源:網(wǎng)絡(luò) 閱讀:410 作者:阿德001 欄目:MySQL數(shù)據(jù)庫

1.登錄和退出mysql服務(wù)器
mysql -h主機名 -u用戶名 -p密碼 -e"sql 命令"
例1:mysql -uroot -p123456 #root用戶,密碼123456登錄數(shù)據(jù)庫。
例2:mysql -uroot -p123456 -e "desc mysql.user" #root用戶,密碼123456登錄并查看user表結(jié)構(gòu)。
例3:mysql -uroot -p123456 mysql #root用戶,密碼123456登錄并直接進入mysql數(shù)據(jù)庫。
2.新建普通用戶:
2.1使用create user語句創(chuàng)建新用戶。
例: create user zhangsan@localhost identified by "132456"; #創(chuàng)建用戶張三,指定密碼為123456.
例: create user zhangsan@"%" identified by "123456"; #創(chuàng)建用戶張三,指定密碼為123456.
2.2使用grant 語句創(chuàng)建用戶:
例:grant all on . to zhangsan@localhost identified by "123456"; #創(chuàng)建張三用戶并授予對所有數(shù)據(jù)庫的所有表的所有權(quán)限。
select from mysql.user where user='zhangsan'\G; #查看zhangsan用戶的信息,權(quán)限都為 y。
3.刪除普通用戶:
3.1 例:drop mysql.user zhangsan@localhost; #刪除用戶zhangsan;
3.2 例:delete from mysql.user where user='zhangsan'; #刪除用戶zhangsan。
4.root用戶修改自己密碼:
4.1 mysqladmin -uroot -p123456 password '654321' #命令行修改,-p指定舊密碼,引號里為新密碼。
4.2 update mysql.user set password=password('123456') where user='root'; flush privileges; #把root用戶密碼該為123456;刷新權(quán)限表。
4.3 set password=password('654321'); #修改root用戶密碼為123456;
5.root用戶修改普通用戶密碼:
5.1 set password for zhangsan@localhost = password('123456'); #修改zhangsan密碼為123456.
5.2 update mysql.user set password=password('123456') where user='zhangsan';flush privileges; #修改zhangsan用戶的密碼為123456;刷新權(quán)限表。
5.3 grant usage on
.* to zhangsan@localhost identified by '123456'; #修改zhangsan用戶密碼為123456;

  1. 普通用戶修改密碼:
    6.1 set password=password('123456'); #使用普通用戶登錄數(shù)據(jù)庫,執(zhí)行命令。
    7.root用戶密碼丟失的解決辦法:
    7.1 修改配置文件/etc/my.cnf 在【mysql】下添加 skip-grant-tables
    7.2 systemctl restart mariadb #重啟服務(wù)
    7.3 mysql #登錄數(shù)據(jù)庫
    7.4 set password=password('123456'); #修改密碼
    7.5 vim /etc/my.cnf 注釋掉 #skip-grant-tables
    7.6 systemctl restart mariadb #重啟服務(wù)
    8.localhost 為本地登錄 “%” 為遠程登錄
向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI