• yum安装mysql(指定版)


    首先需要删除已经存在的mysql,不然后面会报错:

    快速删除:

    yum remove  mysql mysql-server mysql-libs mysql-server

    查找残余文件:

    rpm -qa | grep -i mysql

    将查找出来的文件逐条删除。

    查找残余目录:

    whereis mysql

    删除参与目录。

    下载YUM源:

    #Red Hat7/CentOS7
    http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
    
    #Red Hat6/CentOS6
    http://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm
    
    #Red Hat5/CentOS5
    http://dev.mysql.com/get/mysql57-community-release-el5-7.noarch.rpm

    其他系统可以查看官网:https://dev.mysql.com/downloads/repo/yum/

    或者直接访问下载网址:https://repo.mysql.com/

    安装YUM源:

    [root@sql-test-HK ~]# rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
    Retrieving http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql57-community-release-el7-9  ################################# [100%]

    查看是否已经安装成功:

    [root@sql-test-HK ~]# yum repolist enabled | grep "mysql.*-community.*"
    mysql-connectors-community/x86_64 MySQL Connectors Community                 118
    mysql-tools-community/x86_64      MySQL Tools Community                       95
    mysql57-community/x86_64          MySQL 5.7 Community Server                 364

    有最后一行就可以了。

    使用这种方式进行安装MySQL会默认安装最新版本,此处就是5.7版本。如过你要安装5.6怎么办?

    首先查看被禁用的YUM源:

    [root@sql-test-HK ~]# yum repolist all | grep mysql
    mysql-connectors-community/x86_64 MySQL Connectors Community     enabled:    118
    mysql-connectors-community-source MySQL Connectors Community - S disabled
    mysql-tools-community/x86_64      MySQL Tools Community          enabled:     95
    mysql-tools-community-source      MySQL Tools Community - Source disabled
    mysql-tools-preview/x86_64        MySQL Tools Preview            disabled
    mysql-tools-preview-source        MySQL Tools Preview - Source   disabled
    mysql55-community/x86_64          MySQL 5.5 Community Server     disabled
    mysql55-community-source          MySQL 5.5 Community Server - S disabled
    mysql56-community/x86_64          MySQL 5.6 Community Server     disabled
    mysql56-community-source          MySQL 5.6 Community Server - S disabled
    mysql57-community/x86_64          MySQL 5.7 Community Server     enabled:    364
    mysql57-community-source          MySQL 5.7 Community Server - S disabled
    mysql80-community/x86_64          MySQL 8.0 Community Server     disabled
    mysql80-community-source          MySQL 8.0 Community Server - S disabled

    我们看到5.6版本是不可用的。

    执行如下命令来启动YUM源:

    yum install -y yum-utils
    yum-config-manager --disable mysql57-community
    yum-config-manager --enable mysql56-community

    之后就可以看到5.6的源可用了。

    [root@sql-test-HK ~]# yum repolist enabled | grep mysql
    mysql-connectors-community/x86_64 MySQL Connectors Community                 118
    mysql-tools-community/x86_64      MySQL Tools Community                       95
    mysql56-community/x86_64          MySQL 5.6 Community Server                 479

    安装MySQL:

    yum install mysql-community-server

    启动MySQL:

    [root@sql-test-HK ~]# service mysqld start
    Redirecting to /bin/systemctl start mysqld.service
    [root@sql-test-HK ~]# 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 Wed 2019-07-31 18:09:12 CST; 41s ago
         Docs: man:mysqld(8)
               http://dev.mysql.com/doc/refman/en/using-systemd.html
      Process: 12960 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
      Process: 12886 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
     Main PID: 12964 (mysqld)
       CGroup: /system.slice/mysqld.service
               └─12964 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    
    Jul 31 18:09:08 sql-test-HK systemd[1]: Starting MySQL Server...
    Jul 31 18:09:12 sql-test-HK systemd[1]: Started MySQL Server.

    可以同过如下明明查看MySQL的初始密码:

    [root@sql-test-HK ~]# grep 'temporary password' /var/log/mysqld.log
    2019-07-31T10:09:09.630812Z 1 [Note] A temporary password is generated for root@localhost: Ogue1n7P1?&L

    设置密码(在5.6里面貌似没有初始密码,可以直接设置):

    mysql_secure_installation

    当然我们可以通过初始密码直接在数据库中使用grant来进行设置。

    之后就可以进行登陆了:

    mysql -uroot -p

    需要说明的是,在安装的时候如果出现如下错误:

    Error: Package: mysql-community-server-5.7.27-1.el7.x86_64 (mysql57-community)
               Requires: mysql-community-common(x86-64) = 5.7.27-1.el7
               Installed: mysql-community-common-8.0.17-1.el7.x86_64 (@mysql80-community)
                   mysql-community-common(x86-64) = 8.0.17-1.el7
               Available: mysql-community-common-5.7.9-1.el7.x86_64 (mysql57-community)
                   mysql-community-common(x86-64) = 5.7.9-1.el7
                    ......
               Available: mysql-community-common-5.7.27-1.el7.x86_64 (mysql57-community)
                   mysql-community-common(x86-64) = 5.7.27-1.el7
     You could try using --skip-broken to work around the problem
     You could try running: rpm -Va --nofiles --nodigest

    那证明你没有严格执行第一步,重新指定前面的操作再次安装就可以了。

  • 相关阅读:
    c++11 内存模型解读
    无锁队列的实现
    c++中的原子操作
    还是说Memory Model,gcc的__sync_synchronize真是太坑爹了
    对于Linux平台下C语言开发中__sync_函数的认识
    理解 Memory barrier
    pthread_barrier_init,pthread_barrier_wait简介
    explicit构造函数的作用
    droofs
    27.
  • 原文地址:https://www.cnblogs.com/yangmingxianshen/p/11278319.html
Copyright © 2020-2023  润新知