1、一键安装 mariadb 数据库脚本
echo "安装相关依赖包"
yum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
useradd -r -s /sbin/nologin -d /data/mysql mysql;echo "用户创建成功"
mkdir /data/mysql;chown mysql.mysql /data/mysql;echo "数据库目录创建成功"
tar xf mariadb-10.2.31.tar.gz;echo "解压完成"
echo "安装开始"
cd mariadb-10.2.31/
cmake . \
-DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/data/mysql/ \
-DSYSCONFDIR=/etc/ \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITHOUT_MROONGA_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install;echo "编译安装完成"
echo 'PATH=/app/mysql/bin:$PATH' > //etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh ; echo "环境变量完成"
cd
cd /app/mysql;scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql;echo "数据库文件生成成功"
cp /app/mysql/support-files/my-huge.cnf /etc/my.cnf ;echo "配置文件完成"
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld;systemctl start mysql
2、简述Event 事件介绍以及它的优缺点
优点:
一些对数据定时性操作不再依赖外部程序,而直接使用数据库本身提供的功能,可以实现每秒钟 执行一个任务,这在一些对实时性要求较高的环境下就非常实用
缺点:
定时触发,不可以直接调用
3、在 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.01 sec)
4、在 students 表中,以 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.00 sec)
5、显示第2题中平均年龄大于30的分组及平均年龄
MariaDB [hellodb]> select ClassID,count(*),avg(age) 平均年龄 from students group by ClassID having 平均年龄 > 30;
+---------+----------+--------------+
| ClassID | count(*) | 平均年龄 |
+---------+----------+--------------+
| NULL | 2 | 63.5000 |
| 2 | 3 | 36.0000 |
| 5 | 1 | 46.0000 |
+---------+----------+--------------+
3 rows in set (0.00 sec)