第一步:下载离线安装包
下载地址:https://dev.mysql.com/downloads/
第二步:上传下载包到服务器
上传文件mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar到服务器上。
第三步:解压文件包
切换到上传文件目录下运行如下命令:
[root@gelong-vm1 rpms]# tar -vxf mysql-8.0.18-1.el7.x86_64.rpm-bundle.tar mysql-community-libs-8.0.18-1.el7.x86_64.rpm mysql-community-devel-8.0.18-1.el7.x86_64.rpm mysql-community-embedded-compat-8.0.18-1.el7.x86_64.rpm mysql-community-libs-compat-8.0.18-1.el7.x86_64.rpm mysql-community-common-8.0.18-1.el7.x86_64.rpm mysql-community-test-8.0.18-1.el7.x86_64.rpm mysql-community-server-8.0.18-1.el7.x86_64.rpm mysql-community-client-8.0.18-1.el7.x86_64.rpm
第四步:卸载系统自带的数据库
1.检查系统自带的 MariaDB
检查系统是否自带MariaDB,命令如下:
rpm -qa | grep mariadb
如果系统自带MariaDB,删除掉,删除命令如下:
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
2.检查系统自带的mysql数据库安装包
检查系统是否自带Mysql数据库,名利如下:
rpm -qa | grep mysql
如果系统自带mysql数据库,删除掉,删除命令如下:
rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64
第五步:按照顺序安装mysql数据库
按照如下顺序安装:
rpm -ivh mysql-community-common-8.0.18-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-8.0.18-1.el7.x86_64.rpm rpm -ivh mysql-community-client-8.0.18-1.el7.x86_64.rpm rpm -ivh mysql-community-server-8.0.18-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm
1.安装mysql-community-server-8.0.18-1.el7.x86_64.rpm 报错解决方案
安装 mysql-community-server-8.0.18-1.el7.x86_64.rpm
的时候需要依赖 net-tools
,如果没有 net-tools
会安装失败,此时先安装 net-tools
,然后再安装 mysql-community-server-8.0.18-1.el7.x86_64.rpm
即可,安装命令如下:
# 安装 mysql-community-server-8.0.25-1.el7.x86_64.rpm 依赖报错 [root@sangni mysql-installation]# rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm 警告:mysql-community-server-8.0.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY 错误:依赖检测失败: net-tools 被 mysql-community-server-8.0.25-1.el7.x86_64 需要 # 安装 net-tools [root@sangni mysql-installation]# yum install net-tools 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.njupt.edu.cn * extras: mirrors.njupt.edu.cn * updates: mirrors.njupt.edu.cn 正在解决依赖关系 --> 正在检查事务 ---> 软件包 net-tools.x86_64.0.2.0-0.25.20131004git.el7 将被 安装 --> 解决依赖关系完成 依赖关系解决 ================================================================================================================================== Package 架构 版本 源 大小 ================================================================================================================================== 正在安装: net-tools x86_64 2.0-0.25.20131004git.el7 base 306 k 事务概要 ================================================================================================================================== 安装 1 软件包 总下载量:306 k 安装大小:917 k Is this ok [y/d/N]: y Downloading packages: net-tools-2.0-0.25.20131004git.el7.x86_64.rpm | 306 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 警告:RPM 数据库已被非 yum 程序修改。 ** 发现 2 个已存在的 RPM 数据库问题, 'yum check' 输出如下: 2:postfix-2.10.1-9.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit) 2:postfix-2.10.1-9.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit) 正在安装 : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1 验证中 : net-tools-2.0-0.25.20131004git.el7.x86_64 1/1 已安装: net-tools.x86_64 0:2.0-0.25.20131004git.el7 完毕! # net-tools 安装完成后再次安装 mysql-community-server-8.0.25-1.el7.x86_64.rpm [root@sangni mysql-installation]# rpm -ivh mysql-community-server-8.0.25-1.el7.x86_64.rpm 警告:mysql-community-server-8.0.25-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY 准备中... ################################# [100%] 正在升级/安装... 1:mysql-community-server-8.0.25-1.e################################# [100%]
2.安装 rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm 报错解决方案
[root@192 mysql]# rpm -ivh mysql-community-devel-8.0.18-1.el7.x86_64.rpm warning: mysql-community-devel-8.0.25-1.el7.x86_64.rpm: Header V3 DSA/SHA256 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: pkgconfig(openssl) is needed by mysql-community-devel-8.0.25-1.el7.x86_64
解决办法
yum install openssl-devel
特别说明:关于mysql8之后的大小写问题
在MySQL8中,数据目录初始化之后,不再允许更改lower_case_table_names=1
的值;也就是说启动(重启)MYSQL时,lower_case_table_names
的值必须于,初始化MYSOL时(安装 MYSOL后的首次启动)的值相同。
由于我的业务是有需求的,所以我先设置关闭大小写验证
#进入目录 cd /etc/ #编辑my.cnf文件 vi /etc/my.cnf #添加内容 lower_case_table_names=1
通常,0 表示大小写敏感,1 表示大小写不敏感。
相关文章:
CentOS 上查看 MySQL 的大小写敏感状态
centos 安装MySQL 8.0 区分大小写解决方法
第六步:启动mysql服务
1.启动MYSQL服务:
[root@gelong-vm1 rpms]# service mysqld start Redirecting to /bin/systemctl start mysqld.service
2.查看启动状态:
[root@gelong-vm1 rpms]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 二 2023-09-05 14:19:46 CST; 38s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 15236 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 15315 (mysqld) Status: "Server is operational" CGroup: /system.slice/mysqld.service └─15315 /usr/sbin/mysqld 9月 05 14:19:34 gelong-vm1 systemd[1]: Starting MySQL Server... 9月 05 14:19:46 gelong-vm1 systemd[1]: Started MySQL Server.
第七步:修改默认密码开启远程连接
1.查看默认密码:
查看默认密码命令如下
[root@gelong-vm1 rpms]# grep 'temporary password' /var/log/mysqld.log 2023-09-05T06:19:39.121134Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: iU/%Q(3w<AO*
2.使用默认密码登录mysql:
[root@gelong-vm1 rpms]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.23 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.
3.修改 root 用户密码:
注意:这里修改的密码要足够复杂,包含大小和特殊符号;
mysql> alter user 'root'@'localhost' identified by 'Houpu123!@#'; Query OK, 0 rows affected (0.62 sec) mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.23 | +-----------+ 1 row in set (0.00 sec)
4.修改 root 用户的 host 列值,开启远程连接:
修改运行远程连接命令如下:
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select host from user; +-----------+ | host | +-----------+ | % | | localhost | | localhost | | localhost | +-----------+ 4 rows in set (0.00 sec)
5.刷新缓存:
重新刷新mysql的缓存内容命令:
mysql> flush privileges; Query OK, 0 rows affected (0.47 sec)
6.给 root 用户授予所有权限:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; Query OK, 0 rows affected (0.02 sec)
解决远程连接时报错
2059-Authentication plugin ‘caching_sha2_password‘
- 出现原因
安装的时候,选择了强加密规则caching_sha2_password
,与之前的mysql
的mysql_native_password
规则不同,navicate
驱动目前不支持新加密规则
- 解决方法
通过更改加密规则和刷新权限的方式
use mysql; #选择数据库 # 远程连接请将'%'换成'localhost' ALTER USER 'root'@'%' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER; #更改加密方式 ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; #更新用户密码 FLUSH PRIVILEGES; #刷新权限
8.退出mysql控制台:
exit;