您好,登錄后才能下訂單哦!
這篇文章給大家介紹MySQL數據庫中有哪些基礎操作命令,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
用戶與權限
創建用戶
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';
創建用戶并授權
mysql>grant select,insert,update on student.* to test@localhost identified by 'A1b2c3#!@';
查看授權
mysql> show grants for test@localhost;
移除權限
mysql> revoke insert,update on student.* from test@localhost;
建庫與表
創建庫
mysql> create database student; mysql> show databases;
創建表
mysql> use student; mysql> create table T1 (name varchar(10) not null,sex varchar(10) not null);
通過現有的表創建新表
mysql> create table T2 as select * from T1;
插入數據
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');
查詢數據
查詢數據
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
更新表里的數據
mysql> update T1 set age=25 where name='zhang'; mysql> update T1 set age=23 where name='li';
刪除數據
mysql> delete from T1 where age='22';
建索引與刪除
mysql> create index indexT1 on T1(name(10)); mysql> drop index indexT1 on T1;
主鍵與視圖
創建主鍵
mysql> alter table T1 add primary key(name); mysql> desc T1;
創建與刪除視圖
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 #提示此視圖不存在
關于MySQL數據庫中有哪些基礎操作命令就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。