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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,293评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,604评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,958评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,729评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,719评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,630评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,000评论 3 397
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,665评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,909评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,646评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,726评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,400评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,986评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,959评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,197评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,996评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,481评论 2 342

推荐阅读更多精彩内容