1柱嫌、 導入hellodb.sql生成數(shù)據(jù)庫
(1) 在students表中,查詢年齡大于25歲,且為男性的同學的名字和年齡
MariaDB [hellodb]> select name,age from students where age > 25 and gender = 'm';
+--------------+-----+
| name | age |
+--------------+-----+
| Xie Yanke | 53 |
| Ding Dian | 32 |
| Yu Yutong | 26 |
| Shi Qing | 46 |
| Tian Boguang | 33 |
| Xu Xian | 27 |
| Sun Dasheng | 100 |
+--------------+-----+
(2) 以ClassID為分組依據(jù),顯示每組的平均年齡
MariaDB [hellodb]> select classid,avg(age) from students group by classid;
+---------+----------+
| classid | avg(age) |
+---------+----------+
| NULL | 63.5000 |
| 1 | 20.5000 |
| 2 | 36.0000 |
| 3 | 20.2500 |
| 4 | 24.7500 |
| 5 | 46.0000 |
| 6 | 20.7500 |
| 7 | 19.6667 |
+---------+----------+
8 rows in set (0.00 sec)
(3) 顯示第2題中平均年齡大于30的分組及平均年齡
MariaDB [hellodb]> select classid,avg(age) as avg from students group by classid having avg >30;
+---------+---------+
| classid | avg |
+---------+---------+
| NULL | 63.5000 |
| 2 | 36.0000 |
| 5 | 46.0000 |
+---------+---------+
3 rows in set (0.00 sec)
(4) 顯示以L開頭的名字的同學的信息
MariaDB [hellodb]> select * from students WHERE name LIKE 'L%';
+-------+-------------+-----+--------+---------+-----------+
| StuID | Name | Age | Gender | ClassID | TeacherID |
+-------+-------------+-----+--------+---------+-----------+
| 8 | Lin Daiyu | 17 | F | 7 | NULL |
| 14 | Lu Wushuang | 17 | F | 3 | NULL |
| 17 | Lin Chong | 25 | M | 4 | NULL |
+-------+-------------+-----+--------+---------+-----------+
3 rows in set (0.01 sec)
2拆内、數(shù)據(jù)庫授權(quán)magedu用戶,允許192.168.1.0/24網(wǎng)段可以連接mysql
MariaDB [mysql]> create user magedu@'192.168.1.0/24' identified by '12321';
Query OK, 0 rows affected (0.00 sec)
3宠默、總結(jié)mysql常見的存儲引擎以及特點矛纹。
如圖所示
MyISAM 擴展性好
每個MyISAM表都以三個文件存儲在磁盤上。這些文件的名稱以表名開頭光稼,并具有擴展名以指示文件類型或南。一個.frm 文件存儲表格式。數(shù)據(jù)文件的 擴展名為.MYD(MYData)艾君。索引文件的擴展名為.MYI (MYIndex)采够。
要明確指定您想要一個MyISAM 表,請使用ENGINE表選項進行指示:創(chuàng)建表t(i INT)引擎= MYISAM;
InnoDB 并發(fā)性好
InnoDB
:自MySQL 5.5.5起默認的存儲引擎冰垄。InnoDB
是用于MySQL的事務安全(兼容ACID)的存儲引擎蹬癌,具有提交,回滾和崩潰恢復功能以保護用戶數(shù)據(jù)虹茶。InnoDB
行級鎖定(無需升級為更粗粒度的鎖定)和Oracle風格的一致非鎖定讀取可提高多用戶并發(fā)性和性能逝薪。InnoDB
將用戶數(shù)據(jù)存儲在聚集索引中,以減少基于主鍵的常見查詢的I / O蝴罪。為了保持數(shù)據(jù)完整性董济,InnoDB
還支持FOREIGN KEY
引用完整性約束