N63050 第十一周运维作业

第十一周
就业和全程班小伙伴本周学习内容:

二十一、Mysql数据库二
1、MySQL的视图函数存储过程触发器和事件管理(64分钟)
2、MySQL用户和权限管理(40分钟)
3、MySQL架构和存储引擎(51分钟)
4、MySQL的索引结构(61分钟)
5、MySQL索引管理和相关工具(45分钟)
6、MySQL锁管理和事务(44分钟)
7、事务日志管理和错误日志(57分钟)

二十二、Mysql数据库三
1、MySQL的通用日志和慢查询日志及二进制日志(53分钟)
2、MySQL二进制日志管理(53分钟)
3、MySQL备份类型和原理(50分钟)
4、MySQL备份和还原(61分钟)
5、MySQL备份还原实战(56分钟)
6、xtrabackup备份工具实战(61分钟)
7、MYSQL主从复制原理和实现(48分钟)

就业(全程班)第十一周作业:
1、 导入hellodb.sql生成数据库

[root@centos7 ~]#mysql < hellodb_innodb.sql            #方法一

[root@centos7 ~]#source /root/hellodb_innodb.sql       #方法二

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| db1                |
| db2                |
| hellodb            |           #导入成功
| mysql              |
| performance_schema |
| student            |
| test               |
+--------------------+
8 rows in set (0.00 sec)

(1) 在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄

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      |
| Xu Xian      |  27 | M      |
| Sun Dasheng  | 100 | M      |
+--------------+-----+--------+
7 rows in set (0.00 sec)

(2) 以ClassID为分组依据,显示每组的平均年龄

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) 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.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.00 sec)

2、数据库授权magedu用户,允许192.168.1.0/24网段可以连接mysql

centos8:
MariaDB [(none)]> source hellodb_innodb.sql
MariaDB [hellodb]> create user magedu@'192.168.1.%' identified by '123456';
MariaDB [(none)]> grant all on hellodb.* to magedu@'192.168.1.%';

[root@centos7 ~]#mysql -umagedu -h192.168.1.8 -p123456
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| hellodb            |
| information_schema |
+--------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> use hellodb;
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes           |
| coc               |
| courses           |
| scores            |
| students          |
| teachers          |
| toc               |
+-------------------+
7 rows in set (0.00 sec)

MariaDB [(none)]> select host,user,password from mysql.user;
+--------------------+--------+-------------------------------------------+
| host               | user   | password                                  |
+--------------------+--------+-------------------------------------------+
| localhost          | root   |                                           |
| centos8.magedu.org | root   |                                           |
| 127.0.0.1          | root   |                                           |
| ::1                | root   |                                           |
| 10.0.0.%           | magedu | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+--------------------+--------+-------------------------------------------+

#查看指定用户获得的授权
MariaDB [(none)]> show grants for magedu@'192.168.1.%';
+-----------------------------------------------------------------------------------------------------------------------+
| Grants for magedu@192.168.1.%                                                                                           |
+-----------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `magedu`@`192.168.1.%` IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

#取消权限
MariaDB [(none)]> revoke all privileges on hellodb.* from root@'192.168.1.%';
MariaDB [(none)]> show grants for root@'192.168.1.%';
+------------------------------------------------------------------------------------------------------------+
| Grants for root@192.168.1.%                                                                                   |
+------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `root`@`192.168.1.%` IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
+------------------------------------------------------------------------------------------------------------+


posted @ 2023-02-22 20:46  BruceLebron  阅读(10)  评论(0编辑  收藏  举报