美文网首页
入门 - CentOS7使用Yum安装MySQL5.7

入门 - CentOS7使用Yum安装MySQL5.7

作者: 青花茶叶罐 | 来源:发表于2018-02-06 17:23 被阅读0次

    CentOS7使用Yum安装MySQL5.7

    简介

    安装

    Step 0 - 查看系统版本

    # CentOS 6
    $cat /etc/redhat-release
    CentOS release 6.7 (Final)
    
    # CentOS 7
    $cat /etc/redhat-release
    CentOS Linux release 7.2.1511 (Core)
    

    Step 1 - 下载MySQL官方的Yum Repository

    # CentOS 6
    $wget http://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
    
    # CentOS 7
    $wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
    

    Step 2 - 安装MySQL的Yum Repository

    # CentOS 6
    $yum -y install mysql57-community-release-el6-11.noarch.rpm
    
    # CentOS 7
    $yum -y install mysql57-community-release-el7-11.noarch.rpm
    

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

    $yum -y install mysql-community-server
    

    Step 4 - 启动数据库

    # CentOS 7
    # 启动MySQL数据库
    $systemctl start  mysqld.service
    # 查看Mysql数据库状态
    $systemctl status mysqld.service
    # 重启MySQL数据库
    $systemctl restart mysqld.service
    

    Step 5 - 获取初始密码并修改

    # CentOS 7
    $grep "password" /var/log/mysqld.log
    2016-02-03T10:42:17.272166Z 1 [Note] A temporary password is generated for root@localhost: ra%yk7urCBIh
    
    $ mysql -uroot -p
    Enter password:             #输入密码
    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
    

    Step 6 - 安装完毕

    $mysql -uroot -ppassword
    

    Tips

    1. 查看Mysql实时连接 show processlist;
    2. MySQL服务重启方法 systemctl restart mysqld.service
    3. MySQL配置文件默认路径 /etc/my.cnf
    4. 更改配置文件设置默认UTF-8编码方式:
    [client]
    default-character-set=utf8
    
    [mysqld]
    character_set_server=utf8
    init_connect='SET NAMES utf8'
    

    相关文章

      网友评论

          本文标题:入门 - CentOS7使用Yum安装MySQL5.7

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