Windows下安装MySQL 5.7.17压缩版中遇到的坑
作者:瓜园耕读 时间:2024-01-21 17:06:54
首先下载最新的MySQL 5.7.17 Community 压缩版 for Windows 64-bit:
官方下载地址:http://dev.mysql.com/downloads/mysql/
然后解压到安装目录(如C:\Prog\MySQL\)。接下来复制my-default.ini为my.ini,修改my.ini如下:
[mysql]
default-character-set=utf8mb4
[mysqld]
basedir = C:\Prog\MySQL
datadir = C:\Prog\MySQL\data
port = 3306
max_connections=200
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
default-storage-engine=INNODB
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
之后用“管理员身份”打开cmd——“管理员身份”这很重要,进入安装目录安装MySQL服务:
C:\Prog\MySQL\bin>mysqld install
Service successfully installed.
然后启动MySQL服务:
net start mysql
刚开始以为就这么简单,可是幺蛾子的却报错了:
如果是通过Windows系统的“服务”启动,则提示:
问题出得实在是心塞不已,查了许久,原来是:
If you installed MySQL using the Noinstall package, you may need to initialize the data directory:
Windows distributions prior to MySQL 5.7.7 include a data directory with a set of preinitialized accounts in the mysql database.
As of 5.7.7, Windows installation operations performed using the Noinstall package do not include a data directory. To initialize the data directory, use the instructions at Section 2.10.1.1, “Initializing the Data Directory Manually Using mysqld”.
具体可参考这两个链接:
2.3.5.4 Initializing the Data Directory
2.10.1.1 Initializing the Data Directory Manually Using mysqld
原因找到了,那我们来手动Initialize Data Directory一下啊:
mysqld --defaults-file=C:\Prog\MySQL\my.ini --initialize-insecure
然后依次:
net start mysql
mysql -u root -p
熟悉的mysql>应该就出来了。
希望对遇到类似坑的人有所帮助,究其原因就是5.7.7及以后的压缩包版本,更改为需要手动Initialize Data Directory了。
技无一招鲜,坑要一路填。
我的环境:
Windows 10 64-bit
MySQL Community Server 5.7.17 for Windows (x86, 64-bit), ZIP Archive
(分割线,以上MySQL 5.7.17就算安装完毕了。)
最后手贱,搞个SQLAlchemy测试MySQL:
"""SQLAlchemy操作MySQL测试"""
from sqlalchemy import create_engine, Table, Column, Integer, MetaData
from sqlalchemy.dialects.mysql import CHAR
from sqlalchemy.sql import select
ENGINE = create_engine('mysql+pymysql://root:@127.0.0.1:3306/test?charset=utf8mb4')
CONN = ENGINE.connect()
USERINFO = Table('userinfo',
MetaData(),
Column('id', Integer, primary_key=True, autoincrement=True),
Column('name', CHAR(24, charset='utf8mb4')),
mysql_charset='utf8mb4')
USER = select([USERINFO])
RESULT = CONN.execute(USER)
for row in RESULT:
print(row.name)
RESULT.close()
CONN.close()
结果发现输出结果的同时有个报警:
Warning: (1366, "Incorrect string value: '\xD6\xD0\xB9\xFA\xB1\xEA...' for column 'VARIABLE_VALUE' at row 480")
这是怎么回事呢?要说各种字符集设置都检查n次,应该没啥问题了......
无数次思考、试验中,发现了啥?发现了啥?发现只要show variables like '%charac%';一下,就会出来一个告警!
再来看看这个这个Warning:
不正是它吗?MySQL的Bug莫不是?!OMG!
好吧!重回MySQL 5.6.35!
告警不见了!
接着重新建库、建表,测试程序:
这下OK了,最终还是兜了一圈回到了MySQL 5.6.35。
安静地写Python,没人吵,也不像前端撕来撕去的——岁月静好、Python静好。
最后赞一下Visual Studio Code:
来源:http://www.2gua.info/post/67
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
1行Go代码实现反向代理的示例
![](https://img.aspxhome.com/file/2023/6/134016_0s.png)
大大改善用户体验的10个小细节
LotusPhp笔记之:基于ObjectUtil组件的使用分析
python手写均值滤波
![](https://img.aspxhome.com/file/2023/7/109927_0s.jpg)
Python实现查找二叉搜索树第k大的节点功能示例
![](https://img.aspxhome.com/file/2023/4/101584_0s.png)
python同时遍历两个list用法说明
Pycharm安装第三方库时Non-zero exit code错误解决办法
![](https://img.aspxhome.com/file/2023/2/121732_0s.png)
PHP+MYSQL实现读写分离简单实战
60个vue常用工具类
python Django框架快速入门教程(后台管理)
![](https://img.aspxhome.com/file/2023/2/76102_0s.png)
SQL Server手工插入标识列的方法
Ubuntu下使用python读取doc和docx文档的内容方法
python使用openpyxl库读写Excel表格的方法(增删改查操作)
![](https://img.aspxhome.com/file/2023/3/135113_0s.png)
python网络编程学习笔记(五):socket的一些补充
JavaScript中创建原子的方法总结
软件与网站设计的区别
python中np是做什么的
django从请求到响应的过程深入讲解
![](https://img.aspxhome.com/file/2023/8/72868_0s.png)
Python搭建HTTP服务器和FTP服务器
![](https://img.aspxhome.com/file/2023/5/131405_0s.png)