8.5(glibc的安装及MySQL的安全用户脚色权限)

[复制链接]
发表于 2026-2-9 12:16:24 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
一、glibc安装
mysql
清空/etc/目次下的my.cnf
ls -l /etc/my.cnf
rm -rf /etc/my.cnf
yum -y remove mariadb
find / -name "*mysql*" -exec rm -rf {} \;
安装mysql软件包
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.33-li
nux-glibc2.12-x86_64.tar
解压
[root@Mysql-001 ~]# ls
mysql-8.0.33-linux-glibc2.12-x86_64.tar
[root@Mysql-001 ~]# tar -xvf mysql-8.0.33-linux-glibc2.12-x86_64.tar 
[root@Mysql-001 ~]# tar -xf mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz 
[root@Mysql-001 ~]# ls mysql-8.0.33-linux-glibc2.12-x86_64
bin  docs  include  lib  LICENSE  man  README  share  support-files
将项目文件移动到/usr/local/mysql/
cp -r mysql-8.0.33-linux-glibc2.12-x86_64/ /usr/local/mysql/
yum list installed | grep libaio   #查抄是否有libaio
libaio.x86_64                         0.3.109-13.el7                   @anaconda
[root@Mysql-001 ~]# useradd -r -s /sbin/nologin mysql
[root@Mysql-001 ~]# id mysql
uid=997(mysql) gid=995(mysql) 组=995(mysql)
在/usr/local/mysql/目次下创建mysql-files目次
mkdir /usr/local/mysql/mysql-files
修改mysql-files的权限为750 所属的组和属主都是mysql
chown mysql:mysql /usr/local/mysql/mysql-files/
chmod 750 /usr/local/mysql/mysql-files/
ll /usr/local/mysql/
总用量 292
drwxr-xr-x  2 root  root    4096 8月   5 09:48 bin
drwxr-xr-x  2 root  root      38 8月   5 09:48 docs
drwxr-xr-x  3 root  root     282 8月   5 09:48 include
drwxr-xr-x  6 root  root     201 8月   5 09:48 lib
-rw-r--r--  1 root  root  284945 8月   5 09:48 LICENSE
drwxr-xr-x  4 root  root      30 8月   5 09:48 man
drwxr-x---  2 mysql mysql      6 8月   5 09:55 mysql-files
-rw-r--r--  1 root  root     666 8月   5 09:48 README
drwxr-xr-x 28 root  root    4096 8月   5 09:48 share
drwxr-xr-x  2 root  root      77 8月   5 09:48 support-files
初始化数据库
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/
2024-08-05T02:02:01.330394Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.33) initializing of server in progress as process 2825
2024-08-05T02:02:01.345707Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-08-05T02:02:02.337448Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-08-05T02:02:04.033580Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ax8c5SwT(p/u(mysql暗码)
判断是否天生了data目次
ls /usr/local/mysql     #有data目次就是初始化乐成了
把mysql.server文件放到/etc/init.d/目次下(方便启动mysql服务 service mysql start)
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
service mysqld8 start
二、远程毗连登岸MySQL
1、远程登岸条件条件是mysql。user表中的host属性为%。假如是localhost就不允许远程登岸,
2、update mysql.user set host="%" where user="root",flush privilefes;
3、远程管理,可以利用图形化工具,sqlyog,navicat,把握下令工具,客户端工具mysql
4、mysql -h 192.168.1.10 -P3306 -uxiaojiang -pZhang@2002
        -h        主机IP大概域名假如是localhost大概是127.0.0.1可省略
        -P        端口        默认是3306假如是默认的可以省略
        -u        用户名        
        -p        暗码,可以不换行直接输入,也可以换行  不回显输入暗码
(1)创建账户
create user 'xiaojiang'@'%' identified by 'Zhang@2002';
 eg:创建三个账号,abc[abcd] , ccc[a1b2c3] ,ddd[231343]
(2)给权限
grant all on *.* to 'xiaojiang'
(3)创建库
create database if not exists test;
(4)创建表
use test;
create table user(
    id int primary key,
    username varchar(45) not null,
    password varchar(45) not null
);
(5)添加数据
insert into test.user values(1,"zhangsan","123");
insert into test.user values(2,"lisi","456");
insert into test.user values(3,"wangwu","789");
insert into test.user values(4,"zhaoliu","aaa");
添加lilaosi账号,修改暗码,查察mysql.user中的lilaosi的信息
create user 'lilaosi'@'%' identified by 'lilaoshi_123';
alter user 'lilaosi'@'%' identified by 'Lilaosi_123';
select host,user from mysql.user;
利用root账号,为lilaosi账号添加test库存中全部的表的全部权限
mysql -uroot -pZhang@2002
grant all on test.* to 'lilaosi';
#lilaosi就得到了test库中全部表的利用权限;但是由于root没有个lilaosimysql库的
权限,以是lilaosi账号无法查察mysql库
三、mysql环境摆设脚本
vim mysql.sh
#!/bin/bash
cp $1 /usr/local/mysql/
mkdir /usr/local/mysql/mysql-files/
grep /mysql/ /etc/password
if [ $i ne 0 ]; then
        useradd -r -s /sbin/nologin mysql
fi
chown mysql:mysql /usr/local/mysql/mysql-files
chmod 750 /usr/local/mysql/mysql-files
#初始化
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/
#password
#service
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql8
#start server
service mysql8 start
四、安全用户脚色权限
(一)暗码安全计谋
1、查察暗码计谋
mysql> show variables like 'validate%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
2、 修改计谋
mysql>setglobal validate_password.length=0;
mysql>setglobal validate_password.policy=LOW;
mysql>showvariableslike'validate%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 4      |
| validate_password.mixed_case_count   | 0      |
| validate_password.number_count       | 0      |
| validate_password.policy             | LOW    |
| validate_password.special_char_count | 0      |
+--------------------------------------+--------+
(二)用户
1、创建用户
mysql>create user'efgh'@'%' identified by 'efgh';
Query OK,0 rows affected (0.01 sec)
mysql>select host,user from mysql.user;
+-----------+------------------+
| host      |user              |
+-----------+------------------+
|%          | efgh             |
|%          | root             |
|%          | zhangmin         |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | test1            |
+-----------+------------------+
2、删除用户
mysql>drop user'xiaojiang';
Query OK,0 rows affected (0.02 sec)
3、修改用户
mysql>alter user'zhangmin' identified by 'abc123';
Query OK,0 rows affected (0.01 sec)
(三)脚色
1、创建脚色
mysql>create role 'jingli';
Query OK,0 rows affected (0.00 sec)
2、查察脚色
mysql> select host,user from mysql.user;
3、修改脚色
ALTER ROLE 'role_name' [...属性...];
4、删除脚色
DROP ROLE 'role_name';
(四)权限
1、革新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
2、为root账号添加权限
mysql> grant system_user on *.* to "root";
3、新增权限
mysql> grant insert,delete,update,select on test.user to 'jingli';
4、修改权限
mysql> show grants for "efgh";
+----------------------------------+
| Grants for efgh@%                |
+----------------------------------+
| GRANT USAGE ON *.* TO `efgh`@`%` |
+----------------------------------+
1 row in set (0.00 sec)
5、查察权限
mysql> show grants for 'bbb';
6、删除权限
mysql>revoke all on*.* from "efgh";
Query OK,0 rows affected (0.00 sec)
练习1

1.添加aaa账户,设置暗码aaaa
drop user aaa;
create user 'aaa'@'%' identified by 'aaaa';
2.利用aaa账户访问mysql服务
mysql -h127.0.0.1 -P3306 -uaaa -paaaa
3.查察test数据库发现么有权限
show databases;
4.退出并利用root账户登录
quit|exit
mysql -h127.0.0.1 -P3306 -uroot -proot0000
5.为aaa账户添加查察test.user表的权限
grant select on test.user to 'aaa';
6.退出root,利用aaa账户登录
quit|exit
mysql -h127.0.0.1 -P3306 -uaaa -paaaa
7.查察数据库,查察表,查察表内容 可以或许正常查察
show databases;
user test;
show tables;
select * from user;
8.输入数据,没有权限
insert into user values(5,"ermazi","ermazi");####
9.退出aaa利用root登录
quit|exit
mysql -h127.0.0.1 -P3306 -uroot -proot0000
10.为aaa添加insert权限
grant insert on test.user to 'aaa';
11.退出root利用aaa登录
exit|quit
mysql -h127.0.0.1 -P3306 -uaaa -paaaa
12.向user表添加一行新的数据
insert into test.user values(6,"zhangsanfeng","zhangsanfen");
13.修改user中一行的数据的password(暗码)为111,没有update权限
update test.user set password='zsf' where username-'zhangsanfeng';
练习2
mysql> create role 'jingli';
Query OK, 0 rows affected (0.02 sec)
 
mysql> create role 'yuangong';
Query OK, 0 rows affected (0.02 sec)
#添加jingli,yuangong脚色
 
mysql> grant insert,delete,update,select on test.user to 'jingli';
Query OK, 0 rows affected (0.00 sec)
#给jingli脚色设置权限
 
mysql> show grants for 'jingli';
#查察jingli权限
+-----------------------------------------------------------------------+
| Grants for jingli@%                                                   |
+-----------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `jingli`@`%`                                    |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `test`.`user` TO `jingli`@`%` |
+-----------------------------------------------------------------------+
2 rows in set (0.00 sec)
 
 
mysql> grant select,insert on test.user to 'yuangong';
Query OK, 0 rows affected (0.01 sec)
 
mysql> show grants for 'yuangong';
+---------------------------------------------------------+
| Grants for yuangong@%                                   |
+---------------------------------------------------------+
| GRANT USAGE ON *.* TO `yuangong`@`%`                    |
| GRANT SELECT, INSERT ON `test`.`user` TO `yuangong`@`%` |
+---------------------------------------------------------+
2 rows in set (0.00 sec)
 
mysql> select host,user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| %         | aaa              |
| %         | efgh             |
| %         | jingli           |
| %         | xiaojiang        |
| %         | yuangong         |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
9 rows in set (0.00 sec)
#新增bbb和ccc两个用户,bbb是司理必要增编削查权限,ccc是员工,只必要新增和查察的权限
mysql> create user 'bbb'@'%' identified by 'Zhang@2002';
Query OK, 0 rows affected (0.01 sec)
 
mysql> create user 'ccc'@'%' identified by 'Zhang@2002';
Query OK, 0 rows affected (0.01 sec)
 
mysql> grant jingli to 'bbb';
Query OK, 0 rows affected (0.01 sec)
 
mysql> grant yuangong to 'ccc';
Query OK, 0 rows affected (0.01 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
 
mysql> show grants for 'bbb';
+---------------------------------+
| Grants for bbb@%                |
+---------------------------------+
| GRANT USAGE ON *.* TO `bbb`@`%` |
| GRANT `jingli`@`%` TO `bbb`@`%` |
+---------------------------------+
2 rows in set (0.00 sec)
 
mysql> show grants for 'ccc';
+-----------------------------------+
| Grants for ccc@%                  |
+-----------------------------------+
| GRANT USAGE ON *.* TO `ccc`@`%`   |
| GRANT `yuangong`@`%` TO `ccc`@`%` |
+-----------------------------------+
2 rows in set (0.00 sec)
————————————————
                            版权声明:本文为博主原创文章,依照 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.csdn.net/m0_71589190/article/details/140935586

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!qidao123.com:ToB企服之家,中国第一个企服评测及软件市场,开放入驻,技术点评得现金
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表