linux学习之数据库

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";
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容