原码笔记

原码笔记

Windows下安装MySQL 5.7.17压缩版中遇到的坑

小诸哥 0

首先下载最新的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如下:

  1. [mysql]
  2. default-character-set=utf8mb4
  3.  
  4. [mysqld]
  5. basedir = C:\Prog\MySQL
  6. datadir = C:\Prog\MySQL\data
  7. port = 3306
  8. max_connections=200
  9. character-set-server=utf8mb4
  10. collation-server=utf8mb4_general_ci
  11. default-storage-engine=INNODB
  12. join_buffer_size = 128M
  13. sort_buffer_size = 2M
  14. read_rnd_buffer_size = 2M
  15. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

之后用“管理员身份”打开cmd——“管理员身份”这很重要,进入安装目录安装MySQL服务:

  1. C:\Prog\MySQL\bin>mysqld install
  2. Service successfully installed.

然后启动MySQL服务:

  1. 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一下啊:

  1. mysqld --defaults-file=C:\Prog\MySQL\my.ini --initialize-insecure

然后依次:

  1. net start mysql
  2. mysql -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:

  1. """SQLAlchemy操作MySQL测试"""
  2.  
  3. from sqlalchemy import create_engine, Table, Column, Integer, MetaData
  4. from sqlalchemy.dialects.mysql import CHAR
  5. from sqlalchemy.sql import select
  6.  
  7. ENGINE = create_engine('mysql+pymysql://root:@127.0.0.1:3306/test?charset=utf8mb4')
  8.  
  9. CONN = ENGINE.connect()
  10.  
  11. USERINFO = Table('userinfo',
  12.      MetaData(),
  13.      Column('id', Integer, primary_key=True, autoincrement=True),
  14.      Column('name', CHAR(24, charset='utf8mb4')),
  15.      mysql_charset='utf8mb4')
  16.  
  17. USER = select([USERINFO])
  18.  
  19. RESULT = CONN.execute(USER)
  20.  
  21. for row in RESULT:
  22.      print(row.name)
  23.  
  24. RESULT.close()
  25. 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:

总结

以上就是这篇文章的全部内容了,希望自己的一些经验能帮到同样遇到这些问题的朋友们,如果有疑问大家也可以留言交流。

标签: Windows 安装 MySQL 压缩