环境信息
系统:
centos7
数据库:
MySql 8.0.21
环境信息
资源信息 | 版本 | 备注 |
---|---|---|
服务器 | Centos7 | 使用的虚拟机 |
数据库 | MySql 8.0.21 | 使用的 *rpm 安装方式 |
1 下载离线安装包
官网地址:https://downloads.mysql.com/archives/community/
CSDN 下载地址: https://download.csdn.net/download/qq_15769939/14504214
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IIkEkWMM-1619339949985)(Centos7 离线安装和配置mysql8.assets/mysql离线安装包下载.png)]
2 上传文件到服务器
可以用ftp工具,这里我使用命令进行文件上传,上传目录到 /opt/software/
目录不存在需自己创建
1:输入rz命令,看是否已经安装了lrzsz,如果没有安装则执行 yum -y install lrzsz命令进行安装。
[root@localhost ~]# rz
-bash: rz: command not found
[root@localhost ~]# yum -y install lrzsz
2:安装成功后查看是否安装成功
[root@localhost ~]# rpm -qa lrzsz
lrzsz-0.12.20-36.el7.x86_64
3:输入rz -y 进行上传
3 解压文件到指定位置
当前演示解压到/opt/module/mysql下,
目录不存在需自己创建
[root@localhost ~]# cd /opt/software/
[root@localhost module]# tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar -C /opt/module/mysql
[root@localhost ~]# cd /opt/module/mysql
4 执行安装命令
[root@localhost mysql]# yum localinstall *.rpm
执行过程中会自动处理依赖关系
5 启动服务
[root@localhost mysql]# systemctl start mysqld
6 安装与配置
6.1 修改默认密码
6.1.1 查看默认密码
[root@localhost ~]# cat /var/log/mysqld.log | grep "A temporary password"
2021-01-15T06:46:57.734199Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: xQ4bCD)6Im1p
6.1.2 修改密码
[root@localhost ~]# mysql_secure_installation
输入随机密码,然后确认,再更改新的密码,再确认
6.2 修改密码验证方式
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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> 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> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host | User | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY '123456';
mysql> FLUSH PRIVILEGES;
mysql> SELECT Host, User, plugin from user;
+-----------+------------------+-----------------------+
| Host | User | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
6.3 允许远程连接
mysql> use mysql;
mysql> mysql update user set host="%" where user="root";
mysql> flush privileges;
6.4 开放防火墙
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost ~]# firewall-cmd --reload
7 启动与测试
7.1 服务管理
7.1.1 启动mysql8
[root@localhost ~]# systemctl restart mysqld
7.1.2 停止mysql8
停止
systemctl stop mysqld
重启
[root@localhost ~]# systemctl restart mysqld
7.2 访问测试
这里使用
navicat
连接测试
9 相关信息
- 博文不易,辛苦各位猿友点个关注和赞,感谢