数据库

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;

 

转载于:https://www.cnblogs.com/xnb123/p/8024694.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值