首先去下载rpm安装包:
https://dev.mysql.com/downloa…
,选择红帽linux64位版。然后上传到服务器中。
[root@cs mysql]# ls
mysql-community-client-5.7.20-1.el7.x86_64.rpm mysql-community-embedded-5.7.20-1.el7.x86_64.rpm mysql-community-libs-5.7.20-1.el7.x86_64.rpm mysql-community-server-5.7.20-1.el7.x86_64.rpm
mysql-community-common-5.7.20-1.el7.x86_64.rpm mysql-community-embedded-compat-5.7.20-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm mysql-community-server-minimal-5.7.20-1.el7.x86_64.rpm
mysql-community-devel-5.7.20-1.el7.x86_64.rpm mysql-community-embedded-devel-5.7.20-1.el7.x86_64.rpm mysql-community-minimal-debuginfo-5.7.20-1.el7.x86_64.rpm mysql-community-test-5.7.20-1.el7.x86_64.rpm
接下来就是安装了,如果是普通用户需要sudo权限,并在执行命令前加sudo。如果安装过mysql先用命令卸载掉相关的包。rpm安装是有依赖关系的所以我们要按照顺序进行安装:
[root@cs mysql]# rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.20-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.52-1.el7.x86_64
提示和我们安装的有冲突,我们找到这个包并卸载掉:
[root@cs mysql]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@cs mysql]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
再次安装:
[root@cs mysql]# rpm -ivh mysql-community-common-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-5.7.20-1.e################################# [100%]
[root@cs mysql]# rpm -ivh mysql-community-libs-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-5.7.20-1.el7################################# [100%]
[root@cs mysql]# rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.20-1.e################################# [100%]
[root@cs mysql]# rpm -ivh mysql-community-client-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-5.7.20-1.e################################# [100%]
[root@cs mysql]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libaio.so.1()(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.20-1.el7.x86_64
提示安装失败,这是因为我们少这个依赖库,用yum进行安装:
[root@cs mysql]# yum install libaio
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================
Installing:
libaio x86_64 0.3.109-13.el7 base 24 k
Transaction Summary
==============================================================================================================================================================================================================================================================================
Install 1 Package
Total download size: 24 k
Installed size: 38 k
Is this ok [y/d/N]: y
Downloading packages:
libaio-0.3.109-13.el7.x86_64.rpm | 24 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 2 pre-existing rpmdb problem(s), 'yum check' output follows:
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 has missing requires of libmysqlclient.so.18(libmysqlclient_18)(64bit)
Installing : libaio-0.3.109-13.el7.x86_64 1/1
Verifying : libaio-0.3.109-13.el7.x86_64 1/1
Installed:
libaio.x86_64 0:0.3.109-13.el7
Complete!
再次安装:
[root@cs mysql]# rpm -ivh mysql-community-server-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-5.7.20-1.e################################# [100%]
[root@cs mysql]# rpm -ivh mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm
warning: mysql-community-libs-compat-5.7.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-compat-5.7.2################################# [100%]
到此,安装完成。然后我们进行初始化数据库,因为我是root安装的所以想要指定一个mysql用,用mysql启动。根据自己的需要也可以不加。初始化:
[root@cs mysql]# mysqld --initialize --user=mysql
启动数据库并:
[root@cs mysql]# systemctl start mysqld
设置开机自动启动并查看是否设置成功:
[root@cs mysql]# systemctl enable mysqld
[root@cs mysql]# systemctl is-enabled mysqld
enabled
因为mysql5.7的会有一个随机密码在日志中生成,我们查找一下,密码这语句的最后:
[root@cs mysql]# grep 'temporary password' /var/log/mysqld.log
2017-11-17T08:05:05.411354Z 1 [Note] A temporary password is generated for root@localhost: Ret6HK7sab<a
然后我们就可以用密码登陆数据库,并修改密码或增加远程访问权限了:
set password for 'root'@'localhost'=password('666666');
GRANT ALL PRIVILEGES ON *.* TO 'name'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;FLUSH PRIVILEGES;
小写部分为修改密码;大写部分为设置远程登陆权限。大功告成!