• Centos 安装MySQL 5.7.38


    1、通过wget下载MySQL的rpm

    wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.38-1.el7.x86_64.rpm
    wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-libs-5.7.38-1.el7.x86_64.rpm
    wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.38-1.el7.x86_64.rpm
    wget https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-server-5.7.38-1.el7.x86_64.rpm
    
    • 1
    • 2
    • 3
    • 4

    2、检查是否已经安装mysql或者mariadb

    [root@localhost ~]# rpm -qa | grep mysql
    [root@localhost ~]# rpm -qa | grep mariadb
    
    • 1
    • 2

    如果安装过,上面命令会检查出相关安装信息,将其卸载

    #卸载MySQL
    rpm -qa | grep mysql | xargs  rpm -e --nodeps
    #卸载mariadb
    rpm -qa | grep mariadb| xargs  rpm -e --nodeps
    
    • 1
    • 2
    • 3
    • 4

    3、依次安装如下4个文件即可

    [root@localhost mysql]# rpm -ivh mysql-community-common-5.7.38-1.el7.x86_64.rpm
    [root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.38-1.el7.x86_64.rpm
    [root@localhost mysql]# rpm -ivh mysql-community-client-5.7.38-1.el7.x86_64.rpm
    [root@localhost mysql]# rpm -ivh mysql-community-server-5.7.38-1.el7.x86_64.rpm
    
    • 1
    • 2
    • 3
    • 4

    在安装server文件时,可能还会提示缺失其他依赖包,比如:net-tools,根据提示逐一下载相关依赖包并安装,全部依赖解决完后,再安装mysql-community-server这个rpm文件。缺失的依赖包推荐到这里下载:https://centos.pkgs.org/7/centos-x86_64/

    至此,mysql5.7所有文件安装完毕,接下来就是开启服务了。

    4、修改配置文件

    修改配置文件my.cnf,设置免密登陆

    [root@localhost ~]# vim /etc/my.cnf
    ### 可以参考如下内容
    [mysql]
    default-character-set=utf8
    
    [mysqld]
    datadir=/data/mysql
    socket=/data/mysql/mysql.sock
    slow_query_log = ON
    slow_query_log_file = /var/log/mysql_slow_query.log
    long_query_time = 3
    symbolic-links=0
    log-error=/data/mysql/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    log-bin=mysql-bin
    thread_cache_size=100
    server-id=33
    back_log=500
    lower_case_table_names=1
    #thread_concurrency=80
    #thread_concurrency=32
    query_cache_limit=12M
    query_cache_size=512M
    query_cache_type=1
    character-set-server=utf8mb4
    max_connections=3000
    innodb_buffer_pool_size=12G
    innodb_file_per_table=ON
    innodb_log_file_size=3G
    expire_logs_days=5
    read_only=1
    lower_case_table_names=1
    skip-name-resolve
    [client]
    socket=/data/mysql/mysql.sock
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    5、启动MySQL

    systemctl restart mysqld
    
    • 1

    启动时间较长,需要耐心等待,预计再10分钟左右,因为需要数据库初始化。

    6、查看MySQL初始密码

    通过my.cnf文件找到/data/mysql/mysqld.log文件,在改文件中根据password关键字查询初始密码

    #查看log-error指定的数据目录
    [root@admin02 ~]# cat /etc/my.cnf | grep log-error
    log-error=/data/mysql/mysqld.log
    
    #查看初始化密码
    [root@admin02 ~]# cat /data/mysql/mysqld.log | grep localhost
    2022-07-05T16:48:26.206485Z 1 [Note] A temporary password is generated for root@localhost: B9eldAjOiu=(
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    查看密码后,就可以使用该密码登录到MySQL,并进行后续的操作

    7、登录MySQL

    [root@admin02 ~]# mysql -uroot -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.7.38-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2022, 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> set global validate_password_policy = 0;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> SET PASSWORD = PASSWORD('root');
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    安装完成!

  • 相关阅读:
    【owt】owt-client-native-p2p-e2e-test vs2017构建 6:修改脚本自动生成vs工程
    c++ 学习 之 继承中静态成员函数和静态成员变量
    SICTF-2023-Crypto
    Nginx Web服务器搭建
    文心一言 VS 讯飞星火 VS chatgpt (232)-- 算法导论17.1 3题
    ts工具类
    开发中如何克服tomcat热部署弱的缺陷?看这篇文章就够了
    使用Vue.js和Vuex构建可维护的前端应用
    新版原型和原型链详解,看完整个人都通透
    JavaScript开发工具WebStorm入门教程:用户界面概况
  • 原文地址:https://blog.csdn.net/Victory_Lei/article/details/125623513