CentOS 7 安装MySQL 8.0教程

  1. 下载安装包

    官方下载网址

    image.png
  2. 点击Download 下载mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar

  3. 点击No thanks, just start my download 直接下载

    image.png

    也可以在Centos7wget直接下载 [root@Centos ~]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar

    [root@Centos ~]# wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar
    --2021-04-29 18:03:19--  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar
    Resolving cdn.mysql.com (cdn.mysql.com)... 23.204.250.61
    Connecting to cdn.mysql.com (cdn.mysql.com)|23.204.250.61|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 793600000 (757M) [application/x-tar]
    Saving to: ‘mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar’
    
    100%[==========================================================================================================>] 793,600,000 7.66MB/s   in 1m 47s 
    
    2021-04-29 18:05:06 (7.09 MB/s) - ‘mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar’ saved [793600000/793600000]
    
    
  4. 把下载好的mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar上传至服务器

    image.png
  5. 通过 rpm -qa | grep mariadb 命令查看 mariadb的安装包

    image.png
  6. 通过 rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps 命令装卸 mariadb

    [root@Centos ~]# rpm -e mariadb-libs-5.5.60-1.el7_5.x86_64 --nodeps

  7. 通过 rpm -qa | grep mariadb 命令再次查看 mariadb 的安装包

    image.png
  8. /usr/local目录创建mysql目录

    [root@Centos local]# mkdir mysql
    
  9. mysql安装包移到新创建的/usr/local/mysql目录

    [root@Centos ~]# ls
    mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar
    [root@Centos ~]# mv mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar  /usr/local/mysql/ 
    
  10. 通过 ls命令查看一下/usr/local/mysql

    [root@Centos mysql]# ls
    mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar        
    #已经完成移动
    
  11. 通过 tar 命令解压 tar

    [root@Centos mysql]# tar -xvf mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar 
    
  12. 通过ls命令查看解压的结果

    
    [root@Centos mysql]# ls
    mysql-8.0.24-1.el7.x86_64.rpm-bundle.tar                mysql-community-embedded-compat-8.0.24-1.el7.x86_64.rpm
    mysql-community-client-8.0.24-1.el7.x86_64.rpm          mysql-community-libs-8.0.24-1.el7.x86_64.rpm
    mysql-community-client-plugins-8.0.24-1.el7.x86_64.rpm  mysql-community-libs-compat-8.0.24-1.el7.x86_64.rpm
    mysql-community-common-8.0.24-1.el7.x86_64.rpm          mysql-community-server-8.0.24-1.el7.x86_64.rpm
    mysql-community-devel-8.0.24-1.el7.x86_64.rpm           mysql-community-test-8.0.24-1.el7.x86_64.rpm
    #接下来开始正式安装
    
  13. 通过 rpm -ivh mysql-community-common-8.0.24-1.el7.x86_64.rpm --nodeps --force 命令安装 common]

    [root@Centos mysql]# rpm -ivh mysql-community-common-8.0.24-1.el7.x86_64.rpm  --nodeps --force
    warning: mysql-community-common-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql-community-common-8.0.24-1.e################################# [100%]
    
  1. 通过 rpm -ivh mysql-community-libs-8.0.24-1.el7.x86_64.rpm --nodeps --force 命令安装 libs

    [root@Centos mysql]# rpm -ivh mysql-community-libs-8.0.24-1.el7.x86_64.rpm --nodeps --force
    warning: mysql-community-libs-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql-community-libs-8.0.24-1.el7################################# [100%]
    
  2. 通过 rpm -ivh mysql-community-client-8.0.24-1.el7.x86_64.rpm --nodeps --force 命令安装 client

    [root@Centos mysql]# rpm -ivh mysql-community-client-8.0.24-1.el7.x86_64.rpm --nodeps --force
    warning: mysql-community-client-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql-community-client-8.0.24-1.e################################# [100%]
    
  3. 通过 rpm -ivh mysql-community-server-8.0.24-1.el7.x86_64.rpm --nodeps --force 命令安装 server

    [root@Centos mysql]# rpm -ivh mysql-community-common-8.0.24-1.el7.x86_64.rpm  --nodeps --force
    
    warning: mysql-community-common-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql-community-common-8.0.24-1.e################################# [100%]
    [root@iZwz91gi0pal3t5041g3foZ mysql]# rpm -ivh mysql-community-libs-8.0.24-1.el7.x86_64.rpm --nodeps --force
    warning: mysql-community-libs-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql-community-libs-8.0.24-1.el7################################# [100%]
    [root@iZwz91gi0pal3t5041g3foZ mysql]# rpm -ivh mysql-community-client-8.0.24-1.el7.x86_64.rpm --nodeps --force
    warning: mysql-community-client-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql-community-client-8.0.24-1.e################################# [100%]
    [root@iZwz91gi0pal3t5041g3foZ mysql]# rpm -ivh mysql-community-server-8.0.24-1.el7.x86_64.rpm
    warning: mysql-community-server-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    error: Failed dependencies:
            libaio.so.1()(64bit) is needed by mysql-community-server-8.0.24-1.el7.x86_64
            libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-8.0.24-1.el7.x86_64
            libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-8.0.24-1.el7.x86_64
    [root@iZwz91gi0pal3t5041g3foZ mysql]# rpm -ivh mysql-community-server-8.0.24-1.el7.x86_64.rpm --nodeps --force
    warning: mysql-community-server-8.0.24-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql-community-server-8.0.24-1.e################################# [100%]
    
  1. 通过rpm -qa | grep mysql 查看mysql安装包

    
    [root@Centos mysql]# rpm -qa | grep mysql     
    mysql-community-libs-8.0.24-1.el7.x86_64
    mysql-community-server-8.0.24-1.el7.x86_64
    mysql-community-common-8.0.24-1.el7.x86_64
    mysql-community-client-8.0.24-1.el7.x86_64
    
  2. 通过以下命令,完成对 mysql数据库的初始化和相关配置

    [root@Centos mysql]# mysqld --initialize
    [root@Centos mysql]# chown mysql:mysql /usr/local/mysql -R
    [root@Centos mysql]# systemctl start mysqld.service
    [root@Centos mysql]# systemctl enable mysqld
    

    如果执行mysqld --initialize的时候报错,就需要安装libaio

    [root@Centos mysql]# mysqld --initialize
    mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
    

    解决方式:

    [root@Centos mysql]# yum install -y libaio

    如果提示日志提示:

    [ERROR] [MY-012271] [InnoDB] The innodb_system data file 'ibdata1' must be writable

    解决方式:设置权限

    [root@Centos mysql]# find / -name ibdata1
    /var/lib/mysql/ibdata1
    [root@Centos mysql]# chmod -R 777 /var/lib/mysql
    
  3. 通过 cat /var/log/mysqld.log | grep password 命令查看数据库的密码

