(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>
分享文章:MySQL数据库管理
本文来源:https://www.cdcxhl.com/article2/jjjooc.html
成都网站建设公司_创新互联,为您提供手机网站建设、企业网站制作、做网站、品牌网站设计、移动网站建设、用户体验
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联