安装MySQL5.7

1.下载mysql5.7软件包

1.下载mysql5.7软件包

下载地址:

https://dev.mysql.com/downloads/repo/yum/

# 下载

shell> wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

# 安装 mysql 源

shell> yum localinstall mysql57-community-release-el7-11.noarch.rpm

 

安装MySQL5.7

 

2.查看mysql是否安装成功

[root@localhost ~]# yum repolist enabled | grep "mysql.*-community.*"

mysql-connectors-community/x86_64 MySQL Connectors Community 175

mysql-tools-community/x86_64 MySQL Tools Community 120

mysql57-community/x86_64 MySQL 5.7 Community Server 464

mysql80-community/x86_64 MySQL 8.0 Community Server 211

注:以上mysql源中包括了mysql5.7和mysql8.0这两个安装包,如需要下改其他mysql软件包,如下载mysql5.6等版本需要修改/etc/yum.repos.d/mysql-community.repo配置文件中的enable选项

# Enable to use MySQL 5.5

[mysql55-community]

name=MySQL 5.5 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.6

[mysql56-community]

name=MySQL 5.6 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.7

[mysql57-community]

name=MySQL 5.7 Community Server

baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]

name=MySQL 8.0 Community Server

baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-connectors-community]

name=MySQL Connectors Community

baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]

name=MySQL Tools Community

baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-preview]

name=MySQL Tools Preview

baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.5-community]

name=MySQL Cluster 7.5 Community

baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-7.6-community]

name=MySQL Cluster 7.6 Community

baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-cluster-8.0-community]

name=MySQL Cluster 8.0 Community

baseurl=http://repo.mysql.com/yum/mysql-cluster-8.0-community/el/7/$basearch/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

View Code

2.安装mysql软件

安装mysql5.7软件

yum install mysql-community-server -y

启动服务

systemct start mysqld

[root@localhost ~]# mysqld --version

mysqld Ver 5.7.32 for Linux on x86_64 (MySQL Community Server (GPL))

设置开机自启动

systemctl enable mysqld

systemctl daemon-reload

注:mysql5.7在安装后,会/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改

[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log

2020-12-12T20:36:30.875750Z 1 [Note] A temporary password is generated for root@localhost: Ljy_GM<ws6sh

使用账户密码进行登录数据库

[root@localhost ~]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.32

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.
............................
注:用户在第一次登录数据库时需要进行更改用户密码才能操作数据库

 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'ABC_123abc';
 Query OK, 0 rows affected (0.00 sec)

mysql> select version();

+-----------+
| version() |
+-----------+
| 5.7.32 |
+-----------+
1 row in set (0.00 sec)

以上是 安装MySQL5.7 的全部内容, 来源链接: utcz.com/a/76484.html

回到顶部