image.png
  1. 通过 mysql -uroot -p 敲回车键进入数据库登陆界面

    [root@Centos mysql]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 8
    Server version: 8.0.24
    
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    
    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> 
    
  1. 通过 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'命令来修改密码

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> exit;
    

    在此修改密码为123456为例,根据自身实际情况设置密码

  2. 通过 exit; 命令退出 MySQL,然后通过新密码再次登陆

    mysql> exit;
    Bye
    [root@Centos mysql]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 9
    Server version: 8.0.24 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    
    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> 
    
  3. 通过以下命令,进行远程访问的授权

    create user 'root'@'%' identified with mysql_native_password by '123456';
    grant all privileges on *.* to 'root'@'%' with grant option;
    flush privileges;
    
    
    mysql> create user 'root'@'%' identified with mysql_native_password by '123456';
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> grant all privileges on *.* to 'root'@'%' with grant option;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> 
    
  4. 通过 ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;命令修改加密规则,MySql8.0 版本 和 5.0 的加密规则不一样,而现在的可视化工具只支持旧的加密方式。

    mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;    
    Query OK, 0 rows affected (0.01 sec)
    
  5. 通过 flush privileges; 命令刷新修该后的权限

    mysql>  flush privileges; 
    Query OK, 0 rows affected (0.00 sec)
    
  6. 通过 exit; 命令退出 MySQL

    mysql> exit;
    Bye
    
  7. 自此就可以用Navicat链接数据库,如果链接不成功就看一下检查防火墙。

这里用ssh登录到服务器再转到MySQL的方式登录数据库:

image.png
image.png

点击测试连接看是否成功:

image.png

你可能感兴趣的:(CentOS 7 安装MySQL 8.0教程)