Linux下安装MySQL5.7
本次将在Linux下通过yum安装MySQL,安装的版本为MySQL 5.7,官⽹中是最新版本8.0,在⽹上查了下,发现最新版本的yum源也包含了旧版本,⽽我们,只需要在安装时启⽤ 5.7 的安装即可。
本⼈环境:CentOS 7.3 64位
1.检查CentOS是否有系统⾃带的mysql
yum list installed | grep mysql
如果存在系统⾃带的mysql及依赖,则通过 yum remove 将其卸载
2.在官⽹中获取yum源
这⾥获取到的是最新版本的下载地址:
3.CentOS中下载rpm包,并安装本地mysql源
mysql下载下来没安装包下载rpm包:wget --no-check-certificate
安装mysql源:yum arch.rpm
通过 yum localinstall 安装mysql源,可以帮助我们解决本地rpm包的依赖问题。
最后,验证是否安装成功:yum repolist all | grep mysql
4.修改默认安装版本为
5.7
从上⾯的图⽚,我们可以看到,默认是MySQL 8.0可⽤,我们若想安装MySQL 5.7,则需启⽤5.7。接下来通过直接修改配置⽂件来设置启⽤。
vim /pos.po
输⼊上⾯的命令,在编辑界⾯,先输⼊ i 进⼊编辑模式,将8.0的 enabled 设置为0,将5.7的 enabled 设置为1,如下:
接着按 Esc 退出编辑模式,最后输⼊ :wq 保存并退出。
再次输⼊命令:yum repolist all | grep mysql ,可以看到8.0已被禁⽤,⽽5.7是启⽤的。
5.安装MySQL
yum install mysql-community-server
输⼊上⾯命令,进⾏安装即可。
[root@wintest mysql]# yum install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.27-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.27-1.el7 for package: mysql-community-server-5.7.27-1.el7.x86_64 --> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.27-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-5.7.27-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-5.7.27-1.el7.x86_64
-
-> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-5.7.27-1.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package mysql-community-client.x86_64 0:5.7.27-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.27-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.27-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.1
0.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.27-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.27-1.el7 will be obsoleting
---> Package postfix.x86_64 2:2.10.1-6.el7 will be updated
---> Package postfix.x86_64 2:2.10.1-7.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================
Package                      Arch    Version          Repository          Size
====================================================================================
Installing:
mysql-community-libs          x86_64  5.7.27-1.el7      mysql57-community  2.2 M
replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
mysql-community-libs-compat  x86_64  5.7.27-1.el7      mysql57-community  2.0 M
replacing  mariadb-libs.x86_64 1:5.5.52-1.el7
mysql-community-server        x86_64  5.7.27-1.el7      mysql57-community  165 M
Installing for dependencies:
libaio                        x86_64  0.3.109-13.el7    base                24 k
mysql-community-client        x86_64  5.7.27-1.el7      mysql57-community    24 M
mysql-community-common        x86_64  5.7.27-1.el7      mysql57-community  275 k
Updating for dependencies:
postfix                      x86_64  2:2.10.1-7.el7    base                2.4 M
Transaction Summary
====================================================================================
Install  3 Packages (+3 Dependent packages)
Upgrade            ( 1 Dependent package)
Total download size: 197 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/7): libaio-0.3.109-13.el7.x86_64.rpm                      |  24 kB  00:00:00
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.27-
1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Public key for mysql-community-common-5.7.27-1.el7.x86_64.rpm is not installed
(2/7): mysql-community-common-5.7.27-1.el7.x86_64.rpm        | 275 kB  00:00:01
(3/7): mysql-community-libs-5.7.27-1.el7.x86_64.rpm          | 2.2 MB  00:00:01
(4/7): mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm  | 2.0 MB  00:00:01
(5/7): postfix-2.10.1-7.el7.x86_64.rpm                      | 2.4 MB  00:00:00
(6/7): mysql-community-client-5.7.27-1.el7.x86_64.rpm        |  24 MB  00:00:34
(7/7): mysql-community-server-5.7.27-1.el7.x86_64.rpm        | 165 MB  00:00:52
------------------------------------------------------------------------------------
Total                                                  3.5 MB/s | 197 MB  00:56
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid    : "MySQL Release Engineering <acle>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package    : arch (installed)
From      : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-common-5.7.27-1.el7.x86_64                      1/9
Installing : mysql-community-libs-5.7.27-1.el7.x86_64                        2/9
Installing : mysql-community-libs-compat-5.7.27-1.el7.x86_64                  3/9
Installing : mysql-community-client-5.7.27-1.el7.x86_64                      4/9
Installing : libaio-0.3.109-13.el7.x86_64                                    5/9
Installing : mysql-community-server-5.7.27-1.el7.x86_64                      6/9
Updating  : 2:postfix-2.10.1-7.el7.x86_64                                    7/9
Cleanup    : 2:postfix-2.10.1-6.el7.x86_64                                    8/9
Erasing    : 1:mariadb-libs-5.5.52-1.el7.x86_64                              9/9
Verifying  : mysql-community-libs-compat-5.7.27-1.el7.x86_64                  1/9
Verifying  : mysql-community-common-5.7.27-1.el7.x86_64                      2/9
Verifying  : mysql-community-libs-5.7.27-1.el7.x86_64                        3/9
Verifying  : 2:postfix-2.10.1-7.el7.x86_64                                    4/9
Verifying  : mysql-community-server-5.7.27-1.el7.x86_64                      5/9
Verifying  : mysql-community-client-5.7.27-1.el7.x86_64                      6/9
Verifying  : libaio-0.3.109-13.el7.x86_64                                    7/9
Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                              8/9
Verifying  : 2:postfix-2.10.1-6.el7.x86_64                                    9/9
Installed:
mysql-community-libs.x86_64 0:5.7.27-1.el7
mysql-community-libs-compat.x86_64 0:5.7.27-1.el7
mysql-community-server.x86_64 0:5.7.27-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7
mysql-community-client.x86_64 0:5.7.27-1.el7
mysql-community-common.x86_64 0:5.7.27-1.el7
Dependency Updated:
postfix.x86_64 2:2.10.1-7.el7
Replaced:
mariadb-libs.x86_64 1:5.5.52-1.el7
Complete!
6.启⽤MySQL
在CentOS 6中,我们⼀般通过 service mysqld start 来启动mysql,在CentOS 7中,如果直接输⼊ service mysqld start ,则会出现以下信息:
这是因为 CentOS 7 下重启服务不再通过 service 操作,⽽是通过 systemctl 操作,因此我们可以输⼊命令:
启动mysql:systemctl start mysqld.service
查看mysql状态:systemctl status mysqld.service
7.登录mysql
mysql -u root -p
在要求输⼊密码时,因为mysql 5.7的初始密码不是空,直接按回车键不能成功登录,因此需先到初始密码,才能登录。
grep 'temporary password' /var/log/mysqld.log
如上,最后的内容就是初始密码。
再次登录,输⼊初始密码,即可成功登录。
第⼀次登录成功后,发现不能执⾏操作,同时提⽰让修改密码。
8.修改登录密码
alter user root@localhost identified by '新密码'

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。