真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

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

SQL語句概述

SQL語言

  • 是Structured Query Language的縮寫,即結(jié)構(gòu)化查詢語言
  • 是關(guān)系型數(shù)據(jù)庫的標(biāo)準(zhǔn)語言
  • 用于維護管理數(shù)據(jù)庫,如數(shù)據(jù)查詢、數(shù)據(jù)更新、訪問控制、對象管理等功能

SQL分類

(1)DDL:數(shù)據(jù)定義語言
(2)DML:數(shù)據(jù)操縱語言
(3)DQL:數(shù)據(jù)查詢語言
(4)DCL:數(shù)據(jù)控制語言

創(chuàng)新互聯(lián)建站專注于蓮池企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站設(shè)計,商城網(wǎng)站建設(shè)。蓮池網(wǎng)站建設(shè)公司,為蓮池等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站建設(shè),專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)

DDL操作命令

1、DDL語句用于創(chuàng)建數(shù)據(jù)庫對象,如庫、表、索引等

2、使用DDL語句新建庫、表

(1)創(chuàng)建數(shù)據(jù)庫:creste databaes 數(shù)據(jù)庫名
(2)創(chuàng)建數(shù)據(jù)表:create table 表名 (字段定義……)

3、使用DDL語句刪除庫、表

(1)刪除指定的數(shù)據(jù)表:drop table [數(shù)據(jù)庫名]表名
(2)刪除指定的數(shù)據(jù)庫:drop database 數(shù)據(jù)庫名

DML操作命令

1、DML語句用于對表中的數(shù)據(jù)進行管理

2、包括以下操作

(1)insert:插入新數(shù)據(jù)
(2)update:更新原有數(shù)據(jù)
(3)delete:刪除不需要的數(shù)據(jù)

3、向數(shù)據(jù)表中插入新的數(shù)據(jù)記錄

insert into 表名(字段1,字段2, .....) values(字段1的值,字段的值, .....)

4、修改、更新數(shù)據(jù)表P F的數(shù)據(jù)記錄

update 表名 set 字段名1=值1[,字段名2=值2] where 條件表達式

5、在數(shù)據(jù)表中刪除指定的數(shù)據(jù)記錄

(1)delete from 表名 where 條件表達式
(2)不帶where條件的語句表示刪除表中所有記錄(謹慎操作)

DQL操作命令

1、DQL是數(shù)據(jù)查詢語句,只有一條: SELECT

2、用于從數(shù)據(jù)表中查找符合條件的數(shù)據(jù)記錄

3、查詢時可不指定條件

selext 字段名1,字段名2..... from 表名;

4、查詢時指定條件

select 字段名1,字段名2.... from 表名 where 條件表達式;

DCL語句操作

1、設(shè)置用戶權(quán)限(用戶不存在時,則新建用戶)

GRANT 權(quán)限列表 ON 數(shù)據(jù)庫名.表名 TO 用戶名@來源地址 [ IDENTIFIED BY‘密碼’ ]

2、查看用戶的權(quán)限

SHOW GRANTS FOR 用戶名@來源地址

3、撤銷用戶的權(quán)限

REVOKE 權(quán)限列表 ON 數(shù)據(jù)庫名.表名 FROM 用戶名@來源地址

操作實例

1、查看數(shù)據(jù)庫列表信息

MySQL> show databases;    //查看數(shù)據(jù)庫列表信息
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |                     //其中mysql為系統(tǒng)數(shù)據(jù)庫
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.02 sec)

2、創(chuàng)建數(shù)據(jù)庫

mysql> create database school;    //創(chuàng)建數(shù)據(jù)庫school
Query OK, 1 row affected (0.02 sec)

mysql> show databases;      //查看數(shù)據(jù)庫列表信息
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| school             |                //成功創(chuàng)建數(shù)據(jù)庫
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> 

3、創(chuàng)建表

mysql> 
mysql> use school;   //使用數(shù)據(jù)庫school
Database changed
mysql> show tables;
Empty set (0.00 sec)

mysql> create table info (
    -> id int(4) not null,
    -> name char(10) not null,
    -> address varchar(50) default 'beijing',
    -> score decimal,
    -> primary key(id));   //創(chuàng)建表info
Query OK, 0 rows affected (0.01 sec)

