[root@host125 etc]# cat /etc/os-release NAME="CentOS Linux" VERSION="8" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-8" CENTOS_MANTISBT_PROJECT_VERSION="8"
二、下载MySQL rpm
https://dev.mysql.com/downloads/mysql/
三、安装
查看mysql官方安装教程文档
[root@host125 install]# ls -l mysql* -rw-rw-r--. 1 wuzb wuzb 14692316 12月 19 09:14 mysql-community-client-8.0.27-1.el8.x86_64.rpm -rw-rw-r--. 1 wuzb wuzb 645452 12月 19 09:03 mysql-community-common-8.0.27-1.el8.x86_64.rpm -rw-rw-r--. 1 wuzb wuzb 1565372 12月 19 09:14 mysql-community-libs-8.0.27-1.el8.x86_64.rpm -rw-rw-r--. 1 wuzb wuzb 55964292 12月 19 09:01 mysql-community-server-8.0.27-1.el8.x86_64.rpm [root@host125 install]# [root@host125 install]# rpm -ivh mysql-community-common-8.0.27-1.el8.x86_64.rpm 警告:mysql-community-common-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY Verifying... ################################# [100%] 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-common-8.0.27-1.e################################# [100%] [root@host125 install]# rpm -ivh mysql-community-libs-8.0.27-1.el8.x86_64.rpm --force --nodeps 警告:mysql-community-libs-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY Verifying... ################################# [100%] 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-libs-8.0.27-1.el8################################# [100%] [root@host125 install]# rpm -ivh mysql-community-client-8.0.27-1.el8.x86_64.rpm --force --nodeps 警告:mysql-community-client-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY Verifying... ################################# [100%] 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-client-8.0.27-1.e################################# [100%] [root@host125 install]# rpm -ivh mysql-community-client-8.0.27-1.el8.x86_64.rpm --force --nodeps 警告:mysql-community-client-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY Verifying... ################################# [100%] 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-client-8.0.27-1.e################################# [100%] [root@host125 install]# rpm -ivh mysql-community-server-8.0.27-1.el8.x86_64.rpm 警告:mysql-community-server-8.0.27-1.el8.x86_64.rpm: 头V3 DSA/SHA256 Signature, 密钥 ID 5072e1f5: NOKEY Verifying... ################################# [100%] 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-server-8.0.27-1.e################################# [100%] [/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.
安装完成后会创建以下内容
[root@host125 install]# rpm -aq|grep mysql mysql-community-common-8.0.27-1.el8.x86_64 mysql-community-client-8.0.27-1.el8.x86_64 mysql-community-server-8.0.27-1.el8.x86_64 mysql-community-libs-8.0.27-1.el8.x86_64
还有以下方式也可查看:
ps -ef | grep mysql
cat /etc/group | grep mysql
cat /etc/password | grep mysql
mysqladmin --version
[root@host125 mysql]# mysqld --initialize //创建数据文件目录和mysql系统数据库 产生随机root密码
[root@host125 mysql]# systemctl start mysqld Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
哦豁,报错了。别急,查看报错日志
[root@host125 mysql]# view /var/log/mysqld.log 2021-12-19T14:31:55.430093Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.27) initializing of server in progress as process 35122 2021-12-19T14:31:55.450191Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2021-12-19T14:31:56.205957Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2021-12-19T14:31:57.546533Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main 2021-12-19T14:31:57.546567Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main 2021-12-19T14:31:57.673184Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: cxXe5.,sQ-v* 2021-12-19T14:33:17.353176Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.27) starting as process 35270 2021-12-19T14:33:17.367265Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9b23fb7f-60d8-11ec-b633-000c29f7125c. mysqld: File '/var/lib/mysql/auto.cnf' not found (OS errno 13 - Permission denied) 2021-12-19T14:33:17.367427Z 0 [ERROR] [MY-010183] [Server] Failed to create file(file: '/var/lib/mysql/auto.cnf', errno 13) 2021-12-19T14:33:17.367457Z 0 [ERROR] [MY-010076] [Server] Initialization of the server's UUID failed because it could not be read from the auto.cnf file. If this is a new server, the initialization failed because it was not possible to generate a new UUID. 2021-12-19T14:33:17.367560Z 0 [ERROR] [MY-010119] [Server] Aborting 2021-12-19T14:33:17.368344Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.27) MySQL Community Server - GPL.
从报错可以看出是因为没权限,赋权后重新启动
[root@host125 mysql]# chown -R mysql:mysql /var/lib/mysql/ [root@host125 mysql]# systemctl start mysqld [root@host125 mysql]# ps -ef | grep mysqld mysql 2579 1 2 08:58 ? 00:00:04 /usr/sbin/mysqld root 2658 2164 0 09:00 pts/0 00:00:00 grep --color=auto mysqld [root@host125 mysql]#
[root@host125 mysql]# grep 'temporary password' /var/log/mysqld.log 2021-12-19T14:31:57.673184Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: cxXe5.,sQ-v* [root@host125 mysql]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.27 Copyright (c) 2000, 2021, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root123'; Query OK, 0 rows affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec) mysql>
大功告成