溫馨提示×

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

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

mysql數(shù)據(jù)庫(kù)的常用命令操作

發(fā)布時(shí)間:2020-06-03 14:21:34 來(lái)源:網(wǎng)絡(luò) 閱讀:240 作者:三月 欄目:MySQL數(shù)據(jù)庫(kù)

下文我給大家簡(jiǎn)單講講關(guān)于mysql數(shù)據(jù)庫(kù)的常用命令操作,大家之前了解過(guò)相關(guān)類似主題內(nèi)容嗎?感興趣的話就一起來(lái)看看這篇文章吧,相信看完mysql數(shù)據(jù)庫(kù)的常用命令操作對(duì)大家多少有點(diǎn)幫助吧。

善用help 幫助

掌握基本的增刪改查,建庫(kù)建表索引比較常用

基礎(chǔ)的增刪改查、創(chuàng)建和刪除
show databases;  查看庫(kù)
show tables;         查看表
select database();查看當(dāng)前數(shù)據(jù)庫(kù)
select now();        查看當(dāng)前時(shí)間
select user();       查看當(dāng)前用戶
庫(kù)操作:
create database dddd character set gbk collate gbk_chinese_ci; 創(chuàng)建gbk字符的dddd庫(kù)
show create database dddd\G  查看建庫(kù)語(yǔ)句,庫(kù)的字符權(quán)限等
drop database dddd;  刪除數(shù)據(jù)庫(kù)dddd
表操作:
create table dong( id int(4) not null,name char(10) not null ); 創(chuàng)建dong表
show create table dong\G  查看建表語(yǔ)句
desc table_name; 查詢表結(jié)構(gòu)
drop table(s) table_name; 刪除表
insert into table_name(lie,lie,lie) values(1,2,3); 向表中插入數(shù)據(jù)
delete from table where id=1 and name="dongshizhang";刪除表中數(shù)據(jù),可根據(jù)where條件
可+ U啟動(dòng)數(shù)據(jù)庫(kù) 防止誤操作(可設(shè)置別名 alias)
truncate table_name 清空表
修改字段類型、字段名稱
alter table table_name modify|change
rename table_name name to name1;  修改表名

用戶授權(quán):
grant all on . to user@"%" identified by '111111'; 授權(quán)用戶
show grants for user@‘localhost’;查看用戶授權(quán)
revoke insert user@‘localhost’; 刪除用戶指定權(quán)限

關(guān)于索引:
alter table ling change id id int primary key auto_increment;  增加自增主鍵
atler table student drop peimary key;  刪除主鍵(帶有auto_increment自增主鍵需先刪除自增)
alter table table_name modify id int ; 【修改列類型】
create unique index index_index on 表(age); 創(chuàng)建唯一索引(就是在index前增加一個(gè)unique)
atler table student add index index_name(name(8)); name列創(chuàng)建普通索引
create index index_name on student(name(8);  根據(jù)name列的前N個(gè)字符創(chuàng)建索引
create index inde_name_dept on student(name,dept); 根據(jù)多個(gè)列創(chuàng)建聯(lián)合索引
alter table student drop index index_name; 刪除索引
drop index index_name on 表; 刪除索引
create index index_name on 表(age); 創(chuàng)建索引
聯(lián)合索引的創(chuàng)建和普通索引創(chuàng)建差不多,
聯(lián)合索引有前綴生效特性
index(a,b,c) 僅a,ab,abc三個(gè)查詢條件可以走索引,b,bc,ac,c等無(wú)法使用索引

數(shù)據(jù)庫(kù)慢查詢
mysql -uroot -p"passwd" -h227.0.0.1 -e "show processlist;"|grep slow 查詢數(shù)據(jù)庫(kù)慢查詢
show databases like '指定字段查詢庫(kù)';

system echo $LANG 到數(shù)據(jù)庫(kù)外面執(zhí)行命令

庫(kù)表備份

mysqldump -u -p -B 庫(kù)名 >/root/    將庫(kù)備份到指定位置
grep -E -v "#|\/|^$|--" ./lingling_utf8.sql   查看備份的庫(kù)內(nèi)容

mysqladmin -uroot -p flush-log 日志切割

大家覺(jué)得mysql數(shù)據(jù)庫(kù)的常用命令操作這篇文章怎么樣,是否有所收獲。如果想要了解更多相關(guān),可以繼續(xù)關(guān)注我們的行業(yè)資訊板塊。

向AI問(wèn)一下細(xì)節(jié)

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

AI