一、前置条件:CentOS Mini 安装需要先安装ifconfig 和 wget工具,参考步骤:
1.首先,让我们找出哪个包提供了ifconfig命令。要完成这项任务,输入以下命令:
yum provides ifconfig
输出:
[root@localhost ~]# yum provides ifconfig
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo : @base
Matched from:
Filename : /usr/sbin/ifconfig
[root@localhost ~]#
2.就像你在上面的输出中所看到的,net-tools包提供了ifconfig命令。因此,让我们安装net-tools包来使用ifconfig命令。
yum install net-tools
3.现在,你就可以像以往一样使用ifconfig命令了。
二、安装前的准备
1.清理和卸载系统重所有mysql 和 mariadb程序及其文件、文件夹,避免冲突不能正常安装:
如果此前有安装过的,用过的,备份数据库,然后全部卸载清理干净。
1. 备份数据库
mysqldump -uroot -p'密码' [DB名称] > [备份脚本名称].sql
2. 停止服务
service mysqld stop
3. 卸载mysql
yum remove mysql mysql-server
4. 查找和清理
rpm -qa | grep mysql
rpm -qa | grep mariadb
使用如下命令卸载和删除: rpm -e 和 rm -rf 后面紧跟的是你查找出来的软件包和文件夹、文件名。
rpm -e '替换成需要卸载的包的名称,不需要加引号' --nodeps
rm -rf '绝对路径/文件名'
最后再用find命令查找一下还有没有mysql相关的东西,务必全部清除干净,免去各种奇奇怪怪的问题:
find / -name mysql
清理干净就可以准备安装步骤了,先更新切换到阿里云的源加速器,更新一遍yum
5. 下载yum源
检查当前操作系统的版本, 找到对应的yum源并下载
[root@VM-1 bin]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
进入下载页面
MySQL :: Download MySQL Yum Repository
使用 Red Hat 7
wget https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm
5. 安装yum源
rpm -Uvh mysql80-community-release-el7-11.noarch.rpm
插曲:
之前安装了mysql 5.7 产生了冲突
查看 rpm -qa | grep mysql
删除 mysql 5.7 相关
rpm -e mysql57-community-release
rpm -e mysql-community-
再次安装成功
三、正式安装的正确操作
0、更换yum源
1、打开 mirrors.aliyun.com,选择centos的系统,点击帮助
2、执行命令:
yum install wget -y
3、改变某些文件的名称
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
4、执行更换yum源的命令
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
5、更新本地缓存
yum clean all
yum makecache
1、再次查看系统中是否自带安装mysql
yum list installed | grep mysql
2、删除系统自带的mysql及其依赖(防止冲突)
yum -y remove mysql-libs.x86_64
3、安装wget命令
yum install wget -y
4、给CentOS添加rpm源,并且选择较新的MySQL源
wget -i -c https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
5、安装下载好的rpm文件
yum install mysql80-community-release-el7-3.noarch.rpm -y
6、使用yum安装mysql
yum install mysql-community-server -y
6.1、安装中遇到错误解决方式 错误: mysql-community-libs-8.0.32-1.el7.x86_64.rpm 的公钥尚未安装 失败的软件包是:mysql-community-libs-8.0.32-1.el7.x86_64 GPG 密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 解决办法: 执行如下命令后再次安装:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
7、启动mysql服务 #启动mysql服务,查看启动状态及是否开机启动
systemctl start mysqld.service
systemctl status mysqld.service
systemctl list-unit-files | grep enabled
8、获取mysql的临时密码
grep "password" /var/log/mysqld.log
9、使用临时密码登录
mysql -uroot -p
#输入密码
10、修改密码 #密码要符合mysql安全规则,否则修改不成功
ALTER USER 'root'@'localhost' IDENTIFIED BY '密码';
11、修改远程访问权限
create user 'aiops'@'%' identified by '123456';
grant all privileges on *.* to 'aiops'@'%' with grant option;
flush privileges;
12、设置字符集为utf-8 #在[mysqld]部分添加: character-set-server=utf8 #在文件末尾新增[client]段,并在[client]段添加:
default-character-set=utf8
四、开发测试启用弱密码的方法
启动mysql
[root@localhost rootftp]# systemctl start mysqld
[root@localhost rootftp]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor pres>
Active: active (running) since Thu 2022-03-03 04:46:34 EST; 20s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 41027 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=>
Main PID: 41061 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 23385)
Memory: 471.0M
CGroup: /system.slice/mysqld.service
└─41061 /usr/sbin/mysqld
Mar 03 04:46:27 localhost.localdomain systemd[1]: Starting MySQL Server...
Mar 03 04:46:34 localhost.localdomain systemd[1]: Started MySQL Server.
修改密码
查看密码
grep 'temporary password' /var/log/mysqld.log
2022-03-03T07:10:39.887374Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: U<=VsitGY83w
mysql
修改密码
## 这里是个错误的提示样子,仅做提醒大佬们,因为所输入的密码不符合mysql默认密码安全规则
[root@localhost rootftp]# mysql
mysql> alter user 'root'@'localhost' identified by 'root';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password_length=1;
ERROR 1193 (HY000): Unknown system variable 'validate_password_length'
mysql> show global
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql> SHOW VARIABLES LIKE 'validate_password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
## 提示:先按照默认密码规则设置并记住设置的密码,
### 密码组合最好是: 大写字母+数字+小写字母+特殊符号,
## 记下来,最好抄下来,忘记了会哭
mysql> ALTER USER 'root'@'localhost' identified by '12345678Aa?'; # 注意密码规则
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; # 刷新权限规则
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| 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 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
mysql> set global validate_password.length=4; # 减少密码长度要求
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.policy=0; # 取消密码验证策略
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
### “新密码”即更新密码规则后自己设置的密码,
### 做了如上规则更改以后可以设置简单密码,诸如:123456
### 简单密码仅限于本地开发调试方便,
### 正式部署或生产环境时候必须按照密码规则设置复杂度足够和
### 符合密码规则和各种安全标准规范合规的密码,以增强系统的安全性
### 常见的安全标准规范如 GB强制的等级保护、分级保护之二、三、四级,以及企业或组织要求的规则等;
mysql> ALTER USER 'root'@'localhost' identified by '新密码'; # 建议设置合规安全的密码,开发测试可以设置简单密码
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[root@192 home]# mysql -u root -p
Enter password: # 输入新设置的密码登入
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.34 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
# 数据库操作和使用请参考官方文档或者其他技术博文,此处不再赘述
mysql> exit
Bye
[root@192 home]#
问题 短密码不能设置,需要修改密码策略
set global validate_password.length=4; 密码长度改成4
set global validate_password.policy=0; 密码校验强度改成LOW后,只校验密码长度
查看当前安全变量值并修改
mysql> show variables like 'validate_password%';
+--------------------------------------+--------+
| 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 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
mysql> set global validate_password.length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 4 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | LOW |
| validate_password.special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
设置开机启动
[root@192 home]# systemctl enable mysqld
————————————————
更多安装细节和问题处理方案请参考我的另一篇博文,涵盖面更广泛:
centos8 \CentOS 9 Stream \Oracle Linux8\Oracle Linux 9 rpm 安装mysql8.0.28 mysql8.0.34
https://blog.csdn.net/lqzixi/article/details/123260293