本次将在Linux下经过yum安装MySQL,安装的版本为MySQL 5.7,官网中是最新版本8.0,在网上查了下,发现最新版本的yum源也包含了旧版本,而咱们,只须要在安装时启用 5.7 的安装便可。mysql
本人环境:CentOS 7.3 64位sql
yum list installed |grep mysqlvim
若是存在系统自带的mysql及依赖,则经过 yum remove 将其卸载oracle
这里获取到的是最新版本的下载地址:https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpmapp
下载rpm包:wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm --no-check-certificate
安装mysql源:yum localinstall mysql80-community-release-el7-3.noarch.rpmide
经过 yum localinstall 安装mysql源,能够帮助咱们解决本地rpm包的依赖问题。post
最后,验证是否安装成功:yum repolist all | grep mysqlui
从上面的图片,咱们能够看到,默认是MySQL 8.0可用,咱们若想安装MySQL 5.7,则需启用5.7。接下来经过直接修改配置文件来设置启用。this
vim /etc/yum.repos.d/mysql-community.repo3d
输入上面的命令,在编辑界面,先输入 i 进入编辑模式,将8.0的 enabled 设置为0,将5.7的 enabled 设置为1,以下:
接着按 Esc 退出编辑模式,最后输入 :wq 保存并退出。
再次输入命令:yum repolist all | grep mysql ,能够看到8.0已被禁用,而5.7是启用的。
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.10.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 <mysql-build@oss.oracle.com>" Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 Package : mysql80-community-release-el7-3.noarch (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!
在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
mysql -u root -p
在要求输入密码时,由于mysql 5.7的初始密码不是空,直接按回车键不能成功登陆,所以需先找到初始密码,才能登陆。
grep 'temporary password' /var/log/mysqld.log
如上,最后的内容就是初始密码。
再次登陆,输入初始密码,便可成功登陆。
第一次登陆成功后,发现不能执行操做,同时提示让修改密码。
alter user root@localhost identified by '新密码'
这里,我想设置新密码为 123456,但出现了报错,这里的报错是mysql的密码策略问题,输入命令:show variables like 'validate_password%',查看 mysql 初始的密码策略,发现密码的最小长度为8,密码的验证强度等级为MEDIUM,能够修改一下密码策略:
设置密码的验证强度等级:set global validate_password_policy=LOW
设置密码的最小长度:set global validate_password_length=6
好了,这时咱们再次执行修改密码的sql,便不会报错了。
最后经过 flush privileges 刷新权限,使当前操做当即生效,就大功告成了。
注意:最后这里,也能够不修改密码策略,只要本身设置的密码知足MySQL的原密码策略便可。