Exercises and summary of the database

1. Import hellodb.sql to generate database

(1) In the students table, query the names and ages of male students who are older than 25 years old
(2) Use ClassID as the grouping basis to show the average age of each group
(3) Show that the average age in question 2 is greater than 30 Groups and average age
(4) Display information of classmates whose names begin with L

# 导入hellodb.sql
mysql -uroot -p < hellodb_innodb.sql

# 在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄
use hellodb;
select name as 姓名,age as 年龄 from students where age > 25 and gender='M';

# 以ClassID为分组依据,显示每组的平均年龄
select ClassID as 班级,avg(Age) as 平均年龄 from students group by Classid;

# 显示第2题中平均年龄大于30的分组及平均年龄
select ClassID as 班级,avg(Age) as 平均年龄 from students group by Classid having avg(Age) > 30;

# 显示以L开头的名字的同学的信息
select *  from students where name like 'L%';

2. The database authorizes magedu users to allow the 192.168.1.0/24 network segment to connect to mysql

# 创建magedu用户并且设定密码
create user magedu@'192.168.1.%' identified by '123456';

# 在另一台CentOS虚拟机登录数据库进行验证
mysql -umagedu -p123456 -h192.168.1.12

# 使用hellodb数据库
use hellodb;

3. Common storage engines and characteristics of mysql

The most common storage engines for MySQL include InnoDB, MyISAM

Features of InnoDB storage engine:

  • Support affairs, suitable for handling a large number of short-term affairs
  • Support row-level lock, performance is better than table-level lock
  • Cacheable data and index
  • With crash repair capabilities and concurrency control
  • Support foreign keys
  • Support clustered index
  • Low data insertion speed

Features of MyISAM storage engine:

  • Does not support transactions
  • Only supports table-level locks, not row-level locks
  • Read and write block each other, write cannot read, and cannot write while reading
  • Only cache index
  • Does not support foreign key constraints
  • Does not support clustered indexes
  • Read data faster
  • Does not support MVCC (multi-version concurrency control mechanism) high concurrency
  • Poor crash recovery

Guess you like

Origin blog.51cto.com/14920534/2605439