美文网首页
Linux CentOS 7.4 安装 MySQL 5.7

Linux CentOS 7.4 安装 MySQL 5.7

作者: Think_Heart | 来源:发表于2018-09-06 16:57 被阅读0次

    该篇文章主要基于阿里云的服务器,对 Linux CentOS 7.4 下安装 MySQL 5.7 进行简单介绍,并对安装过程中出现的问题给出了已测的解决方案。

    MySQL 5.7 安装

    在 /opt 目录下新建一个目录用来保存 MySQL

    cd /opt
    mkdir mysql

    下载 MySQL 5.7(下载地址

    wget http://repo.mysql.com/mysql57-community-release-el7.rpm

    安装 MySQL 的 rpm,执行后在 /etc/yum.repos.d/ 目录下多出mysql-community-source.repo 和 mysql-community.repo两个文件,如图

    rpm -ivh mysql57-community-release-el7-8.noarch.rpm

    安装MySQL(一直按 Yes)

    sudo yum install mysql-server

    启动/关闭/重启 MySQL 服务

    service mysqld start/stop/restart

    为了加强安全性,MySQL 5.7 为 root 用户随机生成了一个密码,如果用的是 rpm 包安装,则默认在 /var/log/mysqld.log 中保存。通过下面命令获得初始密码,如图在 root@localhost: 后的即为初始密码。

    cat /var/log/mysqld.log | grep password

    登录 MySQL

    mysql -uroot -p'password'

    修改用户密码(MySQL 5.7 对用户密码有要求,设置的密码必须达到规定长度,且必须含有数字,小写或大写字母,特殊字符)

    mysql> alter user 'root'@'localhost' identified by 'password';

    查看 MySQL 5.7 的密钥要求,validate_password_number_count 指定了密码的长度,validate_password_special_char_count 指定了密码中特殊字符的长度,validate_password_mixed_case_count 指定了密码中大小字母的长度。


    问题

    MySQL 5.7 登录报 ERROR 1045 (28000) 错误

    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    解决办法:采用 skip-grant-tables 命令,跳过权限表的限制,不用验证密码,直接登录 MySQL,然后重新设置密码。步骤如下:

    1. 修改配置文件 /etc/my.cnf,实现无密码登录

    vi /etc/my.cnf

    1. 在文件中添加,如图

    skip-grant-tables

    1. 重启 MySQL

    service mysqld restart

    1. 登录 MySQL,这里不要加 -p

    mysql -u root

    1. 修改密码(注意密码的要求)

    use mysql;
    update mysql.user set authentication_string=password('password') where user='root' ;

    1. 回到第二步,删除添加上的 skip-grant-tables
    2. 重启 MySQL 即可
    MySQL 5.7 报 ERROR 1820 (HY000) 错误

    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    解决办法:重新修改密码,以下两个命令都可以

    alter user 'root'@'localhost' identified by 'password';

    set password=password("password");

    MySQL 5.7 报 ERROR 1819 (HY000) 错误

    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

    解决办法:密码格式不符合要求,按上文说的密码格式修改密码即可

    Navicat 连接阿里云 MySQL 5.7 报 2003 错误

    2003 - Can't connect to MySQL server on 'xxx.xxx.xxx' ("10060 Unknown error")

    解决办法:

    检查 MySQL 是否启动
    检查 3306 端口是否开启

    1. 检查 MySQL 是否启动,采取以下命令,如图即为启动

    service mysqld status

    1. 检查 3306 端口是否开启,在本地机器上采用以下命令,如图即为开启

    telnet xxx.xxx.xxx(远程服务器IP) 3306

    Navicat 连接阿里云 MySQL 5.7 报 1130 错误

    1130 - Host ‘xxx.xxx.xxx’ is not allowed to connect to this MySQL server

    解决办法:发生此问题的原因是 MySQL 未开启远程访问。采用如下命令,修改 mysql 数据库下 user 表中 root 用户的 host字段即可

    use mysql;
    update user set host='%' where user = 'root';
    flush privileges;

    相关文章

      网友评论

          本文标题:Linux CentOS 7.4 安装 MySQL 5.7

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