• 在CentOS下安装MySQL


    最近自己centos虚拟机里面的mariadb忘记了密码,登录不进去了,解决安装一个mysql。

    1、首先需要先卸载mariadb

    使用rpm命令查询mariadb相关安装包:

    rpm -qa|grep mariadb

    然后依次卸载

    1. rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
    2. rpm -e --nodeps mariadb-server-5.5.64-1.el7.x86_64
    3. rpm -e --nodeps mariadb-devel-5.5.64-1.el7.x86_64
    4. rpm -e --nodeps mariadb-5.5.64-1.el7.x86_64

    但是这里会有个坑,就是我卸载完这些包之后,rpm命令竟然也跟着卸载了,不能用了。为了填坑,我参考了下面这篇博文把rpm命令给重新装回来了

    CentOS7-rpm命令找不到问题解决

    填完坑然后继续

    卸载maradb后,原数据库的数据文件不会被删掉,如果重新安装mysql,还是会读到旧的数据,所以此时需要删除旧数据,旧数据默认存放在/var/lib/mysql目录,可以重命名该文件夹或者直接删除

    同样的maradb的配置文件最好也要删除掉,否则新安装的mysql有可能读到mariadb的配置文件,配置文件的默认存储路径为:/etc/my.cnf

    2、下载mysql安装包

    下载地址:

    MySQL :: Download MySQL Community Server

     选择操作系统和版本:

    这里因为我的centos版本是7,试着安装myql 8.0以上的版本装不上,提示c++库不支持,就装了个5.7.38的版本 

    下载完成后解压

    tar -xvpf mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar

    解压后有如下的rpm包:

    1. [root@localhost mysql]# ll
    2. 总用量 1083048
    3. -rw-r--r--. 1 root root 554516480 3月 23 01:37 mysql-5.7.38-1.el7.x86_64.rpm-bundle.tar
    4. -rw-r--r--. 1 7155 31415 28991900 3月 23 01:26 mysql-community-client-5.7.38-1.el7.x86_64.rpm
    5. -rw-r--r--. 1 7155 31415 318868 3月 23 01:26 mysql-community-common-5.7.38-1.el7.x86_64.rpm
    6. -rw-r--r--. 1 7155 31415 4363096 3月 23 01:26 mysql-community-devel-5.7.38-1.el7.x86_64.rpm
    7. -rw-r--r--. 1 7155 31415 47993516 3月 23 01:26 mysql-community-embedded-5.7.38-1.el7.x86_64.rpm
    8. -rw-r--r--. 1 7155 31415 23315792 3月 23 01:26 mysql-community-embedded-compat-5.7.38-1.el7.x86_64.rpm
    9. -rw-r--r--. 1 7155 31415 132675656 3月 23 01:26 mysql-community-embedded-devel-5.7.38-1.el7.x86_64.rpm
    10. -rw-r--r--. 1 7155 31415 2704332 3月 23 01:26 mysql-community-libs-5.7.38-1.el7.x86_64.rpm
    11. -rw-r--r--. 1 7155 31415 1264876 3月 23 01:26 mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm
    12. -rw-r--r--. 1 7155 31415 186231736 3月 23 01:27 mysql-community-server-5.7.38-1.el7.x86_64.rpm
    13. -rw-r--r--. 1 7155 31415 126641600 3月 23 01:27 mysql-community-test-5.7.38-1.el7.x86_64.rpm

    3、安装mysql

    以上那么多包,我们只需要安装下面几个就行了,下面是安装命令:

    1. rpm -ivh mysql-community-common-5.7.38-1.el7.x86_64.rpm
    2. rpm -ivh mysql-community-libs-5.7.38-1.el7.x86_64.rpm
    3. rpm -ivh mysql-community-client-5.7.38-1.el7.x86_64.rpm
    4. rpm -ivh mysql-community-server-5.7.38-1.el7.x86_64.rpm

    然后启动:

    1. systemctl start mysqld
    2. systemctl enable mysqld

    4、进入mysql

    新安装的myslq,初始化密码会打印在日志中,查找初始化密码:

    1. [root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
    2. 2022-07-29T01:14:01.932720Z 1 [Note] A temporary password is generated for root@localhost: :D8TUZf>EOk<

     使用mysql -uroot -p登录mysql

    1. [root@localhost mysql]# mysql -uroot -p
    2. Enter password:
    3. Welcome to the MySQL monitor. Commands end with ; or \g.
    4. Your MySQL connection id is 5
    5. Server version: 5.7.38 MySQL Community Server (GPL)
    6. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
    7. Oracle is a registered trademark of Oracle Corporation and/or its
    8. affiliates. Other names may be trademarks of their respective
    9. owners.
    10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    参考文章:

    在CentOS下安装MySQL

  • 相关阅读:
    Docker从入门到精通,一文详解
    【STM32】sct 分散加载文件的格式与应用
    【亲测可用】图像目标识别入门-利用笔记本电脑摄像头识别人脸标记出来采用深度学习模型实现
    C++算法:柱状图中最大的矩形
    Python教学案例 - 三天打渔、两天晒网
    Python爬虫_Scrapy(一)
    数据结构 - 泛型
    il2cpp分析-gobal-metadata.dat解密
    string 中 s.size()的小问题
    竞赛 基于机器视觉的火车票识别系统
  • 原文地址:https://blog.csdn.net/hacker_lpy/article/details/126051497