计算机网络/计算机科学与应用/系统/运维/开发

RPM方式安装MySQL8数据库

一、RPM方式安装MySQL8.0

系统:CentOS7.x  MySQL8  


MySQL官网:https://downloads.mysql.com/archives/community/


# 检查是否安装过MySQL,如果有,需要先卸载

[root@Linux ~]# rpm -qa|grep -i mysql


# 安装依赖包

[root@Linux ~]# rpm -qa|grep libaio
libaio-0.3.109-13.el7.x86_64
[root@Linux ~]# rpm -qa|grep net-tools
net-tools-2.0-0.25.20131004git.el7.x86_64


# 下载MySQl包

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar


# 解压MySQL包

[root@Linux ~]# tar xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar 
mysql-community-client-8.0.28-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
mysql-community-common-8.0.28-1.el7.x86_64.rpm
mysql-community-devel-8.0.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-8.0.28-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.28-1.el7.x86_64.rpm
mysql-community-server-8.0.28-1.el7.x86_64.rpm
mysql-community-test-8.0.28-1.el7.x86_64.rpm
[root@Linux ~]#


# 依次按顺序安装

[root@Linux ~]#  rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm
warning: mysql-community-common-8.0.28-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing...                          ################################# [100%]
package mysql-community-common-8.0.28-1.el7.x86_64 is already installed
[root@Linux ~]# rpm -ivh mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
warning: mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-plugins-8.################################# [100%]
[root@Linux ~]# rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.28-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-8.0.28-1.el7################################# [100%]
[root@Linux ~]# rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.28-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-8.0.28-1.e################################# [100%]
[root@Linux ~]# rpm -ivh mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
warning: mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-icu-data-files-8.################################# [100%]
[root@Linux ~]# rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.28-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-8.0.28-1.e################################# [100%]


# 查看安装的相关包

[root@Linux ~]# rpm -qa|grep -i mysql
mysql-community-client-plugins-8.0.28-1.el7.x86_64
mysql-community-server-8.0.28-1.el7.x86_64
mysql-community-common-8.0.28-1.el7.x86_64
mysql-community-libs-8.0.28-1.el7.x86_64
mysql-community-icu-data-files-8.0.28-1.el7.x86_64
mysql-community-client-8.0.28-1.el7.x86_64


# 查看MySQL版本

[root@Linux ~]# mysqladmin --version
mysqladmin  Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)


# 查看启动MySQl服务

[root@Linux ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html


# 启动MySQL服务

[root@Linux ~]# systemctl start mysqld


# 初次登陆查看临时密码 

[root@Linux ~]# grep "temporary password" /var/log/mysqld.log 
2022-08-29T09:14:46.125515Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: )m2Rtio3L<ld


# 登陆MySQL

[root@Linux ~]# mysql -uroot -p  (密码是)m2Rtio3L<ld)
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.28
Copyright (c) 2000, 2022, 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.
mysql>


# 修改密码

mysql> alter user root@'localhost' identified by 'Zhao825520*';
Query OK, 0 rows affected (0.01 sec)


# 刷新数据缓存

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


# 创建远程登录并授权

mysql> create user root@'%' identified by 'Zhao825520*';
Query OK, 0 rows affected (0.01 sec)

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

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


# 修改加密规则

mysql>ALTER USER root@'%' IDENTIFIED BY '密码' PASSWORD EXPIRE NEVER;


# 更新一下用户的密码

mysql>ALTER USER root@'%' IDENTIFIED WITH mysql_native_password BY '密码';


# 刷新权限

mysql>FLUSH PRIVILEGES;

# 关闭防火墙

[root@Linux ~]# systemctl stop firewalld.service


# 禁止防火墙开机启动

[root@Linux ~]# systemctl disable firewalld.service


此时,就可以通过MySQL工具远程链接mysql.


rpm mysql8

只有惜缘,才有缘分;只有惜友,才有友谊。

评论

image

40 2022-08-29 05:08:17

参考:https://zhuanlan.zhihu.com/p/370585453

回复 删除

^