CentOS 7 傻瓜式安装 MySQL 8.0+ 版本数据库(8.0.20)

1. 从MySQL官网,下载MySQL所需要的安装包。

 网址:https://dev.mysql.com/downloads/mysql/
 
 Select Operating System: 选择 Red Hat(因为CentOS 是基于红帽的);Select OS Version: 选择 linux 7

 下载第一个: mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar

CentOS 7 傻瓜式安装 MySQL 8.0+ 版本数据库(8.0.20)_第1张图片

2. 点击 No thanks, just start my download. 进行下载,cp到虚拟机里

 [root@zw ~]# cd /opt
[root@zw opt]# ls
mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar

3. 通过tar 解压

[root@zw opt]# tar -xvf  mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar 
mysql-community-libs-8.0.20-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.20-1.el7.x86_64.rpm
mysql-community-test-8.0.20-1.el7.x86_64.rpm
mysql-community-common-8.0.20-1.el7.x86_64.rpm
mysql-community-devel-8.0.20-1.el7.x86_64.rpm
mysql-community-client-8.0.20-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.20-1.el7.x86_64.rpm
mysql-community-server-8.0.20-1.el7.x86_64.rpm

[root@zw opt]# ls
mysql-8.0.20-1.el7.x86_64.rpm-bundle.tar        mysql-community-devel-8.0.20-1.el7.x86_64.rpm            mysql-community-libs-compat-8.0.20-1.el7.x86_64.rpm
mysql-community-client-8.0.20-1.el7.x86_64.rpm  mysql-community-embedded-compat-8.0.20-1.el7.x86_64.rpm  mysql-community-server-8.0.20-1.el7.x86_64.rpm
mysql-community-common-8.0.20-1.el7.x86_64.rpm  mysql-community-libs-8.0.20-1.el7.x86_64.rpm             mysql-community-test-8.0.20-1.el7.x86_64.rpm

4、通过 rpm -ivh 安装

[root@zw opt]# rpm -ivh mysql-community-common-8.0.20-1.el7.x86_64.rpm --nodeps --force
警告:mysql-community-common-8.0.20-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-8.0.20-1.e################################# [100%]
[root@zw opt]# rpm -ivh mysql-community-c --nodeps --force
mysql-community-client-8.0.20-1.el7.x86_64.rpm  mysql-community-common-8.0.20-1.el7.x86_64.rpm  
[root@zw opt]# rpm -ivh mysql-community-client-8.0.20-1.el7.x86_64.rpm --nodeps --force
警告:mysql-community-client-8.0.20-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-8.0.20-1.e################################# [100%]
[root@zw opt]# rpm -ivh mysql-community-server-8.0.20-1.el7.x86_64.rpm --nodeps --force
警告:mysql-community-server-8.0.20-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-8.0.20-1.e################################# [100%]

5. 通过以下命令,完成对 mysql 数据库的初始化和相关配置

[root@zw opt]# mysqld --initialize
[root@zw mysql]# chown mysql:mysql /var/lib/mysql -R
[root@zw mysql]# systemctl start mysqld.service
[root@zw mysql]# systemctl status  mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2020-06-08 17:32:33 CST; 26s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 22395 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 22445 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─22445 /usr/sbin/mysqld

6月 08 17:32:02 zw systemd[1]: Starting MySQL Server...
6月 08 17:32:33 zw systemd[1]: Started MySQL Server.

6. 查看日志获取初始密码,连接mysql修改初始密码

[root@zw ~]#  grep password /var/log/mysqld.log
2020-06-08T09:30:18.510275Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: pu4pj6bIBZ&g

[root@zw mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.20

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>

7.修改root,并开启远程访问(修改密码为Welljoint,123)

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Welljoint,123';
Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> create user 'root'@'%' identified with mysql_native_password by 'Welljoint,123'; #开启远程登录授权
Query OK, 0 rows affected (0.01 sec)

mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.05 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)

mysql> exit
Bye

8. Navicat使用 连接测试

CentOS 7 傻瓜式安装 MySQL 8.0+ 版本数据库(8.0.20)_第2张图片

你可能感兴趣的:(linux,mysql,运维)