欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux离线安装MySQL-5.7.31

程序员文章站 2024-03-21 18:15:10
...

1、安装环境

系统版本 内存 处理器内核总数 硬盘 MySQL版本
CentOS Linux release 7.2.1511 (Core) 1G 2 40G 5.7.31

下载地址:https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar

2、检查卸载MySQL|mariadb

#检查
rpm -qa | grep mysql
rpm -qa | grep mariadb

#卸载
rpm -e --nodeps [mysql组件]

如下图:

Linux离线安装MySQL-5.7.31

3、解压安装包

tar -xvf mysql-5.7.31-1.el7.x86_64.rpm-bundle.tar

4、安装MySQL(按顺序执行)

rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm

如下图:

Linux离线安装MySQL-5.7.31

5、配置默认字符集

  1. /etc/my.cnf 文件,在[mysqld] 标签下添加

    vim /etc/my.cnf
    
    [mysqld]
    init_connect='SET collation_connection = utf8_unicode_ci'
    init_connect='SET NAMES utf8'
    character-set-server=utf8
    collation-server=utf8_unicode_ci
    skip-character-set-client-handshake
    

    在最后一行添加skip-grant-tables调过密码验证

  2. /etc/my.cnf.d/client.cnf 文件,在 [client] 标签下添加

    vim /etc/my.cnf.d/client.cnf
    
    [client]
    default-character-set=utf8
    
  3. /etc/my.cnf.d/mysql-clients.cnf 文件,在 [mysql] 标签下添加

    vim /etc/my.cnf.d/mysql-clients.cnf
    
    [mysql]
    default-character-set=utf8
    

6、启动设置

  1. 启动MySQL

    service mysqld start
    
  2. 以root账户登陆mysql,直接回车

    mysql -u root -p
    
  3. 设置root账户密码

    use mysql;
    update mysql.user set authentication_string=password('root') where user='root';
    
  4. 去掉/etc/my.cnf中的skip-grant-tables,并重启MySQL

    service mysqld restart
    
  5. 再次登录MySQL,设置远程主机登录

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

    报错如下:

    mysql> GRANT ALL PRIVILEGES ON *.* TO'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    mysql> 
    

    重置密码

    alter user user() identified by "aaa@qq.com";
    FLUSH PRIVILEGES ;
    

    注意:测试远程连接的时候关闭防火墙,或开放3306端口

奇怪了,进行MySQL-5.7.31在线安装的时候就没出现过关于密码策略方面的问题,离线安装的时候却出现了。