1、 导入hellodb.sql生成数据库
[root@mysql ~]# mysql -uroot -p123456 < hellodb.sql
(1) 在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄
mysql> SELECT name 名字,age 年龄 FROM students WHERE age > 25 AND gender = "m";
(2) 以ClassID为分组依据,显示每组的平均年龄
mysql> SELECT classid,avg(age) FROM students GROUP BY classid;
(3) 显示第2题中平均年龄大于30的分组及平均年龄
mysql> SELECT classid,avg(age) FROM students GROUP BY classid HAVING avg(age) > 30;
(4) 显示以L开头的名字的同学的信息
mysql> SELECT * FROM students WHERE name LIKE 'L%';
2、数据库授权centos用户,允许192.168.1.0/24网段可以连接mysql
mysql> GRANT ALL ON *.* TO 'centos'@'192.168.1.%'IDENTIFIED BY '123456';