首页

在centos的linux操作系统上安装mysql详细整理shell脚本步骤(提供本地和官网下载链接)

标签:linux安装mysql,mysql57-community-release-el6-9.noarch.rpm,centos安装MYSQL     发布时间:2019-05-03   

一、前言

下面再centos6.7的linux操作系统安装mysql版本(更多版本&window版本参见其他文章页面),具体安装步骤整理如下

二、安装步骤

1. 查看本机是否安装mysql,如果有则删除以安装正确的版本

[root@centos-cluster-s19423 ~]# yum list installed | grep mysql@b@mysql-libs.x86_64       5.1.73-5.el6_6  @anaconda-CentOS-201508042137.x86_64/6.7@b@[root@centos-cluster-s19423 ~]# yum  -y  remove  mysql-libs.x86_64 @b@已加载插件:fastestmirror, refresh-packagekit, security@b@设置移除进程@b@解决依赖关系@b@--> 执行事务检查@b@---> Package mysql-libs.x86_64 0:5.1.73-5.el6_6 will be 删除@b@--> 处理依赖关系 libmysqlclient.so.16()(64bit),它被软件包 2:postfix-2.6.6-6.el6_5.x86_64 需要@b@--> 处理依赖关系 libmysqlclient.so.16(libmysqlclient_16)(64bit),它被软件包 2:postfix-2.6.6-6.el6_5.x86_64 需要@b@--> 处理依赖关系 mysql-libs,它被软件包 2:postfix-2.6.6-6.el6_5.x86_64 需要@b@--> 执行事务检查@b@---> Package postfix.x86_64 2:2.6.6-6.el6_5 will be 删除@b@--> 处理依赖关系 /usr/sbin/sendmail,它被软件包 redhat-lsb-core-4.0-7.el6.centos.x86_64 需要@b@--> 处理依赖关系 /usr/sbin/sendmail,它被软件包 cronie-1.4.4-15.el6.x86_64 需要@b@--> 执行事务检查@b@---> Package cronie.x86_64 0:1.4.4-15.el6 will be 删除@b@--> 处理依赖关系 cronie = 1.4.4-15.el6,它被软件包 cronie-anacron-1.4.4-15.el6.x86_64 需要@b@---> Package redhat-lsb-core.x86_64 0:4.0-7.el6.centos will be 删除@b@--> 处理依赖关系 redhat-lsb-core(x86-64) = 4.0,它被软件包 redhat-lsb-printing-4.0-7.el6.centos.x86_64 需要@b@--> 处理依赖关系 redhat-lsb-core(x86-64) = 4.0,它被软件包 redhat-lsb-graphics-4.0-7.el6.centos.x86_64 需要@b@--> 执行事务检查@b@---> Package cronie-anacron.x86_64 0:1.4.4-15.el6 will be 删除@b@---> Package redhat-lsb-graphics.x86_64 0:4.0-7.el6.centos will be 删除@b@---> Package redhat-lsb-printing.x86_64 0:4.0-7.el6.centos will be 删除@b@--> 处理依赖关系 /etc/cron.d,它被软件包 crontabs-1.10-33.el6.noarch 需要@b@--> 处理依赖关系 /etc/cron.d,它被软件包 sysstat-9.0.4-27.el6.x86_64 需要@b@--> 使用新的信息重新计算依赖关系@b@--> 执行事务检查@b@---> Package crontabs.noarch 0:1.10-33.el6 will be 删除@b@---> Package sysstat.x86_64 0:9.0.4-27.el6 will be 删除@b@--> 完成依赖关系计算@b@@b@依赖关系解决@b@@b@================================================================================@b@ 软件包  架构   版本             仓库                                      大小@b@================================================================================@b@正在删除:@b@ mysql-libs@b@         x86_64 5.1.73-5.el6_6   @anaconda-CentOS-201508042137.x86_64/6.7 4.0 M@b@为依赖而移除:@b@ cronie  x86_64 1.4.4-15.el6     @anaconda-CentOS-201508042137.x86_64/6.7 174 k@b@ cronie-anacron@b@         x86_64 1.4.4-15.el6     @anaconda-CentOS-201508042137.x86_64/6.7  43 k@b@ crontabs@b@         noarch 1.10-33.el6      @anaconda-CentOS-201508042137.x86_64/6.7 2.4 k@b@ postfix x86_64 2:2.6.6-6.el6_5  @anaconda-CentOS-201508042137.x86_64/6.7 9.7 M@b@ redhat-lsb-core@b@         x86_64 4.0-7.el6.centos @anaconda-CentOS-201508042137.x86_64/6.7  22 k@b@ redhat-lsb-graphics@b@         x86_64 4.0-7.el6.centos @anaconda-CentOS-201508042137.x86_64/6.7 0.0  @b@ redhat-lsb-printing@b@         x86_64 4.0-7.el6.centos @anaconda-CentOS-201508042137.x86_64/6.7 0.0  @b@ sysstat x86_64 9.0.4-27.el6     @anaconda-CentOS-201508042137.x86_64/6.7 825 k@b@@b@事务概要@b@================================================================================@b@Remove        9 Package(s)@b@@b@Installed size: 15 M@b@下载软件包:@b@运行 rpm_check_debug @b@执行事务测试@b@事务测试成功@b@执行事务@b@  正在删除   : redhat-lsb-graphics-4.0-7.el6.centos.x86_64                                                                                                                                   1/9 @b@  正在删除   : redhat-lsb-printing-4.0-7.el6.centos.x86_64                                                                                                                                   2/9 @b@  正在删除   : redhat-lsb-core-4.0-7.el6.centos.x86_64                                                                                                                                       3/9 @b@/var/tmp/rpm-tmp.EtHPoI: line 1: lsb_release: command not found@b@  正在删除   : sysstat-9.0.4-27.el6.x86_64                                                                                                                                                   4/9 @b@  正在删除   : crontabs-1.10-33.el6.noarch                                                                                                                                                   5/9 @b@  正在删除   : cronie-anacron-1.4.4-15.el6.x86_64                                                                                                                                            6/9 @b@  正在删除   : cronie-1.4.4-15.el6.x86_64                                                                                                                                                    7/9 @b@  正在删除   : 2:postfix-2.6.6-6.el6_5.x86_64                                                                                                                                                8/9 @b@  正在删除   : mysql-libs-5.1.73-5.el6_6.x86_64                                                                                                                                              9/9 @b@  Verifying  : redhat-lsb-printing-4.0-7.el6.centos.x86_64                                                                                                                                   1/9 @b@  Verifying  : mysql-libs-5.1.73-5.el6_6.x86_64                                                                                                                                              2/9 @b@  Verifying  : redhat-lsb-core-4.0-7.el6.centos.x86_64                                                                                                                                       3/9 @b@  Verifying  : sysstat-9.0.4-27.el6.x86_64                                                                                                                                                   4/9 @b@  Verifying  : crontabs-1.10-33.el6.noarch                                                                                                                                                   5/9 @b@  Verifying  : redhat-lsb-graphics-4.0-7.el6.centos.x86_64                                                                                                                                   6/9 @b@  Verifying  : 2:postfix-2.6.6-6.el6_5.x86_64                                                                                                                                                7/9 @b@  Verifying  : cronie-anacron-1.4.4-15.el6.x86_64                                                                                                                                            8/9 @b@  Verifying  : cronie-1.4.4-15.el6.x86_64                                                                                                                                                    9/9 @b@@b@删除:@b@  mysql-libs.x86_64 0:5.1.73-5.el6_6                                                                                                                                                             @b@@b@作为依赖被删除:@b@  cronie.x86_64 0:1.4.4-15.el6                    cronie-anacron.x86_64 0:1.4.4-15.el6                crontabs.noarch 0:1.10-33.el6                       postfix.x86_64 2:2.6.6-6.el6_5      @b@  redhat-lsb-core.x86_64 0:4.0-7.el6.centos       redhat-lsb-graphics.x86_64 0:4.0-7.el6.centos       redhat-lsb-printing.x86_64 0:4.0-7.el6.centos       sysstat.x86_64 0:9.0.4-27.el6       @b@@b@完毕!

