-
准备安装包
# 切换目录 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
-
开始安装
-
安装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
-
创建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
-
初始化配置文件
#使用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
-
配置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
-
初始化数据库,启动服务
# 初始化数据库,会在/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
-
-
修改默认密码并开启远程连接
[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;
-
设置开机自启
# 将服务文件拷贝到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 nativesystemd services. SysV configuration data might be overridden by nativesystemd 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
-
测试连接-使用本地windows客户端连接mysql 端口3306,用户名root,密码123456
-
mysql升级
-
数据备份及程序升级
# 逻辑备份数据库 #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
-
观察错误日志
[root@VM-16-2-centos local]# service mysql restartERROR! 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).
-
进行数据或者配置文件的修复
-
# 查看日志文件的错误信息 [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 atThe 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
-
-
问题汇总
-
升级之后服务无法启动
-