Linux-6-作业练习
1. 通过编译、二进制安装MySQL5.7
请移步:https://www.cnblogs.com/lyj1023/p/16252556.html
2. 二进制安装mariadb10.4
请移步:https://www.cnblogs.com/lyj1023/p/16262486.html
3. 导入hellodb.sql生成数据库

[root@centos8-liyj ~]#mysql -uroot -patech123456 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 21 Server version: 10.4.24-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases -> ; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 3 rows in set (0.000 sec) MariaDB [(none)]> source /root/hellodb_innodb.sql MariaDB [hellodb]> show databases; +--------------------+ | Database | +--------------------+ | hellodb | | information_schema | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.000 sec) MariaDB [hellodb]> use hellodb Database changed MariaDB [hellodb]> show tables; +-------------------+ | Tables_in_hellodb | +-------------------+ | classes | | coc | | courses | | scores | | students | | teachers | | toc | +-------------------+ 7 rows in set (0.000 sec)
(1) 在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄

MariaDB [hellodb]> select Name,Age,Gender from students -> ; +---------------+-----+--------+ | Name | Age | Gender | +---------------+-----+--------+ | Shi Zhongyu | 22 | M | | Shi Potian | 22 | M | | Xie Yanke | 53 | M | | Ding Dian | 32 | M | | Yu Yutong | 26 | M | | Shi Qing | 46 | M | | Xi Ren | 19 | F | | Lin Daiyu | 17 | F | | Ren Yingying | 20 | F | | Yue Lingshan | 19 | F | | Yuan Chengzhi | 23 | M | | Wen Qingqing | 19 | F | | Tian Boguang | 33 | M | | Lu Wushuang | 17 | F | | Duan Yu | 19 | M | | Xu Zhu | 21 | M | | Lin Chong | 25 | M | | Hua Rong | 23 | M | | Xue Baochai | 18 | F | | Diao Chan | 19 | F | | Huang Yueying | 22 | F | | Xiao Qiao | 20 | F | | Ma Chao | 23 | M | | Xu Xian | 27 | M | | Sun Dasheng | 100 | M | +---------------+-----+--------+ 25 rows in set (0.000 sec) MariaDB [hellodb]> select Name,Age,Gender from students where Age>=25 and Gender='M'; +--------------+-----+--------+ | Name | Age | Gender | +--------------+-----+--------+ | Xie Yanke | 53 | M | | Ding Dian | 32 | M | | Yu Yutong | 26 | M | | Shi Qing | 46 | M | | Tian Boguang | 33 | M | | Lin Chong | 25 | M | | Xu Xian | 27 | M | | Sun Dasheng | 100 | M | +--------------+-----+--------+ 8 rows in set (0.000 sec)
(2) 以ClassID为分组依据,显示每组的平均年龄

MariaDB [hellodb]> select ClassID, avg(Age) 平均年龄 from students group by ClassID; +---------+--------------+ | ClassID | 平均年龄 | +---------+--------------+ | 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.001 sec)
(3) 显示第2题中平均年龄大于30的分组及平均年龄
MariaDB [hellodb]> select ClassID, avg(Age) from students group by ClassID having avg(Age)>=30; +---------+----------+ | ClassID | avg(Age) | +---------+----------+ | NULL | 63.5000 | | 2 | 36.0000 | | 5 | 46.0000 | +---------+----------+ 3 rows in set (0.001 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.001 sec)
4.数据库授权magedu用户,允许192.168.1.0/24网段可以连接mysql
MariaDB [hellodb]> create user magedu@'192.168.1.%/255.255.255.0' identified by 'atech123456'; Query OK, 0 rows affected (0.002 sec)
5.主从复制及主主复制的实现
主从复制https://www.cnblogs.com/lyj1023/p/16270642.html
主主复制https://www.cnblogs.com/lyj1023/p/16270856.html
6.xtrabackup实现全量+增量+binlog恢复库
https://www.cnblogs.com/lyj1023/p/16271860.html
7.MyCAT实现MySQL读写分离
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~