2. 在线下载(或者本地下载

[root@centos-cluster-s19423 soft]# wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm@b@--2019-04-29 23:22:10--  https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm@b@正在解析主机 dev.mysql.com... 137.254.60.11@b@正在连接 dev.mysql.com|137.254.60.11|:443... 已连接。@b@已发出 HTTP 请求,正在等待回应... 302 Found@b@位置:https://repo.mysql.com//mysql57-community-release-el6-9.noarch.rpm [跟随至新的 URL]@b@--2019-04-29 23:22:20--  https://repo.mysql.com//mysql57-community-release-el6-9.noarch.rpm@b@正在解析主机 repo.mysql.com... 23.194.189.202@b@正在连接 repo.mysql.com|23.194.189.202|:443... 失败:连接超时。@b@重试中。@b@@b@--2019-04-29 23:23:24--  (尝试次数: 2)  https://repo.mysql.com//mysql57-community-release-el6-9.noarch.rpm@b@正在连接 repo.mysql.com|23.194.189.202|:443... 失败:连接超时。@b@重试中。@b@@b@--2019-04-29 23:24:29--  (尝试次数: 3)  https://repo.mysql.com//mysql57-community-release-el6-9.noarch.rpm@b@正在连接 repo.mysql.com|23.194.189.202|:443... 失败:连接超时。@b@重试中。@b@@b@--2019-04-29 23:25:35--  (尝试次数: 4)  https://repo.mysql.com//mysql57-community-release-el6-9.noarch.rpm@b@正在连接 repo.mysql.com|23.194.189.202|:443... 已连接。@b@已发出 HTTP 请求,正在等待回应... 200 OK@b@长度:9216 (9.0K) [application/x-redhat-package-manager]@b@正在保存至: “mysql57-community-release-el6-9.noarch.rpm”@b@@b@100%[=======================================================================================================================================================>] 9,216       --.-K/s   in 0.03s   @b@@b@2019-04-29 23:25:36 (354 KB/s) - 已保存 “mysql57-community-release-el6-9.noarch.rpm” [9216/9216])

3. 将下载rpm进行安装

[root@centos-cluster-s19423 soft]# rpm -Uvh mysql57-community-release-el6-9.noarch.rpm @b@warning: mysql57-community-release-el6-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY@b@Preparing...                ########################################### [100%]@b@   1:mysql57-community-relea########################################### [100%]@b@ @b@@b@[root@centos-cluster-s19423 soft]# yum install mysql-community-server@b@已加载插件:fastestmirror, refresh-packagekit, security@b@设置安装进程@b@Loading mirror speeds from cached hostfile@b@ * base: mirrors.163.com@b@ * extras: mirrors.163.com@b@ * updates: mirrors.163.com@b@base                                                                                                                                                                      | 3.7 kB     00:00     @b@extras                                                                                                                                                                    | 3.4 kB     00:00     @b@mysql-connectors-community                                                                                                                                                | 2.5 kB     00:00     @b@mysql-connectors-community/primary_db                                                                                                                                     |  36 kB     00:00     @b@mysql-tools-community                                                                                                                                                     | 2.5 kB     00:00     @b@mysql-tools-community/primary_db                                                                                                                                          |  49 kB     00:00     @b@mysql57-community                                                                                                                                                         | 2.5 kB     00:00     @b@mysql57-community/primary_db                                                                                                                                              | 182 kB     00:01     @b@updates                                                                                                                                                                   | 3.4 kB     00:00     @b@解决依赖关系@b@--> 执行事务检查@b@---> Package mysql-community-server.x86_64 0:5.7.26-1.el6 will be 安装@b@--> 处理依赖关系 mysql-community-common(x86-64) = 5.7.26-1.el6,它被软件包 mysql-community-server-5.7.26-1.el6.x86_64 需要@b@--> 处理依赖关系 mysql-community-client(x86-64) >= 5.7.9,它被软件包 mysql-community-server-5.7.26-1.el6.x86_64 需要@b@--> 执行事务检查@b@---> Package mysql-community-client.x86_64 0:5.7.26-1.el6 will be 安装@b@--> 处理依赖关系 mysql-community-libs(x86-64) >= 5.7.9,它被软件包 mysql-community-client-5.7.26-1.el6.x86_64 需要@b@---> Package mysql-community-common.x86_64 0:5.7.26-1.el6 will be 安装@b@--> 执行事务检查@b@---> Package mysql-community-libs.x86_64 0:5.7.26-1.el6 will be 安装@b@--> 完成依赖关系计算@b@@b@依赖关系解决@b@@b@=================================================================================================================================================================================================@b@ 软件包                                                架构                                  版本                                         仓库                                              大小@b@=================================================================================================================================================================================================@b@正在安装:@b@ mysql-community-server                                x86_64                                5.7.26-1.el6                                 mysql57-community                                153 M@b@为依赖而安装:@b@ mysql-community-client                                x86_64                                5.7.26-1.el6                                 mysql57-community                                 22 M@b@ mysql-community-common                                x86_64                                5.7.26-1.el6                                 mysql57-community                                332 k@b@ mysql-community-libs                                  x86_64                                5.7.26-1.el6                                 mysql57-community                                2.1 M@b@@b@事务概要@b@=================================================================================================================================================================================================@b@Install       4 Package(s)@b@@b@总下载量:178 M@b@Installed size: 888 M@b@确定吗?[y/N]:y@b@下载软件包:@b@(1/4): mysql-community-client-5.7.26-1.el6.x86_64.rpm                                                                                                                     |  22 MB     00:45     @b@(2/4): mysql-community-common-5.7.26-1.el6.x86_64.rpm                                                                                                                     | 332 kB     00:00     @b@(3/4): mysql-community-libs-5.7.26-1.el6.x86_64.rpm                                                                                                                       | 2.1 MB     00:03     @b@(4/4): mysql-community-server-5.7.26-1.el6.x86_64.rpm                                                                                                                     | 153 MB     04:46     @b@-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------@b@总计                                                                                                                                                             541 kB/s | 178 MB     05:37     @b@warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY@b@Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql@b@Importing GPG key 0x5072E1F5:@b@ Userid : MySQL Release Engineering <mysql-build@oss.oracle.com>@b@ Package: mysql57-community-release-el6-9.noarch (installed)@b@ From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql@b@确定吗?[y/N]:y@b@运行 rpm_check_debug @b@执行事务测试@b@事务测试成功@b@执行事务@b@Warning: RPMDB altered outside of yum.@b@  正在安装   : mysql-community-common-5.7.26-1.el6.x86_64                                                                                                                                    1/4 @b@  正在安装   : mysql-community-libs-5.7.26-1.el6.x86_64                                                                                                                                      2/4 @b@  正在安装   : mysql-community-client-5.7.26-1.el6.x86_64                                                                                                                                    3/4 @b@  正在安装   : mysql-community-server-5.7.26-1.el6.x86_64                                                                                                                                    4/4 @b@  Verifying  : mysql-community-server-5.7.26-1.el6.x86_64                                                                                                                                    1/4 @b@  Verifying  : mysql-community-client-5.7.26-1.el6.x86_64                                                                                                                                    2/4 @b@  Verifying  : mysql-community-common-5.7.26-1.el6.x86_64                                                                                                                                    3/4 @b@  Verifying  : mysql-community-libs-5.7.26-1.el6.x86_64                                                                                                                                      4/4 @b@@b@已安装:@b@  mysql-community-server.x86_64 0:5.7.26-1.el6                                                                                                                                                   @b@@b@作为依赖被安装:@b@  mysql-community-client.x86_64 0:5.7.26-1.el6                    mysql-community-common.x86_64 0:5.7.26-1.el6                    mysql-community-libs.x86_64 0:5.7.26-1.el6                   @b@@b@完毕!

4. 配置防火墙

[root@centos-cluster-s19423 soft]# vi /etc/sysconfig/iptables@b@# Firewall configuration written by system-config-firewall@b@# Manual customization of this file is not recommended.@b@*filter@b@:INPUT ACCEPT [0:0]@b@:FORWARD ACCEPT [0:0]@b@:OUTPUT ACCEPT [0:0]@b@-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT@b@-A INPUT -p icmp -j ACCEPT@b@-A INPUT -i lo -j ACCEPT @b@-A INPUT -m state --state NEW -m tcp -p tcp --dport  3306  -j ACCEPT@b@-A INPUT -j REJECT --reject-with icmp-host-prohibited@b@-A FORWARD -j REJECT --reject-with icmp-host-prohibited@b@COMMIT@b@@b@"/etc/sysconfig/iptables" 20L, 947C written@b@[root@centos-cluster-s19423 soft]# service  iptables  restart@b@iptables:将链设置为政策 ACCEPT:filter [确定]@b@iptables:清除防火墙规则:[确定]@b@iptables:正在卸载模块:[确定]@b@iptables:应用防火墙规则:[确定]

5. 设置超级管理员及修改密码    

[root@centos-cluster-s19423 soft]# grep 'temporary password' /var/log/mysqld.log@b@2019-04-29T15:44:37.654501Z 1 [Note] A temporary password is generated for root@localhost: ,D!u4TAeufiR@b@ @b@[root@centos-cluster-s19423 soft]# mysql -uroot -p @b@Enter password: @b@Welcome to the MySQL monitor.  Commands end with ; or \g.@b@Your MySQL connection id is 5@b@Server version: 5.7.26@b@@b@Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.@b@@b@Oracle is a registered trademark of Oracle Corporation and/or its@b@affiliates. Other names may be trademarks of their respective@b@owners.@b@@b@Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.@b@@b@mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456!';@b@Query OK, 0 rows affected (0.00 sec)@b@@b@mysql> exit;@b@Bye

6 重启mysql服务并测试

[root@centos-cluster-s19423 ~]#  service mysqld stop@b@停止 mysqld: [确定]@b@[root@centos-cluster-s19423 ~]#  service mysqld start@b@正在启动 mysqld: [确定]@b@@b@正在启动 mysqld: [确定]@b@[root@centos-cluster-s19423 ~]# mysql  -u root  -p@b@Enter password: @b@Welcome to the MySQL monitor.  Commands end with ; or \g.@b@Your MySQL connection id is 3@b@Server version: 5.7.26 MySQL Community Server (GPL)@b@@b@Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.@b@@b@Oracle is a registered trademark of Oracle Corporation and/or its@b@affiliates. Other names may be trademarks of their respective@b@owners.@b@@b@Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

如需修改配置端口vi  /etc/my.cnf

  • <<相关内容>>
<<热门下载>>