个人博客


  • Linux版本:CentOS7.6
  • MySQL版本:8.0.13

1、下载MySQL8

  1. 下载地址:https://downloads.mysql.com/archives/community/
  2. 选择版本和系统版本,然后Download。
    -w1458

2、安装MySQL8

  1. 登陆root用户。

  2. 上传安装包到服务器(或者可以在服务器直接使用wget命令进行下载),并解压。

  3. 卸载mariadb,会与MySQL安装冲突。

    • rpm -qa | grep mariadb查看有无mariadb
    • 如果有则删除yum -y remove mariadb-libs.x86_64
  4. 安装numactl

    • yum list installed|grep numactl
    • 如果没有则yum install numactl,否则会在安装时报错
    1
    2
    3
    4
    5
    error:
    Failed dependencies:
    libnuma.so.1()(64bit) is needed by mysql-community-server-8.0.13-1.el7.x86_64
    libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-8.0.13-1.el7.x86_64
    libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-8.0.13-1.el7.x86_64
  5. 解压tar -xvf mysql-8.0.13-1.el7.x86_64.rpm-bundle.tar

  6. 安装4个必须安装的包(需要按顺序安装)。

    1
    2
    3
    4
    rpm -ivh mysql-community-common-8.0.13-1.el7.x86_64.rpm
    rpm -ivh mysql-community-libs-8.0.13-1.el7.x86_64.rpm
    rpm -ivh mysql-community-client-8.0.13-1.el7.x86_64.rpm
    rpm -ivh mysql-community-server-8.0.13-1.el7.x86_64.rpm
  7. 安装另外4个非必须包(需要按顺序安装也可以不装跳过此步骤)。

    1
    2
    3
    4
    rpm -ivh mysql-community-libs-compat-8.0.13-1.el7.x86_64.rpm
    rpm -ivh mysql-community-embedded-compat-8.0.13-1.el7.x86_64.rpm
    rpm -ivh mysql-community-devel-8.0.13-1.el7.x86_64.rpm
    rpm -ivh mysql-community-test-8.0.13-1.el7.x86_64.rpm
  8. 启动service mysqld start并查看状态service mysqld status

3、登陆MySQL8

  1. 查看临时密码cat /var/log/mysqld.log
    -w1304

  2. 使用临时密码登陆并修改密码。

    • mysql -u root -p回车输入临时密码。
    • alter USER 'root'@'localhost' IDENTIFIED BY '新密码(必须包含:数字大小写字母特殊字符)';
  3. 修改MySQL的root用户远程可以登陆

    • use mysql;
    • select host, user from user;
    • 如果hostlocalhost则执行update user set host = "%" where user='root';
    • 刷新生效flush privileges;
  4. 解决部分客户端无法连接的问题,比如dbvisualizer
    Unable to load authentication plugin 'caching_sha2_password

    • mysql -u root -p回车输入密码。
    • alter USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root用户的密码';
    • 刷新生效flush privileges;

4、更改时区

1.查看当前时间。

1
select now() from dual;

2.如果发现和当前系统时间不一致,则需要根据实际情况来修改。

1
2
set persist time_zone='-5:00';
flush privileges;

3.查看修改后的时区和当前时间。

1
2
show variables like '%time_zone%';
select now() from dual;

参考链接