惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
Docker
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
腾讯CDC
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
IT之家
IT之家
月光博客
月光博客
U
Unit 42
K
Kaspersky official blog
T
Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
P
Proofpoint News Feed
Last Week in AI
Last Week in AI
云风的 BLOG
云风的 BLOG
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
Engineering at Meta
Engineering at Meta
Recorded Future
Recorded Future
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Security @ Cisco Blogs
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Security Archives - TechRepublic
Security Archives - TechRepublic
Webroot Blog
Webroot Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Schneier on Security
S
Secure Thoughts
The Register - Security
The Register - Security
B
Blog RSS Feed
The Last Watchdog
The Last Watchdog
P
Palo Alto Networks Blog
爱范儿
爱范儿
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
L
LINUX DO - 热门话题
C
Cisco Blogs
Spread Privacy
Spread Privacy
F
Full Disclosure
博客园 - 聂微东
T
The Blog of Author Tim Ferriss

ncc的个人网站

MCSManager 数据备份与迁移实践 Goland Update Delve frp反向代理群晖WebDAV服务器 备份mc服务器脚本 威联通使用screen报错 Cannot find terminfo entry for 'screen.linux' Brew No Available Formula Gitea迁移和SSH容器直通 QQ邮箱文件夹重新开启通知 Act_runner 使用 supervisor 启动无法正常识别到 asdf 设置的环境问题(二) 将博客从Typecho迁移到Hugo
1panel安装的Mysql版本从5.7升级到8.4.5
FGHWETT · 2025-06-09 · via ncc的个人网站

注意

本文最后更新于 2025-06-10,文中内容可能已过时。

之前1panel安装的Mysql版本是5.7,由于很多开源项目将最低支持版本提升到了8.0以上,所以我直接升级到了8.4.5。

升级前准备

安装mysql-shell检查升级兼容性

1
2
apt install mysql-shell
mysqlsh -- util check-for-server-upgrade root@localhost:3306 --target-version=8.4.5 --output-format=JSON  > upgrade_report.json

导出所有数据库

1
2
cd /root/
docker exec mysql mysqldump -u root -pmysql_pwssword --ignore-table=mysql.innodb_index_stats --ignore-table=mysql.innodb_table_stats --all-databases > backup.sql

停止并备份数据库

1
2
3
4
cd /opt/1panel/apps/mysql/mysql/
docker-compose down
cd ../
tar -czvf /root/mysql.tar.gz mysql

升级操作

创建新版本数据库

创建8.4.5版本并启动 可以从1panel创建 也可以单独创建 这里我单独创建了

 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
36
37
38
39
40
41
42
43
44
45
46
47
48
# 创建目录
mkdir -p /opt/app/mysql/conf
cd /opt/app/mysql/

# 创建compose文件
cat > docker-compose.yml <<EOF
services:
  mysql:
    container_name: mysql
    image: mysql:8.4.5
    environment:
      MYSQL_ROOT_PASSWORD: must_change_to_your_password
    ports:
      - 3306:3306
    restart: unless-stopped
    volumes:
      - ./data/:/var/lib/mysql
      - ./conf/my.cnf:/etc/my.cnf
      - ./log:/var/log/mysql
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    command:
      - --mysql-native-password=on
    networks:
      - 1panel-network

networks:
  1panel-network:
    external: true
EOF

# 创建配置文件
cat > conf/my.cnf <<EOF
[mysqld]
host-cache-size=0
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql

pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock

!includedir /etc/mysql/conf.d/
EOF
docker-compose up -d

恢复数据

1
2
docker cp /root/backup.sql mysql:/backup.sql
docker exec -i mysql mysql -u root -p'mysql_password' < /root/backup.sql

1panel连接

在1panel中添加mysql远程数据库,并同步数据库。

此时会报错:

1
Error 1449 (HY000): The user specified as a definer ('mysql.infoschema'@'localhost) does not exist;

处理方案一(搞了半天开始要处理数据库引擎)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 创建账号
CREATE USER 'mysql.infoschema'@'localhost' IDENTIFIED BY '你的密码';

# 修复报错 mysql8 ERROR 1726 (HY000): Storage engine ‘MyISAM’ does not support system tables. [mysql.user]
ALTER TABLE mysql.user ENGINE = InnoDB;

# 修复报错 ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'Timestamp' at row 1
## 临时关闭严格模式
SET SESSION sql_mode = '';
## 清理无效日期 即可再次转换
UPDATE mysql.tables_priv SET Timestamp = NULL WHERE Timestamp = '0000-00-00 00:00:00';

# 上述步骤依次执行 直到没有报错

方案二(如果方案一可以就无须方案二)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 切换数据库
use mysql;

# 查询用户信息
select * from user where User ='mysql.infoschema';

# 删除旧的信息
delete from user where User ='mysql.infoschema';

# 插入新的信息
INSERT INTO mysql.user(`Host`,`User`,`plugin`,`authentication_string`,ssl_cipher,x509_issuer,x509_subject) VALUES ('localhost','mysql.infoschema','mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','','','');

# 更新用户信息
update mysql.user set Select_priv = 'Y' where User = 'mysql.infoschema';

# 刷新账号
FLUSH PRIVILEGES;

更新后台密码

1panel后台修改密码为之前的密码,此时会报错。

1
Error 1805 (HY000): Column count of mysql.user is wrong. Expected 51, found 45. The table is probably corrupted

需要对mysql进行升级,由于恢复的时候用户表也被恢复了。

一般是mysql_upgrade --force -u root -p,但是不一定所有的版本都还有这个命令,所以也可以使用mysqld --upgrade=FORCE

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
docker run --rm \
  --name mysql-upgrade \
  -v ./data/:/var/lib/mysql \
  -v ./conf/my.cnf:/etc/my.cnf \
  -v ./log:/var/log/mysql \
  mysql:8.4.5 \
  mysqld --upgrade=FORCE

# 结束后停止
docker stop mysql-upgrade

# 启动数据库
docker-compose up -d

现在就可以正常修改密码了,一般到这里也就正式迁移完成了,后续有问题还会补充。

参考链接