发布于 2017-03-12 07:57:26 | 222 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Mysql教程,程序狗速度看过来!

Mysql关系型数据库管理系统

MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。


最近发现原来好端端的MySQL突然间不能用了,无奈只能重新下载了最新的MySQL 5.7.17 Community 压缩版 for Windows 64-bit。但在安装过程中遇到了一些意外的问题,通过查找相关资料也解决了,所以想着总结出来,方便需要的朋友们可以参考借鉴,下面来一起看看吧。

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

总结

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



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务