zoukankan      html  css  js  c++  java
  • CentOS7 安装配置 MySQL 5.7

    1. 下载 yum 源文件 mysql80-community-release-el7-2.noarch.rpm

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

    2. 安装源

    sudo rpm -Uvh mysql80-community-release-el7-2.noarch.rpm 

    3. 查看安装结果

    yum repolist all | grep mysql

     

    4. 将默认版本改为 5.7

    sudo yum-config-manager --disable mysql80-community
    sudo yum-config-manager --enable mysql57-community


    5. 查看修改结果

    yum repolist all | grep mysql

     

    6. 安装

    sudo yum install mysql-community-server.x86_64 

     

    7. 启动并查看状态

    sudo systemctl start mysqld.service
    sudo systemctl status mysqld.service 

    8. 获得初始密码

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


    9. 使用初始密码登陆 mysql

    mysql -u root -p

     

    10. 修改密码(总长度大于8,必须:一个小写字母,一个大写字母,一个数字,一个特殊符号)例如,

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

    11. 修改编码方式到 utf8

    默认情况下,mysql5.7 的编码方式如下,

    mysql> show variables like 'character_set_%';
    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | utf8                       |
    | character_set_connection | utf8                       |
    | character_set_database   | latin1                     |
    | character_set_filesystem | binary                     |
    | character_set_results    | utf8                       |
    | character_set_server     | latin1                     |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.00 sec)

    在 CentOS7 下,mysql 的配置文件是 /etc/my.cnf,打开在最后加上一句,

    character-set-server=utf8

    然后重启 mysql 服务,

    $ sudo systemctl restart mysqld

    再次查看,

    mysql> show variables like 'character_set_%';
    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | utf8                       |
    | character_set_connection | utf8                       |
    | character_set_database   | utf8                       |
    | character_set_filesystem | binary                     |
    | character_set_results    | utf8                       |
    | character_set_server     | utf8                       |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.01 sec)

    其它高级设置参考:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

    12. 使用 mycli 自动补全

     默认 mysql 命令行登陆后,输入命令不会提示及自动补全,非常麻烦,通过使用 mycli 自动补全会方便很多。

    安装如下,

    $ sudo pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ mycli

    使用 mycli 启动数据库连接,

    $ mycli -h 127.0.0.1 -u root -p ******** ( here your MySQL password)

    Ubuntu 18.04 下的安装方法如下: https://www.cnblogs.com/gaowengang/p/10816537.html

    (完)

  • 相关阅读:
    oracle 导入数据时提示只有 DBA 才能导入由其他 DBA 导出的文件
    oracle 常用语句
    android udp 无法收到数据 (模拟器中)
    android DatagramSocket send 发送数据出错
    AtCoder ABC 128E Roadwork
    AtCoder ABC 128D equeue
    AtCoder ABC 127F Absolute Minima
    AtCoder ABC 127E Cell Distance
    CodeForces 1166E The LCMs Must be Large
    CodeForces 1166D Cute Sequences
  • 原文地址:https://www.cnblogs.com/gaowengang/p/10744746.html
Copyright © 2011-2022 走看看