(1)DDL:数据定义语言
(2)DML:数据操纵语言
(3)DQL:数据查询语言
(4)DCL:数据控制语言
(1)创建数据库:creste databaes 数据库名
(2)创建数据表:create table 表名 (字段定义……)
(1)删除指定的数据表:drop table [数据库名]表名
(2)删除指定的数据库:drop database 数据库名
(1)insert:插入新数据
(2)update:更新原有数据
(3)delete:删除不需要的数据
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 权限列表 ON 数据库名.表名 TO 用户名@来源地址 [ IDENTIFIED BY‘密码’ ]
SHOW GRANTS FOR 用户名@来源地址
REVOKE 权限列表 ON 数据库名.表名 FROM 用户名@来源地址
mysql> show databases; //查看数据库列表信息
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql | //其中mysql为系统数据库
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.02 sec)
mysql> create database school; //创建数据库school
Query OK, 1 row affected (0.02 sec)
mysql> show databases; //查看数据库列表信息
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| school | //成功创建数据库
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>
mysql>
mysql> use school; //使用数据库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)); //创建表info
Query OK, 0 rows affected (0.01 sec)
mysql> describe info; //查看表结构
+---------+---------------+------+-----+---------+-------+
| 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); //添加数据
Query OK, 1 row affected (0.03 sec)
mysql> insert into info (id,name,address,score) values (2,'stu02','nanjing',79); //添加数据
Query OK, 1 row affected (0.01 sec)
mysql> insert into info (id,name,address,score) values (3,'stu03',default,90); //添加数据
Query OK, 1 row affected (0.00 sec)
mysql> insert into info (id,name,address,score) values (4,'stu04','',60); //添加数据
Query OK, 1 row affected (0.00 sec)
mysql> select * from info; //查看info表中数据
+----+-------+----------+-------+
| 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; //查看表中数据
+----+-------+----------+-------+
| 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”的数据
Query OK, 1 row affected (0.02 sec)
mysql> select * from info; //查看表中数据
+----+-------+----------+-------+
| 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; //删除数据库
Query OK, 0 rows affected (0.04 sec)
mysql> show databases; //查看数据库,删除成功
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> show grants for 'root'@'%'; //查看权限
+-------------------------------------------------------------+
| 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'@'%'; //删除权限
Query OK, 0 rows affected (0.03 sec)
mysql> show grants for 'root'@'%'; //查看权限
+----------------------------------------------------+
| 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'; //添加权限
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show grants for 'root'@'%'; //查看权限
+-------------------------------------------------------------+
| Grants for root@% |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。