安装mysql5.7

作者: 您好简书 | 来源:发表于2019-03-15 10:03 被阅读11次

    Step1: 检测系统是否自带安装mysql

    yum list installed | grep mysql

    Step2: 删除系统自带的mysql及其依赖

    yum -y remove mysql-libs.x86_64

    Step3: 给CentOS添加rpm源,并且选择较新的源
    CeontOS6只能用el6的。

    3.1配置YUM源

    在MySQL官网中下载YUM源rpm安装包:

    3.2下载mysql源安装包

    http://dev.mysql.com/downloads/repo/yum/

    wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm

    3.3安装mysql源

    yum localinstall mysql-community-release-el6-5.noarch.rpm

    3.4查看启用情况

    yum repolist all | grep mysql

    3.5设置启用mysql57

    检查mysql源是否安装成功

    yum repolist enabled | grep "mysql.-community."

    image

    看到上图所示表示安装成功。

    3.6修改启用mysql57

    可以修改vim /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。改完之后的效果如下:

    image

    3.7查看mysql启用情况

    yum repolist enabled | grep mysql

    image

    Step4:安装mysql 服务器命令:

    yum install mysql-community-server

    顺利的话。。。
    不顺利的话会缺少依赖:
    解决办法:

    修改vim /etc/yum.repos.d/mysql-community.repo 源文件

    [mysql57-community]

    name=MySQL 5.7 Community Server

    baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/

    baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/

    enabled=1

    gpgcheck=0

    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    7.yum install mysql-community-server #再次安装mysql

    Step5:启动MySQL服务

    service mysqld start

    [ok]

    Step6:查看root 临时密码

    grep 'temporary password' /var/log/mysqld.log

    2018-01-07T01:25:58.867073Z 1 [Note] A temporary password is generated for root@localhost: umDn1uy4q>B;

    其中的;也是密码的一部份。

    Step7:修改root密码

    mysql -uroot -p

    mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass2!';

    如果您只是写一个简单的如,123456,则会报错。
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    这个其实与validate_password_policy的值有关。
    validate_password_policy有以下取值:

    默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
    有时候,只是为了自己测试,不想密码设置得那么复杂,譬如说,我只想设置root的密码为123456。
    必须修改两个全局参数:
    首先,修改validate_password_policy参数的值
    mysql> set global validate_password_policy=0;
    Query OK, 0 rows affected (0.00 sec)

    这样,判断密码的标准就基于密码的长度了。这个由validate_password_length参数来决定。(默认需要长度8)

    mysql> set global validate_password_length=4;

    Step8:开放远程登录权限

    GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'root';
    FLUSH PRIVILEGES;

    Step9:关闭防火墙

    (1) 用root用户登录后,执行查看防火墙状态。

    [root@bigdata-senior01 hadoop]# service iptables status
    
    

    (2) 用[root@bigdata-senior01 hadoop]# service iptables stop关闭防火墙,这个是临时关闭防火墙。

    [root@bigdata-senior01 hadoop-2.5.0]# service iptables stop
    iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
    iptables: Flushing firewall rules:                         [  OK  ]
    iptables: Unloading modules:                               [  OK  ]
    
    

    (3) 如果要永久关闭防火墙用。

    [root@bigdata-senior01 hadoop]# chkconfig iptables off
    
    

    关闭,这种需要重启才能生效。


    若mysql开启失败
    报 Fatal error: mysql.user table is damaged. Please run mysql_upgrade.
    或 InnoDB: Plugin initialization aborted with error Generic error。
    删除 /var/lib/mysql下的所有文件再重启。

    tips:在高并发情况下,
    Caused by:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections",这是由于请求的连接太多导致,在/etc/my.cnf文件里加
    max_connections=1000 为设置最大的连接数
    max_user_connections=500 设置每用户最大的 连接数500
    wait_timeout=200 表示200秒后将关闭空闲连接,但对正在工作的连接不受影响。

    5.7版本group by后的列必须出现在select里,可以再my.cnf里添加
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    (只要sql_mode里没有only_full_group_by这一项就可以)

    相关文章

      网友评论

        本文标题:安装mysql5.7

        本文链接:https://www.haomeiwen.com/subject/hlakmqtx.html