• CentOS7下安装MySQL5.7安装与配置(YUM)


    原文链接:http://www.centoscn.com/mysql/2016/0626/7537.html

    安装环境:CentOS7 64位 MINI版,安装MySQL5.7

    1、配置YUM源

    MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/ 

    # 下载mysql源安装包
    shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
    # 安装mysql源
    shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm

    检查mysql源是否安装成功

    shell> yum repolist enabled | grep "mysql.*-community.*"

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

    2、安装MySQL

    shell> yum install mysql-community-server

    3、启动MySQL服务

    shell> systemctl start mysqld

    查看MySQL的启动状态

    shell> systemctl status mysqld
    ● mysqld.service - MySQL Server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
       Active: active (running) since 五 2016-06-24 04:37:37 CST; 35min ago
     Main PID: 2888 (mysqld)
       CGroup: /system.slice/mysqld.service
               └─2888 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
    
    6月 24 04:37:36 localhost.localdomain systemd[1]: Starting MySQL Server...
    6月 24 04:37:37 localhost.localdomain systemd[1]: Started MySQL Server.

    4、开机启动

    shell> systemctl enable mysqld
    shell> systemctl daemon-reload

    5、修改root默认密码

    mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

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

    shell> mysql -uroot -py.0w(csyT,Sx
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 

    或者

    mysql> set password for 'root'@'localhost'=password('MyNewPass4!'); 

    注意:mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误,如下图所示: 

    6、添加远程登录用户

    默认只允许root帐户在本地登录,如果要在其它机器上连接mysql,必须修改root允许远程连接,或者添加一个允许远程连接的帐户,为了安全起见,我添加一个新的帐户:

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;

    7、配置默认编码为utf8

    修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

    [mysqld]
    character_set_server=utf8
    init_connect='SET NAMES utf8'
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

    保存退出 :wq!

    重新启动mysql服务,

    systemctl restart mysqld

    重新进入mysql查看数据库默认编码

    mysql> show variables like '%character%';

    如下所示:

     

    如果防火墙开启,需要添加防火墙规则

    firewall-cmd --zone=public --add-port=3306/tcp --permanent

    重启 Firewalld 使该规则生效,

    systemctl restart firewalld
  • 相关阅读:
    【解压缩命令】 -费元星
    【虚拟机取得该虚拟机的所有权失败】--费元星
    solr 常见的问题整理 -费元星
    oracle 建立一个视图,然后授权其他用户访问
    虚拟机安装win7 64位-完美解决-费元星
    solr 学习
    CentOS安装JDK1.7
    Nginx+Tomcat多站点访问默认主页问题-狒狒完美解决-Q9715234
    pip 安装时提示uvloop/loop.c:20:10: fatal error: Python.h解决
    MySQL锁总结
  • 原文地址:https://www.cnblogs.com/007sx/p/6243333.html
Copyright © 2020-2023  润新知