Centos二进制方式搭建Mysql8,并升级mysql8.0.33到mysql8.3.0

  1. 准备安装包

    # 切换目录
    cd /usr/local/src/
    # 下载libaio包
    wget http://mirror.centos.org/centos/7/os/x86_64/Packages/libaio-0.3.109-13.el7.x86_64.rpm
    # 下载MySQL8.0.33安装包
    wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar.xz
    # 下载mysql8.3.0安装包
    wget https://cdn.mysql.com/archives/mysql-8.3/mysql-8.3.0-linux-glibc2.17-x86_64.tar.xz
    wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.43-linux-glibc2.12-x86_64.tar.gz
    wget https://cdn.mysql.com/archives/mysql-8.4/mysql-8.4.0-linux-glibc2.17-x86_64.tar.xz
    # 批量解压缩或者使用tar -xvf   xxx.tar.xz单个解压缩
    # 测试xargs命令  echo "1 2 , 3 4" |xargs -n1
    ls *.tar.xz | xargs -n1 tar xvf
    

  2. 开始安装

    1. 安装libaio包

      # 查询libaio是否安装,下面提示已安装,跳过此步骤
      [root@VM-16-2-centos mysql]# rpm -qa |grep libaio
      libaio-0.3.109-13.el7.x86_64
      [root@VM-16-2-centos mysql]#
      
      # 如果提示未安装libaio,则进行安装
      [root@VM-16-2-centos mysql]# # rpm -ivh libaio-0.3.109-13.el7.x86_64.rpm
      

    2. 创建mysql用户和用户组

      # 查询mysql的用户和用户组是否存在,下面提示存在则跳过此步骤
      [root@VM-16-2-centos mysql]# cat /etc/passwd |grep mysql
      mysql:x:995:1001::/home/mysql:/bin/bash
      [root@VM-16-2-centos mysql]# cat /etc/group |grep mysql
      mysql:x:1001:
      [root@VM-16-2-centos mysql]#
      # 如果不存在则创建mysql用户和用户组
      # 创建用户组mysql
      groupadd mysql
      # 创建用户mysql并将其添加到用户组mysql
      useradd -r -g mysql mysql

    3. 初始化配置文件

      #使用vi命令编辑 vi /etc/my.cnf, 内容如下
      
      [mysqld]
      port = 3306
      user = mysql
      #basedir=/usr/local/src/mysql-8.4.0-linux-glibc2.17-x86_64
      datadir=/data/mysql-data
      # 设置binlog日志有效期20天
      expire_logs_days=20
      log_error=error.log
      general_log=OFF
      
      [mysql]
      prompt=\\u@\\h:\\d \\r:\\m:\\s>
      
      [client]
      user=root
      password=123456

    4. 配置mysql的相关软连接和配置

      # mysql主目录软连接到usr/local/mysql
      ln -s /usr/local/src/mysql-8.0.33-linux-glibc2.17-x86_64-minimal /usr/local/mysql
      # 软连接mysql客户端和启动脚本
      ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
      ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

    5. 初始化数据库,启动服务

      # 初始化数据库,会在/data/mysql-data下创建元数据
      /usr/local/mysql/bin/mysqld --initialize --user=mysql
      # 启动mysql数据库
      /usr/local/mysql/bin/mysqld_safe --user=mysql &
      # 之后可以使用service启动,停止数据库
      service mysql start
      
      ## 初始化后会在最后提示密码
      [root@VM-16-2-centos data]# /usr/local/mysql/bin/mysqld --initialize --user=mysql
      2024-07-08T02:28:13.187355Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
      2024-07-08T02:28:13.187378Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.33) initializing of server in progress as process 13654
      2024-07-08T02:28:13.194616Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
      2024-07-08T02:28:13.207166Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
      2024-07-08T02:28:13.919112Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
      2024-07-08T02:28:15.322041Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: FCjdMJ,W<1El
      
      ## 启动后会提示错误日志文件的位置 /data/mysql-data/error.log
      [root@VM-16-2-centos data]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
      [1] 15620
      [root@VM-16-2-centos data]# 2024-07-08T02:33:22.288351Z mysqld_safe Logging to '/data/mysql-data/error.log'.
      2024-07-08T02:33:22.313324Z mysqld_safe Starting mysqld daemon with databases from /data/mysql-data
      
      ## 可以在错误日志文件中查询初始密码
      [root@VM-16-2-centos data]# cat /data/mysql-data/error.log |grep password
      2024-07-08T02:33:12.323826Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: FCjdMJ,W<1El
      
      

  3. 修改默认密码并开启远程连接

    [root@VM-16-2-centos data]# mysql -u root -p'FCjdMJ,W<1El'
    
    # 以下操作均在mysql bash中输入
    
    # 密码设置为123456,永不过期
    ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
    # 刷新权限
    flush privileges;
    
    # 切换至mysql数据库
    use mysql;
    # 设置允许远程登录,不限制ip
    update user set user.Host='%' where user.User='root';
    # 刷新权限
    flush privileges;
    

  4. 设置开机自启

    # 将服务文件拷贝到init.d下,并重命名为mysql
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
    # 赋予可执行权限
    chmod 777 /etc/init.d/mysql
    # 添加服务到自启动列表
    chkconfig --add mysql
    # 查询自启动列表
    [root@VM-16-2-centos data]# chkconfig 
    
    Note: This output shows SysV services only and does not include native
          systemd services. SysV configuration data might be overridden by native
          systemd configuration.
    
          If you want to list systemd services use 'systemctl list-unit-files'.
          To see services enabled on particular target use
          'systemctl list-dependencies [target]'.
    
    mysql          	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
    network        	0:off	1:off	2:on	3:on	4:on	5:on	6:off

  5. 测试连接-使用本地windows客户端连接mysql 端口3306,用户名root,密码123456

  6. mysql升级

    1. 数据备份及程序升级

      # 逻辑备份数据库
      #mysqldump备份
      mysqldump -uroot -p123456 --all-databases > ./back.sql
      mysqldump -u root -p --all-databases --single-transaction --quick --lock-tables=false > full-backup.sql
      # 停止mysql服务
      service mysql stop 
      # 备份数据库目录
      cp -r /data/mysql-data/ /data/mysql-data0708
      # 删除软连接
      unlink /usr/local/mysql
      # 创建软连接-升级后的程序目录
      ln -s /usr/local/src/mysql-8.3.0-linux-glibc2.17-x86_64 mysql
      # 启动mysql服务
      service mysql start
      
      
      
      # 备注 mysql数据恢复命令
      # mysql -u root -p --force < data-for-upgrade.sql

    2. 观察错误日志

      [root@VM-16-2-centos local]# service mysql restart
       ERROR! MySQL server PID file could not be found!
      Starting MySQL... ERROR! The server quit without updating PID file (/data/mysql-data/VM-16-2-centos.pid).

    3. 进行数据或者配置文件的修复

    4. # 查看日志文件的错误信息
      [root@VM-16-2-centos local]# cat /data/mysql-data/error.log |grep 'ERROR'
      2024-07-08T03:00:49.368924Z 0 [ERROR] [MY-000067] [Server] unknown variable 'expire_logs_days=20'.
      2024-07-08T03:00:49.370590Z 0 [ERROR] [MY-010119] [Server] Aborting
      2024-07-08T03:00:55.287583Z 0 [ERROR] [MY-000067] [Server] unknown variable 'expire_logs_days=20'.
      2024-07-08T03:00:55.288511Z 0 [ERROR] [MY-010119] [Server] Aborting
      # 删除配置文件的日志过期时间的配置,或者重新设置日志过期时间
      [root@VM-16-2-centos local]# /usr/local/mysql/bin/mysqld --help --verbose |grep expire
        --binlog-expire-logs-auto-purge 
                            (Defaults to on; use --skip-binlog-expire-logs-auto-purge to disable.)
        --binlog-expire-logs-seconds=# 
                            binlog_expire_logs_seconds seconds; Purges happen at
                            The number of days after which the password will expire.
        --disconnect-on-expired-password 
                            (Defaults to on; use --skip-disconnect-on-expired-password to disable.)
                            with a random expired password and store it into the log.
                            The timeout to expire sessions in the TLS session cache
      binlog-expire-logs-auto-purge                                TRUE
      binlog-expire-logs-seconds                                   2592000
      disconnect-on-expired-password                               TRUE
      [root@VM-16-2-centos local]# 
      # 可以看到binlog过期时间的设置是binlog-expire-logs-seconds,并且有默认值,单位是秒
      vi /etc/my.cnf
      #设置binlog的过期时间是20天
      binlog-expire-logs-seconds=1728000

  7. 问题汇总

    1. 升级之后服务无法启动

