系统相关
首页 > 系统相关> > Linux入门(十四)

Linux入门(十四)

作者:互联网

1、 导入hellodb.sql生成数据库
(1) 在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄

MariaDB [hellodb]> select Name,Age from students where Age>25 and Gender='M';
+--------------+-----+
| Name | Age |
+--------------+-----+
| Xie Yanke | 53 |
| Ding Dian | 32 |
| Yu Yutong | 26 |
| Shi Qing | 46 |
| Tian Boguang | 33 |
| Xu Xian | 27 |
| Sun Dasheng | 100 |
+--------------+-----+
7 rows in set (0.001 sec)

 

(2) 以ClassID为分组依据,显示每组的平均年龄

MariaDB [hellodb]> select ClassID,avg(Age) from students group by ClassID;
+---------+----------+
| ClassID | avg(Age) |
+---------+----------+
| NULL | 63.5000 |
| 1 | 20.5000 |
| 2 | 36.0000 |
| 3 | 20.2500 |
| 4 | 24.7500 |
| 5 | 46.0000 |
| 6 | 20.7500 |
| 7 | 19.6667 |
+---------+----------+
8 rows in set (0.001 sec)

 

(3) 显示第2题中平均年龄大于30的分组及平均年龄

MariaDB [hellodb]> select ClassID,avg(Age) from students group by ClassID HAVING avg(Age)>30;
+---------+----------+
| ClassID | avg(Age) |
+---------+----------+
| NULL | 63.5000 |
| 2 | 36.0000 |
| 5 | 46.0000 |
+---------+----------+
3 rows in set (0.001 sec)

 

(4) 显示以L开头的名字的同学的信息

MariaDB [hellodb]> select * from students where Name like 'L%';
+-------+-------------+-----+--------+---------+-----------+
| StuID | Name | Age | Gender | ClassID | TeacherID |
+-------+-------------+-----+--------+---------+-----------+
| 8 | Lin Daiyu | 17 | F | 7 | NULL |
| 14 | Lu Wushuang | 17 | F | 3 | NULL |
| 17 | Lin Chong | 25 | M | 4 | NULL |
+-------+-------------+-----+--------+---------+-----------+
3 rows in set (0.001 sec)

 

2、数据库授权magedu用户,允许192.168.1.0/24网段可以连接mysql

MariaDB [(none)]> GRANT ALL ON *.* TO 'magedu'@'192.168.1.0/24' IDENTIFIED BY 'magedu';

 

3、总结mysql常见的存储引擎以及特点。

  特点 场景
MyISAM

不支持事务
表级锁定
读写相互阻塞
不支持外键约束、聚簇索引

只读
表较小

InnoDB

支持事务
行级锁
读写阻塞与事务隔离级别相关
支持外键、聚簇索引

mysql5.5.5之后的默认引擎
Memory 存放在RAM中  
Archive

只支持SELECT和INSERT操作
支持行级锁和专用缓存区

为存储和检索大量很少参考的存档或安全审核信息

 

标签:ClassID,avg,入门,Age,NULL,Linux,十四,MariaDB,+---------+----------+
来源: https://www.cnblogs.com/ljt-lam/p/14096242.html