数据库

21、部署 MariaDB 数据库

server0 上部署 MariaDB。要求如下: 仅允许从 server0 系统上使用登陆到数据库。

登陆数据库所用的账号为 root,密码为 root_password。

 http://content.example.com/courses/rhce/rhel7.0/materials/mariadb/mariadb.dump  下载文件,并将其恢复为 legacy 库。

并设置数据库访问:

 

用户名

密码

权限

Mary

xxx

对 legacy 库的所有数据有选择操作权限

Legacy

xxx

对 legacy 库的所有数据有选择、插入、更新、删除操作权

Report

xxx

对 legacy 库的所有数据有选择操作权限

 

解题:

 

[root@server0 ~]# yum -y install mariadb mariadb-server [root@server0 ~]# systemctl enable mariadb

ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'

[root@server0 ~]# systemctl restart mariadb

 

[root@server0 ~]# systemctl enable mariadb

[root@server0 ~]# systemctl enable mariadb

[root@server0 ~]# mysql_secure_installation --初始化 mariadb

 

Set root password? [Y/n]y --设置数据库的 root 用户密码 Disallow root login remotely? [Y/n]y --禁止 root 用户远程连接

[root@server0 ~]# wget http://content.example.com/courses/rhce/rhel7.0/materials/mariadb/mariadb.dump [root@server0 ~]# mysql -proot_password --使用‘root_password’这个密码来连接 mysql

MariaDB [(none)]> create database legacy;

MariaDB [(none)]> use legacy; Database changed

MariaDB [legacy]> source /root/mariadb.dump --恢复数据库文件

MariaDB [legacy]> show tables;

MariaDB [(none)]> grant select on legacy.* to 'mary'@'localhost' identified by 'mary_password';--添加授权用户并设置密码

MariaDB [(none)]> grant update,delete,insert,select on legacy.* to 'legacy'@'localhost' identified by 'legacy_password';

MariaDB [(none)]> grant select on legacy.* to 'report'@'localhost' identified by 'report_password';

MariaDB [(none)]> flush privileges; --刷新权限表

 

 

22、数据查询填空

 server0 上登陆数据库,查看 legacy 库进行查询,并将结果填入相应的框格中。 Q1  product 表中,查询 RT-AC68U 的产品 id()

Q2 查询类别为 Servers 的产品的数量()

模拟考环境请在 http://classroom.example.com/cgi-bin/mariadb 提交

解题:

 

MariaDB [legacy]> select id,name from product where name='RT-AC68U';

 

MariaDB [legacy]> select count(product.id) from product,category where category.name='Servers' and category.id=product.id_category;

 

posted on 2017-12-11 19:28  肀肀  阅读(140)  评论(0编辑  收藏  举报

导航