数据库的增删改查,授权和取消授权

数据库的创建修改删除

CREATE  DATABASE  XXX;        #建立库
CREATE  DATABASE  XXX;        #建立库    
USE     XXX;           # 进入库
CREATE TABLE zwy1(id int not null,name varchar(60) null,age tinyint);
             #建立表
INSERT INTO zwy1 values(8,‘Tom‘,‘123‘); #插入数据

ALTER TABLE zwy1 RENAME zwy; #更改表名字
ALTER TABLE zwy ADD class varchar(20); #添加class这一列
ALTER TABLE zwy DROP class; #删除class


delete from zwy where id=6; #删除某条数据

delete from zwy; #删除整张表



 数据库的授权

CREATE USER zwy@192.168.58.128 IDENTIFIED BY 123456;  #数据库的用户创建
DROP USER zwy@192.168.58.128; #删除数据库用户
GRANT SELECT,INSERT on test.* TO zwy@192.168.58.128; #授权查找插入给zwy用户test下面的所有表
SHOW GRANTS FOR zwy@192.168.58.128; #查看所有的授权信息
REVOKE select,insert on test.* from zwy@192.168.58.128; #收回用户的查找插入权限

数据库的查询

SHOW DATABASES;                            显示数据库
USE    库名称;                    进入哪一个库
SHOW        TABLES;                显示表        
DESC        表名称;                显示表结构
SELECT * FROM 表名称;                            显示表信息
SELECT  字段1,字段2,...from 表名称where 字段=‘字段值’;    查询数据

MariaDB [test]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.000 sec)

MariaDB [test]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]

 

MariaDB [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| zwy1 |
+----------------+
1 row in set (0.000 sec)

MariaDB [test]> desc zwy1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | | NULL | |
| name | varchar(60) | YES | | NULL | |
| age | tinyint(4) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.009 sec)

MariaDB [test]> select * from zwy1;
+----+----------+------+
| id | name | age |
+----+----------+------+
| 1 | zhangsan | 21 |
| 2 | lisi | 22 |
| 3 | wangwu | 23 |
| 4 | xyq | 24 |
| 5 | zwy | 24 |
| 6 | cyx | 24 |
+----+----------+------+
6 rows in set (0.007 sec)

 

MariaDB [test]> select name,age from zwy1 where id=‘4‘;
+------+------+
| name | age |
+------+------+
| xyq | 24 |
+------+------+
1 row in set (0.128 sec)

 

------------恢复内容结束------------

数据库的增删改查,授权和取消授权

上一篇:mongodb的时间范围操作


下一篇:sqlalchemy中的literal 为查询结果增加一个常量值