CentOS 如何用rpm安装MySQL8

前期准备

环境

  • CentOS 6 64 位操作系统
  • 因为服务器不连公网,我是选择的 rpm 安装,安装文件是 mysql-8.0.13-1.el6.x86_64.rpm-bundle.tar

过程

  1. 如果有 MySQL 先卸载,没有则忽略,卸载前记得备份数据。CentOS RPM 方式完全卸载 MySQL

  2. 解压之后会有 7 个 rpm 包

tar -xvf mysql-8.0.13-1.el6.x86_64.rpm-bundle.tar
  1. 创建 mysql 用户
useradd mysql
passwd mysql

4:安装 按顺序执行以下命令

rpm -ivh mysql-community-common-8.0.13-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.13-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.13-1.el6.x86_64.rpm
rpm -ivh mysql-community-client-8.0.13-1.el6.x86_64.rpm 
rpm -ivh mysql-community-server-8.0.13-1.el6.x86_64.rpm 
rpm -ivh mysql-community-devel-8.0.13-1.el6.x86_64.rpm 
rpm -ivh mysql-community-test-8.0.13-1.el6.x86_64.rpm

我执行 rpm -ivh mysql-community-server-8.0.13-1.el6.x86_64.rpm 命令时,遇到了失败。 则使用 rpm -ivh mysql-community-server-8.0.13-1.el6.x86_64.rpm –force –nodeps (–force: 强制安装, –nodeps: 不检查依赖关系)

rpm 安装执行成功显示:

warning: mysql-community-libs-compat-8.0.13-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
 1:mysql-community-libs-co########################################### [100%]

rpm 安装执行失败显示:用 rpm -e 先卸载此包在安装

warning: mysql-community-libs-compat-8.0.13-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [100%]
 file /usr/lib64/mysql/libmysqlclient.so.16.0.0 from install of mysql-community-libs-compat-8.0.13-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-8.0.1.el6_8.x86_64
 file /usr/lib64/mysql/libmysqlclient_r.so.16.0.0 from install of mysql-community-libs-compat-8.0.13-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.73-8.0.1.el6_8.x86_64

5:安装完成后执行 mysql -v 有显示版本为 8.0.13 就代表成功了

启动: /etc/init.d/mysqld start
停止: /etc/init.d/mysqld stop
重启: /etc/init.d/mysqld restart
默认datadir:/var/lib/mysql/
配置文件:/etc/my.cnf

6:修改密码 CentOS MySQL8 忘记密码

7:PHP 运行连接的时候字符集报错,MySQL8 的默认字符集是 utf8mb4, 修改配置文件,重启 mysql

[mysqld]
character-set-server = utf8
[mysql]
default-character-set=utf8
[client]
default-character-set=utf8

8:再次连接还是报错

The server requested authentication method unknown to the client

发生这种错误,是由于 MySQL 8 默认使用了新的密码验证插件:caching_sha2_password,而之前的 PHP 版本中所带的 mysqlnd 无法支持这种验证。

解决方法:打开 /etc/my.cnf 此行,重启 mysql

# default-authentication-plugin=mysql_native_password

9:连接成功