(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ù)
(1)創(chuàng)建數(shù)據(jù)庫:creste databaes 數(shù)據(jù)庫名
(2)創(chuàng)建數(shù)據(jù)表:create table 表名 (字段定義……)
(1)刪除指定的數(shù)據(jù)表:drop table [數(shù)據(jù)庫名]表名
(2)刪除指定的數(shù)據(jù)庫:drop database 數(shù)據(jù)庫名
(1)insert:插入新數(shù)據(jù)
(2)update:更新原有數(shù)據(jù)
(3)delete:刪除不需要的數(shù)據(jù)
insert into 表名(字段1,字段2, .....) values(字段1的值,字段的值, .....)
update 表名 set 字段名1=值1[,字段名2=值2] where 條件表達式
(1)delete from 表名 where 條件表達式
(2)不帶where條件的語句表示刪除表中所有記錄(謹慎操作)
selext 字段名1,字段名2..... from 表名;
select 字段名1,字段名2.... from 表名 where 條件表達式;
GRANT 權(quán)限列表 ON 數(shù)據(jù)庫名.表名 TO 用戶名@來源地址 [ IDENTIFIED BY‘密碼’ ]
SHOW GRANTS FOR 用戶名@來源地址
REVOKE 權(quán)限列表 ON 數(shù)據(jù)庫名.表名 FROM 用戶名@來源地址
MySQL> show databases; //查看數(shù)據(jù)庫列表信息
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql | //其中mysql為系統(tǒng)數(shù)據(jù)庫
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
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>
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)
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)
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)
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)
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>