mysql> describe info;   //查看表結(jié)構(gòu)
+---------+---------------+------+-----+---------+-------+
| Field   | Type          | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+-------+
| id      | int(4)        | NO   | PRI | NULL    |       |
| name    | char(10)      | NO   |     | NULL    |       |
| address | varchar(50)   | YES  |     | beijing |       |
| score   | decimal(10,0) | YES  |     | NULL    |       |
+---------+---------------+------+-----+---------+-------+
4 rows in set (0.03 sec)

4、表中添加數(shù)據(jù)與查看表中數(shù)據(jù)

mysql> 
mysql> insert into info (id,name,address,score) values (1,'stu01','shanghai',88);   //添加數(shù)據(jù)
Query OK, 1 row affected (0.03 sec)

mysql> insert into info (id,name,address,score) values (2,'stu02','nanjing',79);   //添加數(shù)據(jù)
Query OK, 1 row affected (0.01 sec)

mysql> insert into info (id,name,address,score) values (3,'stu03',default,90);   //添加數(shù)據(jù)
Query OK, 1 row affected (0.00 sec)

mysql> insert into info (id,name,address,score) values (4,'stu04','',60);   //添加數(shù)據(jù)
Query OK, 1 row affected (0.00 sec)

mysql> select * from info;    //查看info表中數(shù)據(jù)
+----+-------+----------+-------+
| id | name  | address  | score |
+----+-------+----------+-------+
|  1 | stu01 | shanghai |    88 |
|  2 | stu02 | nanjing  |    79 |
|  3 | stu03 | beijing  |    90 |
|  4 | stu04 |          |    60 |
+----+-------+----------+-------+
4 rows in set (0.00 sec)

5、修改與刪除表中數(shù)據(jù)

mysql> update info set address='hangzhou' where id=4 and name='stu04';   //修改id為4的address為“hangzhou”
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from info;   //查看表中數(shù)據(jù)
+----+-------+----------+-------+
| id | name  | address  | score |
+----+-------+----------+-------+
|  1 | stu01 | shanghai |    88 |
|  2 | stu02 | nanjing  |    79 |
|  3 | stu03 | beijing  |    90 |
|  4 | stu04 | hangzhou |    60 |
+----+-------+----------+-------+
4 rows in set (0.01 sec)

mysql> delete from info where name='stu04';   //刪除表中name為“stu04”的數(shù)據(jù)
Query OK, 1 row affected (0.02 sec)

mysql> select * from info;   //查看表中數(shù)據(jù)
+----+-------+----------+-------+
| id | name  | address  | score |
+----+-------+----------+-------+
|  1 | stu01 | shanghai |    88 |
|  2 | stu02 | nanjing  |    79 |
|  3 | stu03 | beijing  |    90 |
+----+-------+----------+-------+
3 rows in set (0.00 sec)

6、刪除表和數(shù)據(jù)庫

mysql> drop table info;   //刪除表info
Query OK, 0 rows affected (0.06 sec)

mysql> show tables;   //查看表,刪除成功
Empty set (0.00 sec)

mysql> drop database school;   //刪除數(shù)據(jù)庫
Query OK, 0 rows affected (0.04 sec)

mysql> show databases;   //查看數(shù)據(jù)庫,刪除成功
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

7、設(shè)置、查看與撤銷用戶權(quán)限

mysql> show grants for 'root'@'%';   //查看權(quán)限
+-------------------------------------------------------------+
| Grants for root@%                                           |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> revoke all on *.* from 'root'@'%';   //刪除權(quán)限
Query OK, 0 rows affected (0.03 sec)

mysql> show grants for 'root'@'%';   //查看權(quán)限
+----------------------------------------------------+
| Grants for root@%                                  |
+----------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'%' WITH GRANT OPTION |
+----------------------------------------------------+
1 row in set (0.00 sec)

mysql> grant all on *.* to root@'%' identified by 'abc123';   //添加權(quán)限
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show grants for 'root'@'%';   //查看權(quán)限
+-------------------------------------------------------------+
| Grants for root@%                                           |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> 

網(wǎng)站標(biāo)題:MySQL數(shù)據(jù)庫管理
網(wǎng)頁路徑:http://weahome.cn/article/jjjooc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部