前言:
最近项目需要搭建集群,处于数据安全性的考虑不能连接外网。这样的前提下,需要在CentOS 7 系统的测试服务器上安装 MySQL 5.7.17。手动安装比yum安装麻烦很多。所以在这里写文章记录安装过程,以便于后边再碰到类似问题。
1.mysql下载
mysql下载路径:https://dev.mysql.com/downloads/mysql/
根据自己的linux版本选择对应的安装包
几分钟就下载了。
以下是下载好的文件
mysql-5.7.20-1.el7.x86_64.rpm-bundle.tar
2.准备依赖包
依赖包下载网页:
https://centos.pkgs.org/7/centos-x86_64/
红框处直接搜索需要的依赖包
我这里缺的依赖包有:libaio、m4、net-tools
m4依赖包为例:
- 搜索 m4 ——> 下图红框处(尽量选后缀无noarch依赖)
- 将红框处地址拷贝,并在浏览器打开
下载好的依赖包有以下:
libaio-0.3.109-13.el7.x86_64.rpm
m4-1.4.16-10.el7.x86_64.rpm
net-tools-2.0-0.25.20131004git.el7.x86_64.rpm
3. 依赖包的安装
将依赖包上传到服务器,依次进行安装
[root@imax rh]# rpm -ivh m4-1.4.16-10.el7.x86_64.rpm
warning: m4-1.4.16-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:m4-1.4.16-10.el7 ################################# [100%]
[root@imax rh]# rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
Preparing... ################################# [100%]
package libaio-0.3.109-13.el7.x86_64 is already installed
[root@imax rh]# rpm -ivh net-tools-2.0-0.25.20131004git.el7.x86_64.rpm
warning: net-tools-2.0-0.25.20131004git.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOK EY
Preparing... ################################# [100%]
package net-tools-2.0-0.25.20131004git.el7.x86_64 is already installed
4. 卸载自带的Mysql-libs
[root@imax rh]# rpm -qa | grep -i -E mysql\|mariadb | xargs -n1 sudo rpm -e --nodeps
5. mysql安装包的安装
[root@imax rh]# rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKE Y
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.17-1.e################################# [100%]
[root@imax rh]# rpm -ivh mysql-community-libs-*
warning: mysql-community-libs-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.17-1.el7################################# [ 50%]
2:mysql-community-libs-compat-5.7.1################################# [100%]
[root@imax rh]# rpm -ivh mysql-community-devel-5.7.17-1.el7.x86_64.rpm
warning: mysql-community-devel-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-devel-5.7.17-1.el################################# [100%]
[root@imax rh]# rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKE Y
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.17-1.e################################# [100%]
[root@imax rh]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKE Y
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.17-1.e################################# [100%]
[root@imax rh]# rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKE Y
Preparing... ################################# [100%]
package mysql-community-client-5.7.17-1.el7.x86_64 is already installed
[root@imax rh]# rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKE Y
Preparing... ################################# [100%]
package mysql-community-common-5.7.17-1.el7.x86_64 is already installed
[root@imax rh]# rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKE Y
Preparing... ################################# [100%]
package mysql-community-client-5.7.17-1.el7.x86_64 is already installed
[root@imax rh]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKE Y
Preparing... ################################# [100%]
package mysql-community-server-5.7.17-1.el7.x86_64 is already installed
6. 启动mysql并修改端口号密码
1启动mysql
[root@imax rh]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@imax rh]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2017-11-04 13:56:37 CST; 24s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 4644 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 4571 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4647 (mysqld)
CGroup: /system.slice/mysqld.service
└─4647 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Nov 04 13:56:07 linuxidc systemd[1]: Starting MySQL Server...
Nov 04 13:56:37 linuxidc systemd[1]: Started MySQL Server.
2 重设mysql密码
查看默认密码
[root@imax rh]# cat /var/log/mysqld.log | grep password
2017-11-04T05:56:08.454323Z 1 [Note] A temporary password is generated for root@localhost: ps1DY?%T.Vc4
登录mysql
[root@linuxidc ~]# mysql -u root -p'ps1DY?%T.Vc4'
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
密码重设
设置复杂密码(由于MySQL密码策略,此密码必须足够复杂)
mysql> set password=password("Qs23=zs32");
更改MySQL密码策略
mysql> set global validate_password_length=4;
mysql> set global validate_password_policy=0;
更改密码策略后便可以更改更容易记的密码了
mysql> set password=password("123456");
3 端口号更改
查看当前端口号
mysql>show global variables like 'port';
3.修改端口:编辑/etc/my.cnf文件
[root@imax rh]# vi /etc/my.cnf
在 [mysqld] 后加一行
port=3308