在centos 7下安装mysql 5.7.17

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在centos 7下安装mysql 5.7.17相关的知识,希望对你有一定的参考价值。

首先查看系统有没有安装mysql

[[email protected]_167_102_centos ~]# rpm -qa|grep mysql
[[email protected]_167_102_centos ~]# 

结果发现没有,那么我们先下载mysql得rpm包

首先下载server

[[email protected]_167_102_centos mysql]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.17-1.el7.x86_64.rpm
--2017-04-02 17:51:11--  https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-server-5.7.17-1.el7.x86_64.rpm
Resolving cdn.mysql.com (cdn.mysql.com)... 23.219.134.205
Connecting to cdn.mysql.com (cdn.mysql.com)|23.219.134.205|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 169496800 (162M) [application/x-redhat-package-manager]
Saving to: mysql-community-server-5.7.17-1.el7.x86_64.rpm

 0% [                                                                                                                              ] 593,988     65.3KB/s  eta 42m 14s

然后下载client

 wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.17-1.el7.x86_64.rpm
--2017-04-02 17:55:12--  https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-community-client-5.7.17-1.el7.x86_64.rpm
Resolving cdn.mysql.com (cdn.mysql.com)... 23.211.97.88
Connecting to cdn.mysql.com (cdn.mysql.com)|23.211.97.88|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 25037548 (24M) [application/x-redhat-package-manager]
Saving to: mysql-community-client-5.7.17-1.el7.x86_64.rpm

 7% [=======>                                                                                                                      ] 1,762,140   60.9KB/s  eta 3m 50s 

然后先安装server

[[email protected]_167_102_centos mysql]# rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm  --nodeps --force
warning: mysql-community-server-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.17-1.e################################# [100%]

然后安装client

[[email protected]_167_102_centos mysql]# rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm --nodeps 
warning: mysql-community-client-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.17-1.e################################# [100%]

然后启动mysql服务

[[email protected]_167_102_centos mysql]# service mysqld start
Redirecting to /bin/systemctl start  mysqld.service
[[email protected]_167_102_centos mysql]# 

获取临时密码

[[email protected]_167_102_centos mysql]# grep temporary password /var/log/mysqld.log
2017-04-02T14:55:58.589047Z 1 [Note] A temporary password is generated for [email protected]: k1pki)rKa6HL

然后使用临时密码进入mysql修改密码

[[email protected]_167_102_centos mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17

Copyright (c) 2000, 2016, 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.

Type help; or \h for help. Type \c to clear the current input statement.

mysql> 

然后进入etc/my.cnf在[mysqld]下添加一行如下代码

skip-grant-tables

然后在使用刚才得临时密码进入mysql修改root密码

mysql> update mysql.user set authentication_string=password(root) where user=root and Host = localhost;
Query OK, 1 row affected, 1 warning (0.00 sec)

然后再把my.cnf文件下刚刚添加得那行代码删除

然后重启mysql

[[email protected]_167_102_centos /]# service mysqld restart
Redirecting to /bin/systemctl restart  mysqld.service
[[email protected]_167_102_centos /]#

然后就可以使用刚才设置得密码进入mysql了

[[email protected]_167_102_centos /]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17

Copyright (c) 2000, 2016, 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.

Type help; or \h for help. Type \c to clear the current input statement.

mysql> 

设置开机自动重启

[[email protected]_167_102_centos /]# systemctl enable mysqld
[[email protected]_167_102_centos /]# systemctl daemon-reload

为了确保远程能访问还得增加3306端口开放

这样centos7_64位安装mysql5.7.17就搞定啦。

不对得地方请各位大佬指正

以上是关于在centos 7下安装mysql 5.7.17的主要内容,如果未能解决你的问题,请参考以下文章

centos7 mysql5.7.17源码安装

Centos7环境下安装Mysql5.7版本

linux centos7 安装mysql-5.7.17教程(图解)

CentOS 7.2 mysql-5.7.17 审计插件安装开启与设定

centos mysql5.7 二进制包安装

怎么在linux虚拟机上安装mysql