這篇文章給大家介紹MySQL數(shù)據(jù)庫中有哪些基礎(chǔ)操作命令,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
“只有客戶發(fā)展了,才有我們的生存與發(fā)展!”這是創(chuàng)新互聯(lián)建站的服務(wù)宗旨!把網(wǎng)站當作互聯(lián)網(wǎng)產(chǎn)品,產(chǎn)品思維更注重全局思維、需求分析和迭代思維,在網(wǎng)站建設(shè)中就是為了建設(shè)一個不僅審美在線,而且實用性極高的網(wǎng)站。創(chuàng)新互聯(lián)對成都網(wǎng)站設(shè)計、成都做網(wǎng)站、網(wǎng)站制作、網(wǎng)站開發(fā)、網(wǎng)頁設(shè)計、網(wǎng)站優(yōu)化、網(wǎng)絡(luò)推廣、探索永無止境。
用戶與權(quán)限
創(chuàng)建用戶
mysql>create user test identified by 'BaC321@#';
修改密碼
5.5版本及以前的命令
mysql>set password for test=passowrd('!1A@2#3');
5.6及以上命令
mysql>update mysql.user set authentication_string=password('A1b2c3#!@') where user='test';
創(chuàng)建用戶并授權(quán)
mysql>grant select,insert,update on student.* to test@localhost identified by 'A1b2c3#!@';
查看授權(quán)
mysql> show grants for test@localhost;
移除權(quán)限
mysql> revoke insert,update on student.* from test@localhost;
建庫與表
創(chuàng)建庫
mysql> create database student; mysql> show databases;
創(chuàng)建表
mysql> use student; mysql> create table T1 (name varchar(10) not null,sex varchar(10) not null);
通過現(xiàn)有的表創(chuàng)建新表
mysql> create table T2 as select * from T1;
插入數(shù)據(jù)
mysql> insert into T1 values('zhang','man'); Query OK, 1 row affected (0.03 sec) mysql> insert into T1 values('li','man'); Query OK, 1 row affected (0.03 sec) mysql> insert into T1 values('wang','man'); Query OK, 1 row affected (0.02 sec) mysql> insert into T1 values('zhao','women'); Query OK, 1 row affected (0.05 sec) #需要注意的是如果列超過兩列,就需要指定列字段名如下 mysql> insert into T1(name,sex) values('gege','man');
查詢數(shù)據(jù)
查詢數(shù)據(jù)
mysql> select user,host from mysql.user; #查看用戶 mysql> select * from T1 where name like '%an%'; mysql> select * from T1 where age like '2%';
匹配查詢
mysql> select * from T1 order by name,age;
查詢排序
mysql> select count(*) as toaolcount from T1; mysql> select sum(age) as sumvalue from T1; mysql> select avg(age) as avgvalue from T1; mysql> select max(age) from T1;
查詢值
mysql> select score from T1 where score <91; mysql> select score from T1 where score >=91; mysql> select * from T1 where score in (96,100);
條件查詢
mysql> select * from T2; mysql> select * from T1;
增刪更新
增加與刪除列
mysql> alter table T1 add age int(4) not null; mysql> alter table T1 drop age
更新表里的數(shù)據(jù)
mysql> update T1 set age=25 where name='zhang'; mysql> update T1 set age=23 where name='li';
刪除數(shù)據(jù)
mysql> delete from T1 where age='22';
建索引與刪除
mysql> create index indexT1 on T1(name(10)); mysql> drop index indexT1 on T1;
主鍵與視圖
創(chuàng)建主鍵
mysql> alter table T1 add primary key(name); mysql> desc T1;
創(chuàng)建與刪除視圖
mysql> create view t1view as select name from T1; mysql> select * from t1view;
mysql> drop view t1view; mysql> select * from t1view; ERROR 1146 (42S02): Table 'student.t1view' doesn't exist #提示此視圖不存在
關(guān)于MySQL數(shù)據(jù)庫中有哪些基礎(chǔ)操作命令就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。