相关推荐

  1. 二进制方式安装mysql

    2024-07-11 14:02:03       29 阅读
  2. CentOS 7系统下通过二进制方式安装MySQL 8.0.34

    2024-07-11 14:02:03       35 阅读
  3. 实现:mysql-5.7.42 mysql-8.2.0 的升级(rpm方式

    2024-07-11 14:02:03       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 14:02:03       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 14:02:03       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 14:02:03       57 阅读
  4. Python语言-面向对象

    2024-07-11 14:02:03       68 阅读

热门阅读

  1. Python 获取 SQL 指纹和 HASH 值

    2024-07-11 14:02:03       25 阅读
  2. 井字棋 AI-Python

    2024-07-11 14:02:03       25 阅读
  3. android解锁remount

    2024-07-11 14:02:03       27 阅读
  4. 洛谷 P3008 [USACO11JAN] Roads and Planes G

    2024-07-11 14:02:03       22 阅读
  5. 2.Spring的IOC容器里面加入对象的常见方式

    2024-07-11 14:02:03       24 阅读
  6. React基础学习-Day02

    2024-07-11 14:02:03       20 阅读
  7. MyClass.static_method() 加不加括号有什么区别

    2024-07-11 14:02:03       23 阅读
  8. AcWing 1633:外观数列

    2024-07-11 14:02:03       26 阅读
  9. nginx的重定向

    2024-07-11 14:02:03       24 阅读
  10. SpringBoot整合Easy-Es最佳实践

    2024-07-11 14:02:03       21 阅读