自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL數(shù)據(jù)庫基礎(chǔ)操作命令

數(shù)據(jù)庫 MySQL
今天給大家介紹的是關(guān)天Mysql數(shù)據(jù)庫一些操作的基礎(chǔ)命令。我們一起來看一下吧。

今天介紹的是關(guān)天Mysql數(shù)據(jù)庫一些操作的基礎(chǔ)命令

用戶與權(quán)限

創(chuàng)建用戶 

  1. mysql>create user test identified by 'BaC321@#'; 

修改密碼

5.5版本及以前的命令 

  1. mysql>set password for test=passowrd('!1A@2#3'); 

5.6及以上命令 

  1. mysql>update mysql.user set authentication_string=password('A1b2c3#!@') where user='test'

創(chuàng)建用戶并授權(quán) 

  1. mysql>grant select,insert,update on student.* to test@localhost identified by 'A1b2c3#!@'; 

查看授權(quán) 

  1. mysql> show grants for test@localhost; 

移除權(quán)限 

  1. mysql> revoke insert,update on student.* from test@localhost; 

建庫與表

創(chuàng)建庫 

  1. mysql> create database student;  
  2. mysql> show databases; 

創(chuàng)建表 

  1. mysql> use student;  
  2. mysql> create table T1 (name varchar(10) not null,sex varchar(10) not null); 

通過現(xiàn)有的表創(chuàng)建新表 

  1. mysql> create table T2 as select * from T1; 

插入數(shù)據(jù) 

  1. mysql> insert into T1 values('zhang','man');  
  2. Query OK, 1 row affected (0.03 sec)  
  3. mysql> insert into T1 values('li','man');  
  4. Query OK, 1 row affected (0.03 sec)  
  5. mysql> insert into T1 values('wang','man');  
  6. Query OK, 1 row affected (0.02 sec)  
  7. mysql> insert into T1 values('zhao','women');  
  8. Query OK, 1 row affected (0.05 sec)  
  9. #需要注意的是如果列超過兩列,就需要指定列字段名如下  
  10. mysql> insert into T1(name,sex) values('gege','man'); 

查詢數(shù)據(jù)

查詢數(shù)據(jù) 

  1. mysql> select user,host from mysql.user;  
  2. #查看用戶  
  3. mysql> select * from T1 where name like '%an%';  
  4. mysql> select * from T1 where age like '2%'; 

匹配查詢

 

  1. mysql> select * from T1 order by name,age; 

查詢排序

 

  1. mysql> select count(*) as toaolcount from T1;  
  2. mysql> select sum(age) as sumvalue from T1;  
  3. mysql> select avg(age) as avgvalue from T1;  
  4. mysql> select max(age) from T1; 

查詢值

 

  1. mysql> select score from T1 where score <91 
  2. mysql> select score from T1 where score >=91;  
  3. mysql> select * from T1 where score in (96,100); 

條件查詢

 

  1. mysql> select * from T2;  
  2. mysql> select * from T1; 

增刪更新

增加與刪除列 

  1. mysql> alter table T1 add age int(4) not null;  
  2. mysql> alter table T1 drop age 

更新表里的數(shù)據(jù) 

  1. mysql> update T1 set age=25 where name='zhang' 
  2. mysql> update T1 set age=23 where name='li'

刪除數(shù)據(jù) 

  1. mysql> delete from T1 where age='22'

建索引與刪除 

  1. mysql> create index indexT1 on T1(name(10));  
  2. mysql> drop index indexT1 on T1; 

主鍵與視圖

創(chuàng)建主鍵 

  1. mysql> alter table T1 add primary key(name);  
  2. mysql> desc T1; 

創(chuàng)建與刪除視圖 

  1. mysql> create view t1view as select name from T1;  
  2. mysql> select * from t1view; 

 

  1. mysql> drop view t1view;  
  2. mysql> select * from t1view;  
  3. ERROR 1146 (42S02): Table 'student.t1view' doesn't exist  
  4. #提示此視圖不存在 

點擊關(guān)注 民工哥技術(shù)之路 微信公眾號對話框回復(fù)關(guān)鍵字:1024 可以獲取一份最新整理的技術(shù)干貨:包括系統(tǒng)運維、數(shù)據(jù)庫、redis、MogoDB、電子書、Java基礎(chǔ)課程、Java實戰(zhàn)項目、架構(gòu)師綜合教程、架構(gòu)師實戰(zhàn)項目、大數(shù)據(jù)、Docker容器、ELK Stack、機器學(xué)習(xí)、BAT面試精講視頻等。 

 

責(zé)任編輯:龐桂玉 來源: segmentfault
相關(guān)推薦

2019-10-12 15:06:02

MySQL數(shù)據(jù)庫命令

2010-06-01 13:20:45

2010-06-01 12:51:23

MySQL數(shù)據(jù)庫

2010-05-11 14:00:01

MySQL數(shù)據(jù)庫命令

2010-11-23 11:04:25

查看MySQL數(shù)據(jù)庫

2009-06-04 15:59:53

Netbeans操作MMySQL數(shù)據(jù)庫

2011-07-01 13:42:24

QT 數(shù)據(jù)庫

2010-06-02 13:03:20

MySQL數(shù)據(jù)庫

2011-07-05 10:16:16

Qt 數(shù)據(jù)庫 SQLite

2021-08-02 09:01:29

PythonMySQL 數(shù)據(jù)庫

2010-05-28 14:51:47

MySQL數(shù)據(jù)庫

2010-05-14 11:12:16

連接MySql

2010-06-01 14:17:44

MySQL重啟命令

2010-10-12 12:00:42

MySQL連接

2011-03-31 16:09:56

Mysql數(shù)據(jù)庫

2010-05-24 16:58:00

MySQL數(shù)據(jù)庫備份

2011-07-05 18:04:45

QT Mysql

2017-10-20 13:59:08

2010-05-28 18:44:45

2018-02-26 20:00:00

編程語言JavaMySQL
點贊
收藏

51CTO技術(shù)棧公眾號