环境信息
系统: centos7
数据库: MySql 8.0.21
1 下载离线安装包
官网地址:
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 进行上传
文件上传.png
3 解压文件到指定位置
当前演示解压到/opt/module/mysql下,目录不存在需自己创建
[root@localhost ~]# cd /opt/software/
[root@localhost module]# tar -zxvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar -C /opt/module/mysql
[root@localhost ~]# cd /opt/module/mysql
4 执行安装命令
执行过程中会自动处理依赖关系
处理依赖关系.png
输入y.png
安装完成.png
5 修改密码
5.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
5.2 修改MySQL密码
[root@localhost ~]# mysql_secure_installation
输入随机密码,然后确认,再更改新的密码,再确认
5.3 修改默认密码验证方式
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 允许远程连接
mysql> use mysql;
mysql> mysql update user set host="%" where user="root";
mysql> flush privileges;
7 服务管理
7.1 启动服务
[root@localhost ~]# systemctl start mysqld
7.2 暂停服务
[root@localhost ~]# systemctl stop mysqld
7.3 重启服务
[root@localhost ~]# systemctl restart mysqld
7.4 开放防火墙端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
[root@localhost ~]# firewall-cmd --reload