1.将数据库文件拷贝到mysql
mysql -uroot < ~/hellodb_innodb.sql
mysql
show database;
2.在student表中查询年龄大于25岁,且为男性的同学的名字和年龄
use hellodb;
show tables;
select * from students;
select Name as 名字,Age as 年龄 from students where Age >25 and Gender = 'M';
3.以classID为分组依据,显示每组平均年龄
select ClassID as 班级号 ,avg(Age) as 平均年龄 from students group by ClassID;
4.显示第2题中平均年龄大于30的分组及平均年龄
select ClassID as 班级号,avg(Age) as 平均年龄 from students group by ClassID having avg(Age) > 30;
5.显示以L开头的名字的同学的信息
select * from students;
select * from students where Name like 'L%';
6.数据库授权magedu用户,允许10.0.0.0/24网段可以连接mysql
use mysql;
create user 'magedu'@'10.0.0.%' identified by "123456";
grant all on mysql.* to magedu@'10.0.0.%' identified by "123456";