当前位置:网站首页>MySQL8.0升级的踩坑历险记
MySQL8.0升级的踩坑历险记
2022-04-23 11:02:00 【liming89】
文章来源: 学习通http://www.bdgxy.com/
前言
最近忙于Fighting的项目,所以笔耕有些松懈,实为不该。
刚好遇到需要从MySQL5.7.33升级到MySQL8.0.x的需求,于是记录一下整个升级过程,踩坑而过。
背景梗概:本地docker容器中使用的MySQL是5.7.33(镜像系统用的是ubuntu16.04),而新项目在线上使用了MySQL8.0。从线上导出的sql文件(表结构+数据)中有一种低版本MySQL不会用到的字符编码,一导入就报错,遇到的字符集报错如下所示:
- Unknown collation: 'utf8mb4_0900_ai_ci'
一顿搜索之后,我也冷静了下来,有两种思路,一种是被我称为掩耳盗铃式解决方法,一种是根治的办法。
掩耳盗铃,顾名思义,不解决本质问题,而是通过批量替换字符集的方式解决报错,也就是把文件中所有的utf8mb4_0900_ai_ci 替换为:utf8_general_ci。
第二种就是保持和线上的MySQL版本一致,这样就能支持该字符集。
于是我采用第二种方法,升级我的docker容器中的MySQL,顺便也可以打包一个新的镜像。
升级的过程也有点坎坷,但逻辑是清晰地。
1.先彻底卸载现有版本MySQL。
可以使用如下命令:
#删除mysql的数据文件 sudo rm -R /var/lib/mysql/ #删除mysql的配置文件
sudo rm -R /etc/mysql/
#自动卸载mysql(包括server和client)
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
记得一定要删除配置文件,因为有可能不兼容。
2.下载deb并按照MySQL8.x。
可以去官网下载,官网地址为https://dev.mysql.com/repo/apt
我们选择最新的deb下载,网址为:
https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb。在命令后使用wget命令进行下载,如下:
wget https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb
下载完成之后使用dpkg命令并更新apt源,然后就可以进行安装了,完整命令如下所示:
dpkg -i mysql-apt-config_0.8.20-1_all.deb apt-get update apt-get install -y mysql-server
在最后一个命令执行过程中,它会让你输入root密码和一些基本配置,然后就可以完成安装了。
因为是在ubuntu里面安装的MySQL,所以启动方式为:
service mysql start
你可以使用命令查看进程运行情况,正常的时候类似如需输出:
/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock
3.创建用户和配置权限。
MySQL8.0.x实际使用的过程中发现用户授权和之前版本有点不同,需要分三步:
- 创建用户。
- 分配权限。
- 刷新权限。
具体的sql语句如下,顺序也是严格的:
create user 'freephp'@'%' identified by '176serTTc8Cg';
grant all privileges on dev_database.* to ‘freephp’@‘%’ with grant option;
flush privileges;
上面的sql解释一下,第一句是创建一个名为freephp的用户,密码为176serTTc8Cg,%代表可以任意主机进行连接。
第二句的意思是把dev_database的所有权限赋予用户freephp。
第三句就是立即刷新权限,让新创建的权限生效。
自此历险记大功告成,MySQL8.0的新特性还需要探索,下次再聊。
总结
到此这篇关于MySQL8.0升级踩坑的文章就介绍到这了,更多相关MySQL8.0升级踩坑内容请搜索菜鸟教程www.piaodoo.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持菜鸟教程www.piaodoo.com!
版权声明
本文为[liming89]所创,转载请带上原文链接,感谢
https://blog.csdn.net/liming89/article/details/124343280
边栏推荐
- Understand the key points of complement
- Excel · VBA array bubble sorting function
- MBA - day5 mathématiques - Questions d'application - Questions d'ingénierie
- Anaconda3 installation
- VIM usage
- Kaggle - real battle of house price prediction
- JDBC – PreparedStatement – 如何设置 Null 值?
- Download and installation steps of xshell + xftp
- 关于JUC三大常用辅助类
- The songbird document editor will be open source: starting with but not limited to markdown
猜你喜欢

SVN的使用:

Jupyter lab top ten high productivity plug-ins

Introduction to data analysis 𞓜 kaggle Titanic mission (III) - > explore data analysis

高价买来的课程,公开了!phper资料分享

Introduction to neo4j authoritative guide, recommended by Qiu Bojun, Zhou Hongxiang, Hu Xiaofeng, Zhou Tao and other celebrities

一道有趣的阿里面试题

vm设置静态虚拟机

Let the LAN group use the remote device

【leetcode】102. Sequence traversal of binary tree

Mysql8.0安装指南
随机推荐
Simple thoughts on the design of a microblog database
关于JUC三大常用辅助类
Installing MySQL with CentOS / Linux
Which company is good for opening futures accounts? Who can recommend several safe and reliable futures companies?
主流手机分辨率与尺寸
【leetcode】102.二叉树的层序遍历
闹钟场景识别
Charles function introduction and use tutorial
The songbird document editor will be open source: starting with but not limited to markdown
ID number verification system based on visual structure - Raspberry implementation
Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
MBA-day6 逻辑学-假言推理练习题
Visual common drawing (I) stacking diagram
数据库管理软件SQLPro for SQLite for Mac 2022.30
Reading integrity monitoring techniques for vision navigation systems - 5 Results
【leetcode】199.二叉树的右视图
Restful、SOAP、RPC、SOA、微服务之间的区别
The difference between restful and soap
Typora operation skill description (I)
VIM usage