CentOS 7.2使用yum安装MYSQL 5.7.10的教程

1 查看Linux发行版本

[root@typecodes ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

2 下载MySQL官方的Yum Repository

根据Linux发行版本(CentOS、Fedora都属于红帽系),从mysql官方(http://dev.mysql.com/downloads/repo/yum/)获取Yum Repository。

[root@typecodes ~]#  wget -i http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
--2016-02-03 18:36:02--  http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm [following]
--2016-02-03 18:36:04--  http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 104.102.164.25
Connecting to repo.mysql.com (repo.mysql.com)|104.102.164.25|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8984 (8.8K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-7.noarch.rpm’

100%[=============================================================================================================================>] 8,984       --.-K/s   in 0s

2016-02-03 18:36:07 (68.4 MB/s) - ‘mysql57-community-release-el7-7.noarch.rpm’ saved [8984/8984]

3 安装MySQL的Yum Repository

安装完MySQL的Yum Repository,每次执行yum update都会检查MySQL是否更新。

[root@typecodes ~]# yum -y linstall mysql57-community-release-el7-7.noarch.rpm
Loaded plugins: axelget, fastestmirror, langpacks
Examining mysql57-community-release-el7-7.noarch.rpm: mysql57-community-release-el7-7.noarch
Marking mysql57-community-release-el7-7.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                                       Arch                       Version                    Repository                                                   Size
=======================================================================================================================================================================
Installing:
 mysql57-community-release                     noarch                     el7-7                      /mysql57-community-release-el7-7.noarch                     7.8 k

Transaction Summary
=======================================================================================================================================================================
Install  1 Package

Total size: 7.8 k
Installed size: 7.8 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql57-community-release-el7-7.noarch                                                                                                              1/1
  Verifying  : mysql57-community-release-el7-7.noarch                                                                                                              1/1

Installed:
  mysql57-community-release.noarch 0:el7-7

Complete!

3 安装MySQL数据库的服务器版本

[root@typecodes ~]# yum -y install mysql-community-server
Loaded plugins: axelget, fastestmirror, langpacks
No metadata available for base
No metadata available for epel
No metadata available for extras
repomd.xml                                                                                                                                      | 2.5 kB  00:00:00    
update mysql-connectors-community metadata successfully
repomd.xml                                                                                                                                      | 2.5 kB  00:00:00    
update mysql-tools-community metadata successfully
repomd.xml                                                                                                                                      | 2.5 kB  00:00:00    
update mysql57-community metadata successfully
No metadata available for updates
mysql-connectors-community                                                                                                                      | 2.5 kB  00:00:00    
mysql-tools-community                                                                                                                           | 2.5 kB  00:00:00    
mysql57-community                                                                                                                               | 2.5 kB  00:00:00    
(1/3): mysql-tools-community/x86_64/primary_db                                                                                                  |  24 kB  00:00:01    
(2/3): mysql57-community/x86_64/primary_db                                                                                                      |  28 kB  00:00:01    
(3/3): mysql-connectors-community/x86_64/primary_db                                                                                             | 8.6 kB  00:00:02    
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.neusoft.edu.cn
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.10-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.10-1.el7 for package: mysql-community-server-5.7.10-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) = 5.7.10-1.el7 for package: mysql-community-server-5.7.10-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.10-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) = 5.7.10-1.el7 for package: mysql-community-client-5.7.10-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.10-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos 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.10-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.10-1.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                                            Arch                          Version                               Repository                                Size
=======================================================================================================================================================================
Installing:
 mysql-community-libs                               x86_64                        5.7.10-1.el7                          mysql57-community                        2.2 M
     replacing  mariadb-libs.x86_64 1:5.5.44-2.el7.centos
 mysql-community-libs-compat                        x86_64                        5.7.10-1.el7                          mysql57-community                        2.0 M
     replacing  mariadb-libs.x86_64 1:5.5.44-2.el7.centos
 mysql-community-server                             x86_64                        5.7.10-1.el7                          mysql57-community                        142 M
Installing for dependencies:
 mysql-community-client                             x86_64                        5.7.10-1.el7                          mysql57-community                         24 M
 mysql-community-common                             x86_64                        5.7.10-1.el7                          mysql57-community                        269 k

Transaction Summary
=======================================================================================================================================================================
Install  3 Packages (+2 Dependent packages)

Total download size: 171 M
Downloading packages:
mysql-community-server-5.7.10-1.el7.x86_64.rpm                                                                                                  | 142 MB  00:03:42    
mysql-community-libs-compat-5.7.10-1.el7.x86_64.rpm                                                                                             | 2.0 MB  00:00:03    
mysql-community-libs-5.7.10-1.el7.x86_64.rpm                                                                                                    | 2.2 MB  00:00:05    
mysql-community-client-5.7.10-1.el7.x86_64.rpm                                                                                                  |  24 MB  00:00:41    
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.10-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY00 ETA
Public key for mysql-community-common-5.7.10-1.el7.x86_64.rpm is not installed
mysql-community-common-5.7.10-1.el7.x86_64.rpm                                                                                                  | 269 kB  00:00:01    
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    : mysql57-community-release-el7-7.noarch (@/mysql57-community-release-el7-7.noarch)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-5.7.10-1.el7.x86_64                                                                                                          1/6
  Installing : mysql-community-libs-5.7.10-1.el7.x86_64                                                                                                            2/6
  Installing : mysql-community-client-5.7.10-1.el7.x86_64                                                                                                          3/6
  Installing : mysql-community-server-5.7.10-1.el7.x86_64                                                                                                          4/6
  Installing : mysql-community-libs-compat-5.7.10-1.el7.x86_64                                                                                                     5/6
  Erasing    : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                                                                                                           6/6
  Verifying  : mysql-community-server-5.7.10-1.el7.x86_64                                                                                                          1/6
  Verifying  : mysql-community-libs-compat-5.7.10-1.el7.x86_64                                                                                                     2/6
  Verifying  : mysql-community-common-5.7.10-1.el7.x86_64                                                                                                          3/6
  Verifying  : mysql-community-libs-5.7.10-1.el7.x86_64                                                                                                            4/6
  Verifying  : mysql-community-client-5.7.10-1.el7.x86_64                                                                                                          5/6
  Verifying  : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                                                                                                           6/6

Installed:
  mysql-community-libs.x86_64 0:5.7.10-1.el7          mysql-community-libs-compat.x86_64 0:5.7.10-1.el7          mysql-community-server.x86_64 0:5.7.10-1.el7

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.10-1.el7                                       mysql-community-common.x86_64 0:5.7.10-1.el7

Replaced:
  mariadb-libs.x86_64 1:5.5.44-2.el7.centos

Complete!
[root@typecodes ~]# clear

最后的截图:

yum安装mysql5.7.10

4 启动数据库:

[root@typecodes ~]# systemctl start  mysqld.service

然后使用命令systemctl status mysql.service查看MySQL数据库启动后的服务状态:

systemctl命令查看MySQL服务状态

5 获取初始密码

使用YUM安装并启动MySQL服务后,MySQL进程会自动在进程日志中打印root用户的初始密码:

#######从mysql进程日志中获取root用户的初始密码:ra%yk7urCBIh

[root@typecodes ~]# grep "password" /var/log/mysqld.log
2016-02-03T10:42:17.272166Z 1 [Note] A temporary password is generated for root@localhost: ra%yk7urCBIh
2016-02-03T10:42:36.776875Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2016-02-03T10:42:52.063138Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2016-02-03T10:42:57.564373Z 4 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2016-02-03T10:43:01.477007Z 5 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2016-02-03T10:46:03.642008Z 6 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2016-02-03T10:46:11.217889Z 7 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2016-02-03T10:47:44.755199Z 0 [Note] Shutting down plugin 'validate_password'
2016-02-03T10:47:46.505844Z 0 [Note] Shutting down plugin 'sha256_password'
2016-02-03T10:47:46.505851Z 0 [Note] Shutting down plugin 'mysql_native_password'

6 修改root用户密码

使用小节5中获取的root用户的初始密码,然后进行修改:

[root@typecodes ~]# mysql -uroot -p
Enter password:             #######输入默认的root密码后回车
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.10

Copyright (c) 2000, 2015, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

7 安装完毕

至此,使用在CentOS7中使用YUM方法安装MySQL5.7.10数据库完毕。如下所示,可以使用新的root密码登陆MySQL了。

[root@typecodes ~]# mysql -uroot -ppassword
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.10 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> clear
mysql> exit
Bye
[root@typecodes ~]# clear

附录1:查看MySQL数据库的配置信息

MySQL的配置文件依然是/etc/my.cnf,其它安装信息可以通过mysql_config命令查看。其中,动态库文件存放在/usr/lib64/mysql目录下。

mysql_config命令查看mysql数据库的安装信息

附录2:删除MySQL的Repository

因为小节3中安装了MySQL的Yum Repository,所以以后每次执行yum操作时,都会去检查更新。如果想要去掉这种自动检查操作的话,可以使用如下命令卸载MySQL的Repository即可。

[root@typecodes ~]# yum -y remove mysql57-community-release-el7-7.noarch

时间: 2024-10-08 20:12:42

CentOS 7.2使用yum安装MYSQL 5.7.10的教程的相关文章

CentOS 7中源码安装MySQL 5.7.6+详细教程_Mysql

配置说明      Linux版本:Centos7      MySQL版本:MySQL5.7.16      该文档适用于MySQL版本>=5.7.6 一.卸载CentOS7默认携带的mariadb包 # 检查mariadb安装包 [root@wing ~]# rpm -qa | grep -i mysql [root@wing ~]# rpm -qa | grep -i mariadb mariadb-libs-5.5.50-1.el7_2.x86_64 # 卸载mariadb安装包 [ro

CentOS 7通过yum安装MySQL数据库例子

在CentOS 7中使用yum list mysql*,没有可以安装的MySQL版本,CentOS 7中默认使用的数据库是MariaDB,关于MariaDB,它是MySQL的一个分支,MySQL被Oracle收购有闭源的风险,因此有了一个MariaDB分支,兼容MySQL,下面是CentOS 7下通过yum安装MySQL的方式. 我们先要下载 Yum Repo package of MySQL Server 5.6 yum install wget wget http://repo.mysql.

在CentOS上使用yum安装MySQL+安全优化

0.说明         使用yum安装的好处是,你不用自己去解决软件之间的依赖问题,基本上yum执行完成,也就把软件安装好了,下面介绍使用yum的方法来安装MySQL,同时也会介绍安装完成后的安全优化.         注意:下面的操作都是以新安装的CentOS  6.5来作为演示的. 1.使用yum安装MySQL          查看是否已经安装MySQL: 1 [root@leaf]# yum list installed | grep mysql         如果你在安装CentO

CentOS 7.0下使用yum安装mysql的方法详解_Mysql

CentOS7默认数据库是mariadb,配置等用着不习惯,因此决定改成mysql,但是CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1.下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2.安装mysql-community-release-el7-5.noarch.rpm包 $ sudo rpm -ivh mys

CentOS 下yum安装mysql、jdk和tomcat的方法_Linux

0. 创建个人文件夹 # 使用 yum 安装tomcat 和 mysql # 创建文件夹 cd /usr/local mkdir hehe 1. 安装rzsz # 1. 安装rzsz yum list lrzsz* yum install lrzsz -y 2. 安装JDK,path之类的已经自动设置好了 # 2. 安装JDK yum list java* yum install java-1.7.0-openjdk* -y 3. 安装mysql # 3. 安装mysql yum list my

在CentOS 7下使用yum配置MySQL源并安装MySQL_Linux

CentOS7默认数据库是mariadb,配置等用着不习惯,因此决定改成mysql,但是CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1.由于CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件. wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm 2.安装yum repo文件 rpm -ivh my

CentOS 6.2下如何使用YUM安装MySQL

用yum安装MySql 打入如下命令: [root@mysql ~]# yum -y install mysql-server      //自动从网上搜索资源并自动下载安装 [root@mysql ~]# chkconfig mysqld on    //设置开机启动MySql服务 检查是否为开机启动 打入命令:[root@mysql ~]# chkconfig –list 看到:mysqld          0:off   1:off   2:on    3:on    4:on    5

Centos7下使用yum安装mysql数据库的详细教程(增强版)_Mysql

在之前给大家分享过这篇文章:CentOS 7.0下使用yum安装mysql的方法详解,小编觉得不够详细,今天给大家通过本文给大家做个补充,感兴趣的朋友可以参考下. 1. 下载mysql的repo源 $ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2. 安装mysql-community-release-el7-5.noarch.rpm包 $ sudo rpm -ivh mysql-community-re

CentOS 6.5下yum安装 MySQL-5.5全过程图文教程_Mysql

在linux安装mysql是一个困难的事情,yum安装一般是安装的mysql5.1,现在经过自己不懈努力终于能用yum安装mysql5.5了.下面通过两种方法给大家介绍CentOS 6.5下yum安装 MySQL-5.5全过程,一起学习吧. 方法一: 具体方法和步骤如下所示: 1.第一步就是看linu是否安装了mysql,经过rpm -qa|grep mysql查看到centos下安装了mysql5.1,那就开始卸载咯 2.接下来就是卸载mysql5.1了,命令:rpm -e mysql-lib