一、导入hellodb.sql生成数据库
MariaDB [(none)]> source /root/hellodb.sql
(1) 在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄
MariaDB [hellodb]> select Name,Age from students where Age>25 and Gender='M';
(2) 以ClassID为分组依据,显示每组的平均年龄
MariaDB [hellodb]> select classid,avg(age) from students group by classid;
(3) 显示第2题中平均年龄大于30的分组及平均年龄
MariaDB [hellodb]> select classid,avg(age) as age from students group by classid having age > 30;
(4) 显示以L开头的名字的同学的信息
MariaDB [hellodb]> select * from students where name like 'L%';
二、数据库授权magedu用户,允许192.168.1.0/24网段可以连接mysql
MariaDB [(none)]> CREATE USER 'magedu'@'192.168.1.%' IDENTIFIED BY 'magedu';
三、总结mysql常见的存储引擎以及特点。
1.MyISAM
是MySQL5.5版之前默认的存储引擎,特点:数据文件和索引文件可以放置在不同的目录,平局分布IO,获得更快的速度。不支持事务,不支持外键。
2.InnoDB
是 MySQL5.5版之后默认的存储引擎,特点:支撑外键支持实物安全。比MyISAM写处理效率差。并会占用更多空间以保留数据和索引。
3.MEMORY
是使用存在内存中的内容来创建表。MEMORY访问速度非常的快,因为他的数据是放在内存中的。并且默认使用HASH索引。
一旦服务关闭,表中的数据就会丢失;它的缺陷就是对表的大小有限制。太大的无法缓存在内存中,其次是要确保表的数据可以恢复。