centos7 安装 mysql5.7

  1. 检查是否安装过mysql

    rpm -qa|grep mariadb
    mariadb-libs-5.5.68-1.el7.x86_64
  2. 如果存在通过如下命令卸载

    rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
  3. 下载mysql包

    https://dev.mysql.com/downloads/mysql/

  4. 上传到服务器解压
     

    [root@hadoop207 software]# mkdir mysql
    [root@hadoop207 software]# tar -xvf mysql-5.7.37-1.el7.x86_64.rpm-bundle.tar -C ./mysql
    mysql-community-client-5.7.37-1.el7.x86_64.rpm
    mysql-community-common-5.7.37-1.el7.x86_64.rpm
    mysql-community-devel-5.7.37-1.el7.x86_64.rpm
    mysql-community-embedded-5.7.37-1.el7.x86_64.rpm
    mysql-community-embedded-compat-5.7.37-1.el7.x86_64.rpm
    mysql-community-embedded-devel-5.7.37-1.el7.x86_64.rpm
    mysql-community-libs-5.7.37-1.el7.x86_64.rpm
    mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm
    mysql-community-server-5.7.37-1.el7.x86_64.rpm
    mysql-community-test-5.7.37-1.el7.x86_64.rpm
    [root@hadoop207 software]#
  5. 按照顺序执行以下

    sudo rpm -ivh mysql-community-common-5.7.37-1.el7.x86_64.rpm
    sudo rpm -ivh mysql-community-libs-5.7.37-1.el7.x86_64.rpm
    sudo rpm -ivh mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm
    sudo rpm -ivh mysql-community-client-5.7.37-1.el7.x86_64.rpm
    sudo rpm -ivh mysql-community-server-5.7.37-1.el7.x86_64.rpm
    [root@hadoop207 mysql]# sudo rpm -ivh mysql-community-common-5.7.37-1.el7.x86_64.rpm
    警告:mysql-community-common-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-common-5.7.37-1.e################################# [100%]
    [root@hadoop207 mysql]# sudo rpm -ivh mysql-community-libs-5.7.37-1.el7.x86_64.rpm
    警告:mysql-community-libs-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-libs-5.7.37-1.el7################################# [100%]
    [root@hadoop207 mysql]# sudo rpm -ivh mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm
    警告:mysql-community-libs-compat-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-libs-compat-5.7.3################################# [100%]
    [root@hadoop207 mysql]# sudo rpm -ivh mysql-community-client-5.7.37-1.el7.x86_64.rpm
    警告:mysql-community-client-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-client-5.7.37-1.e################################# [100%]
    [root@hadoop207 mysql]# sudo rpm -ivh mysql-community-server-5.7.37-1.el7.x86_64.rpm
    警告:mysql-community-server-5.7.37-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
    准备中...                          ################################# [100%]
    正在升级/安装...
       1:mysql-community-server-5.7.37-1.e################################# [100%]
    [root@hadoop207 mysql]#

  6. 安装途中可能会报错,因为我不是第一次安装,所以本次没有报错,一般会出现缺少libao这个依赖的,那就使用以下命令安装libao

    yum install -y libaio
  7. 查看/etc/my.cnf,并删除datadir指向的文件夹下的所有内容,一般第一次安装这里不会有东西

    [root@hadoop207 mysql]# cat /etc/my.cnf
    # For advice on how to change settings please see
    # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
    
    [mysqld]
    #
    # Remove leading # and set to the amount of RAM for the most important data
    # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
    # innodb_buffer_pool_size = 128M
    #
    # Remove leading # to turn on a very important data integrity option: logging
    # changes to the binary log between backups.
    # log_bin
    #
    # Remove leading # to set options mainly useful for reporting servers.
    # The server defaults are faster for transactions and fast SELECTs.
    # Adjust sizes as needed, experiment to find the optimal values.
    # join_buffer_size = 128M
    # sort_buffer_size = 2M
    # read_rnd_buffer_size = 2M
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    [root@hadoop207 mysql]# cd /var/lib/mysql
    [root@hadoop207 mysql]# rm -rf ./*
    [root@hadoop207 mysql]#
    
  8. 初始化数据库

     sudo mysqld --initialize --user=mysql
  9. 查看刚才初始化临时生成的密码

    [root@hadoop207 mysql]#  sudo mysqld --initialize --user=mysql
    [root@hadoop207 mysql]# cat /var/log/mysqld.log
    2022-03-17T02:25:58.909440Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2022-03-17T02:25:59.267735Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2022-03-17T02:25:59.324053Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2022-03-17T02:25:59.385461Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 953a662d-a599-11ec-8097-000c29033aed.
    2022-03-17T02:25:59.388007Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2022-03-17T02:25:59.797101Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
    2022-03-17T02:25:59.797130Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
    2022-03-17T02:25:59.797672Z 0 [Warning] CA certificate ca.pem is self signed.
    2022-03-17T02:26:00.211341Z 1 [Note] A temporary password is generated for root@localhost: BSw:0iia8Sal
    [root@hadoop207 mysql]#
  10. 启动mysql服务

    sudo systemctl start mysqld
  11. 登陆mysql,使用刚才临时生成的密码登陆

    [root@hadoop207 mysql]# sudo systemctl start mysqld
    [root@hadoop207 mysql]#  mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.37
    
    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>
  12. 修改mysql root用户密码,并允许root用户在任意ip登陆

    mysql> set password = password("root");我的密码就设置成了root
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> update mysql.user set host='%' where user='root';
    Query OK, 1 row affected (0.01 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql>  flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
    
  13. 退出mysql,并使用刚设置的密码登陆试试

    mysql> exit
    Bye
    [root@hadoop207 mysql]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 3
    Server version: 5.7.37 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>
    
  14. ok了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值