centos8 \CentOS 9 Stream \Oracle Linux8\Oracle Linux 9 rpm 安装mysql8.0.28 mysql8.0.34
centos8 rpm 安装mysql8.0.28
检查
检测系统是否自带安装 MySQL
命令如下:
rpm -qa | grep mysql
如果如下存在已安装的包,就需要卸载
mysql80-community-release-el8-1.noarch
mysql-community-client-8.0.18-1.el8.x86_64
mysql-community-libs-8.0.18-1.el8.x86_64
mysql-community-server-8.0.18-1.el8.x86_64
mysql-community-common-8.0.18-1.el8.x86_64
卸载命令
存在mysql已安装的包就需要依次卸载
rpm -e mysql // 普通删除
rpm -e --nodeps mysql // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删
查看是否安装了mariadb;
rpm -qa | grep mariadb
如果有安装的话使用如下命令移除:
rpm -e XXX
rpm -e --nodeps xxx //强制删除
下载
官网地址
MySQL :: Download MySQL Community Server
下载 centos8 的
mysql-8.0.28-1.el8.x86_64.rpm-bundle.tar
使用浏览器自带下载功能下载有时候可能会出现因为网络等原因包下载不完整而出问题的情况(最好下载后校验哈希值),如若正常安装老是出问题,推荐使用迅雷等下载工具下载后校验完毕,使用FTP近程传输到服务器安装目录。
解压
[root@localhost rootftp]# ls
mysql-8.0.28-1.el8.x86_64.rpm-bundle.tar
mysql-community-client-8.0.28-1.el8.x86_64.rpm
mysql-community-client-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-client-plugins-8.0.28-1.el8.x86_64.rpm
mysql-community-client-plugins-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-common-8.0.28-1.el8.x86_64.rpm
mysql-community-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-debugsource-8.0.28-1.el8.x86_64.rpm
mysql-community-devel-8.0.28-1.el8.x86_64.rpm
mysql-community-icu-data-files-8.0.28-1.el8.x86_64.rpm
mysql-community-libs-8.0.28-1.el8.x86_64.rpm
mysql-community-libs-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-server-8.0.28-1.el8.x86_64.rpm
mysql-community-server-debug-8.0.28-1.el8.x86_64.rpm
mysql-community-server-debug-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-server-debuginfo-8.0.28-1.el8.x86_64.rpm
mysql-community-test-8.0.28-1.el8.x86_64.rpm
mysql-community-test-debuginfo-8.0.28-1.el8.x86_64.rpm
[root@localhost rootftp]#
安装
注意安装顺序
- mysql-community-common
- 三个一起装 因为 有依赖
- mysql-community-libs-***.rpm
- mysql-community-client-***.rpm
- mysql-community-client-plugins-***.rpm
- mysql-community-server-***.rpm
- 因为依赖perl ,所以可以直接通过yum方式安装
- yum install mysql-community-server-****.x86_64.rpm
本人采用的安装顺序,含最末回车符号批量复制进去可以实现一次性批处理安装至结束,直接接续配置步骤:
rpm -ivh mysql-community-common-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-libs-debuginfo-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-client-plugins-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-client-plugins-debuginfo-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-libs-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-client-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-debuginfo-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-client-debuginfo-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-debugsource-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-devel-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-icu-data-files-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-server-debug-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-server-debug-debuginfo-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-server-debuginfo-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-test-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-test-debuginfo-8.0.28-1.el8.x86_64.rpm rpm -ivh mysql-community-server-8.0.28-1.el8.x86_64.rpm
ps: MySQL 8.0.34 安装顺序(操作系统为CentOS 9 Stream)
=========================CentOS 9 Stream===================
rpm -ivh mysql-community-common-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-libs-debuginfo-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-client-plugins-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-client-plugins-debuginfo-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-libs-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-client-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-debuginfo-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-client-debuginfo-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-debugsource-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-devel-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-icu-data-files-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-server-debug-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-server-debug-debuginfo-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-server-debuginfo-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-test-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-test-debuginfo-8.0.34-1.el9.x86_64.rpm rpm -ivh mysql-community-server-8.0.34-1.el9.x86_64.rpm
=======================Oracle Linux /CentOS 8 =====================
rpm -ivh mysql-community-debuginfo-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-common-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-libs-debuginfo-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-client-plugins-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-client-plugins-debuginfo-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-libs-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-client-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-client-debuginfo-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-debugsource-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-devel-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-icu-data-files-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-server-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-server-debug-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-server-debug-debuginfo-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-server-debuginfo-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-test-8.0.34-1.el8.x86_64.rpm rpm -ivh mysql-community-test-debuginfo-8.0.34-1.el8.x86_64.rpm
On the CentOS 9 Stream, It may thread out Erorr message,like:
在CentOS 9 Stream上可能报如下错误:
warning: mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: libcrypto.so.10()(64bit) is needed by mysql-community-libs-compat-5.7.28-1.el7.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by mysql-community-libs-compat-5.7.28-1.el7.x86_64 libssl.so.10()(64bit) is needed by mysql-community-libs-compat-5.7.28-1.el7.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by mysql-community-libs-compat-5.7.28-1.el7.x86_64 Just Like this , not exactly the same.
To deal with the error, you can try to add --nodeps --force after the "rpm -ivh ***" commond.
rpm -ivh mysql-community-common-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-libs-debuginfo-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-client-plugins-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-client-plugins-debuginfo-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-libs-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-client-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-debuginfo-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-client-debuginfo-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-debugsource-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-devel-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-icu-data-files-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-server-debug-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-server-debug-debuginfo-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-server-debuginfo-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-test-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-test-debuginfo-8.0.28-1.el8.x86_64.rpm --nodeps --force rpm -ivh mysql-community-server-8.0.28-1.el8.x86_64.rpm --nodeps --force
[root@localhost rootftp]# rpm -ivh mysql-community-common-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-common-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-8.0.28-1.e################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-libs-debuginfo-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-libs-debuginfo-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
error: Failed dependencies:
mysql-community-debuginfo(x86-64) = 8.0.28-1.el8 is needed by mysql-community-libs-debuginfo-8.0.28-1.el8.x86_64
[root@localhost rootftp]# rpm -ivh mysql-community-client-plugins-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-client-plugins-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-plugins-8.################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-client-plugins-debuginfo-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-client-plugins-debuginfo-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
error: Failed dependencies:
mysql-community-debuginfo(x86-64) = 8.0.28-1.el8 is needed by mysql-community-client-plugins-debuginfo-8.0.28-1.el8.x86_64
[root@localhost rootftp]# rpm -ivh mysql-community-libs-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-libs-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-8.0.28-1.el8################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-client-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-client-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-8.0.28-1.e################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-debuginfo-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-debuginfo-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-debuginfo-8.0.28-################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-client-debuginfo-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-client-debuginfo-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-debuginfo-################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-debugsource-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-debugsource-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-debugsource-8.0.2################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-devel-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-devel-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-devel-8.0.28-1.el################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-icu-data-files-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-icu-data-files-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-icu-data-files-8.################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-server-debug-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-server-debug-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
error: Failed dependencies:
mysql-community-server = 8.0.28-1.el8 is needed by mysql-community-server-debug-8.0.28-1.el8.x86_64
[root@localhost rootftp]# rpm -ivh mysql-community-server-debug-debuginfo-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-server-debug-debuginfo-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-debug-debu################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-server-debuginfo-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-server-debuginfo-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-debuginfo-################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-test-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-test-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
error: Failed dependencies:
mysql-community-server(x86-64) >= 8.0.11 is needed by mysql-community-test-8.0.28-1.el8.x86_64
perl(JSON) is needed by mysql-community-test-8.0.28-1.el8.x86_64
[root@localhost rootftp]# rpm -ivh mysql-community-test-debuginfo-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-test-debuginfo-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-test-debuginfo-8.################################# [100%]
[root@localhost rootftp]# rpm -ivh mysql-community-server-8.0.28-1.el8.x86_64.rpm
warning: mysql-community-server-8.0.28-1.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-8.0.28-1.e################################# [100%]
[/usr/lib/tmpfiles.d/pesign.conf:1] Line references path below legacy directory /var/run/, updating /var/run/pesign → /run/pesign; please update the tmpfiles.d/ drop-in file accordingly.
[root@localhost rootftp]# yum install mysql-server
Last metadata expiration check: 1:37:35 ago on Thu 03 Mar 2022 03:07:09 AM EST.
Package mysql-community-server-8.0.28-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@localhost rootftp]# yum install mysql
Last metadata expiration check: 1:37:50 ago on Thu 03 Mar 2022 03:07:09 AM EST.
Package mysql-community-client-8.0.28-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
安装完成
-
安装完成后,会自动生成 /etc/my.cnf 配置文件
-
安装了 mysql-community-server 组件,会:
a). 在 /etc/下生成 my.cnf 文件 和 my.cnf.d 文件夹b). 在/var/lib/下生产以下三个文件夹
c). 在/var/log/ 下生成 mysqld.log 文件
d). 在/var/run/ 下生成 mysqld 目录
-
[root@localhost rootftp]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
启动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
=============以下内容与上文有所重复,仅供对比参考======
CentOS 9 Stream rpm 安装mysql8.0.29
# !!!注意:以下参考除命令以外很多是说明文字,不要全部复制,自行选择该执行的命令
方法一(推荐):使用yum安装基础依赖并通过yum安装mysql-community-{server,client,common,libs}-*(亲测能解决所需依赖,正常安装)
# 如果系统提示类似“compat-openssl10 is needed”或者各种提示缺乏依赖的情况,可改用yum进行安装
yum install compat-openssl10
yum install http://mirror.centos.org/centos/8-stream/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-3.el8.x86_64.rpm
sudo yum update
sudo yum install mysql-community-{server,client,common,libs}-*
mysql
# 方法二:官网下载mysql-8.0.29-1.el8.x86_64.rpm-bundle.tar 包解压安装,此种方法要注意解决提示的依赖项和rpm包的安装顺序。
[root@dz Downloads]#wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.29-1.el8.x86_64.rpm-bundle.tar
chmod 777 mysql-8.0.29-1.el8.x86_64.rpm-bundle.tar
tar -xvf mysql-8.0.29-1.el8.x86_64.rpm-bundle.tar #解压后会得到很多个mysql组件的rpm包
ls
# 检查系统中已经存在的mysql和mariadb并卸载干净
rpm -qa | grep mysql
rpm -e mysql80-community-release-el8-4.noarch
rpm -qa | grep mariadb
rpm -e
rpm -e mariadb-connector-c-config-3.2.6-1.el9.noarch
rpm -e
rpm -e mariadb-connector-c-3.2.6-1.el9.x86_64
rpm -e mariadb-connector-c-3.2.6-1.el9.x86_64 --nodeps
rpm -e mariadb-connector-c-config-3.2.6-1.el9.noarch --nodeps
rpm -ivh mysql-community-common-8.0.29-1.el8.x86_64.rpm
# 正式开始安装,此参考安装顺序有时候会提示缺乏依赖项,逐一解决后全部安装完才可以,比较麻烦
rpm -ivh mysql-community-libs-debuginfo-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-plugins-debuginfo-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-debuginfo-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-client-debuginfo-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-debugsource-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-server-debug-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-server-debug-debuginfo-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-server-debuginfo-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-test-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-test-debuginfo-8.0.29-1.el8.x86_64.rpm
rpm -ivh mysql-community-server-8.0.29-1.el8.x86_64.rpm
# 安装完成后进行配置和修改管理密码
[root@dz]#cat /etc/my.cnf
clear
vi /etc/my.cnf
cat /etc/my.cnf
systemctl start mysqld
ystemctl status mysqld
stemctl status mysqld
systemctl status mysqld
grep 'temporary password' /var/log/mysqld.log
# 执行成功回显信息附带了临时密码,显示如下:
[root@dz Downloads]# grep 'temporary password' /var/log/mysqld.log
2022-07-05T07:15:05.672937Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: dz8>DAfTfwtM
# 其中,最末尾的字符串“dz8>DAfTfwtM”即为安装生成的临时密码,供修改密码使用
mysql
systemctl status mysqld
# 此命令执行后应该返回如下:active(running)状态为绿色
[root@dz Downloads]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2022-07-05 03:51:22 EDT; 15s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 23785 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 23812 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 43552)
Memory: 391.3M
CPU: 2.104s
CGroup: /system.slice/mysqld.service
└─23812 /usr/sbin/mysqld
Jul 05 03:51:18 dz systemd[1]: Starting MySQL Server...
Jul 05 03:51:22 dz systemd[1]: Started MySQL Server.
#输入mysql唤醒mysql程序
mysql
mysql> # 输入mysql进入“mysql>”提示符表示安装成功,并已经唤醒进入到mysql,首次应该执行下一条命令来修改root管理密码,
ALTER USER 'root'@'localhost' identified by '你的新密码';
Enter password: #这里要求的密码要输入上面查出来的临时密码
mysql
# 如果出现 类似“
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
”或“ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
”的情况,可以回退到命令行超级权限,先修改my.cnf,在[mysqld]下面一行添加:
skip-grant-tables
# ESC保存":wq",然后修改密码
mysql -u root -p
mysql
ALTER USER 'root'@'localhost' identified by '你的新密码';
# 出现以下提示说明密码已经修改成功,多登入几次试试能成功进入mysql>并执行相关数据库操作命令,以避免自己埋坑
[root@dz Downloads]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.29 MySQL Community Server - GPL
Copyright (c) 2000, 2022, 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.
# ======================================
[root@dz Downloads]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.29 MySQL Community Server - GPL
Copyright (c) 2000, 2022, 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.
# 安装完并已经修改完mysql密码以后,最好是把mysqld服务重启一下,以下为centOS9 Stream操作命令,centOS8类似,其他版本系统自己查命令
systemctl stop mysqld
systemctl start mysqld
systemctl status mysqld
mysql
mysql>
===========================MySQL 8.0.34卸载删除操作======================
测试平台:Oracle Linux 8
说明:如果需要彻底卸载或者遇到问题需要重装,比如更换其他版本等,我们需要彻底卸载删除mysql相关的文件。
# MySQL 8.0.34 卸载删除 (Oracle Linux 8)
systemctl status mysqld
systemctl stop mysqld
systemctl status mysqld
rpm -qa | grep mysql
rpm -e mysql-community-server-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-server-debug-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-debugsource-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-server-debug-debuginfo-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-common-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-icu-data-files-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-client-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-test-debuginfo-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-libs-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-server-debuginfo-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-client-debuginfo-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-libs-debuginfo-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-debuginfo-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-devel-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-client-plugins-debuginfo-8.0.34-1.el8.x86_64 --nodeps
rpm -e mysql-community-client-plugins-8.0.34-1.el8.x86_64 --nodeps
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql.sock
rm -rf /var/run/mysqld/mysqld.pid
rm -rf /var/log/mysqld.log
rm -rf /usr/lib/systemd/system/mysqld.service
rm -rf /usr/lib64/mysql
rm -rf /etc/my.cnf
rm -rf /etc/my.cnf.d
其他版本操作请修改版本号,具体问题具体分析,或直接参考其他教程文章。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本