Windows下安裝MySQL 5.7.17壓縮版中遇到的坑
首先下載最新的MySQL 5.7.17 Community 壓縮版 for Windows 64-bit:
官方下載地址:http://dev.mysql.com/downloads/mysql/
然后解壓到安裝目錄(如C:\Prog\MySQL\)。接下來(lái)復(fù)制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——“管理員身份”這很重要,進(jìn)入安裝目錄安裝MySQL服務(wù):
C:\Prog\MySQL\bin>mysqld install Service successfully installed.
然后啟動(dòng)MySQL服務(wù):
net start mysql
剛開始以為就這么簡(jiǎn)單,可是幺蛾子的卻報(bào)錯(cuò)了:
如果是通過(guò)Windows系統(tǒng)的“服務(wù)”啟動(dòng),則提示:
問(wèn)題出得實(shí)在是心塞不已,查了許久,原來(lái)是:
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”.
具體可參考這兩個(gè)鏈接:
2.3.5.4 Initializing the Data Directory
2.10.1.1 Initializing the Data Directory Manually Using mysqld
原因找到了,那我們來(lái)手動(dòng)Initialize Data Directory一下?。?/p>
mysqld --defaults-file=C:\Prog\MySQL\my.ini --initialize-insecure
然后依次:
net start mysql mysql -u root -p
熟悉的mysql>應(yīng)該就出來(lái)了。
希望對(duì)遇到類似坑的人有所幫助,究其原因就是5.7.7及以后的壓縮包版本,更改為需要手動(dòng)Initialize Data Directory了。
技無(wú)一招鮮,坑要一路填。
我的環(huán)境:
- Windows 10 64-bit
- MySQL Community Server 5.7.17 for Windows (x86, 64-bit), ZIP Archive
(分割線,以上MySQL 5.7.17就算安裝完畢了。)
最后手賤,搞個(gè)SQLAlchemy測(cè)試MySQL:
"""SQLAlchemy操作MySQL測(cè)試""" 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()
結(jié)果發(fā)現(xiàn)輸出結(jié)果的同時(shí)有個(gè)報(bào)警:
Warning: (1366, "Incorrect string value: '\xD6\xD0\xB9\xFA\xB1\xEA...' for column 'VARIABLE_VALUE' at row 480")
這是怎么回事呢?要說(shuō)各種字符集設(shè)置都檢查n次,應(yīng)該沒(méi)啥問(wèn)題了......
無(wú)數(shù)次思考、試驗(yàn)中,發(fā)現(xiàn)了啥?發(fā)現(xiàn)了啥?發(fā)現(xiàn)只要show variables like '%charac%';一下,就會(huì)出來(lái)一個(gè)告警!
再來(lái)看看這個(gè)這個(gè)Warning:
不正是它嗎?MySQL的Bug莫不是?!OMG!
好吧!重回MySQL 5.6.35!
告警不見了!
接著重新建庫(kù)、建表,測(cè)試程序:
這下OK了,最終還是兜了一圈回到了MySQL 5.6.35。
安靜地寫Python,沒(méi)人吵,也不像前端撕來(lái)撕去的——?dú)q月靜好、Python靜好。
最后贊一下Visual Studio Code:
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望自己的一些經(jīng)驗(yàn)?zāi)軒偷酵瑯佑龅竭@些問(wèn)題的朋友們,如果有疑問(wèn)大家也可以留言交流。
相關(guān)文章
mysql中l(wèi)ower_case_table_names=1參數(shù)的作用
lower_case_table_names是MySQL數(shù)據(jù)庫(kù)中的一個(gè)系統(tǒng)變量,本文主要介紹了mysql中l(wèi)ower_case_table_names=1參數(shù)的作用,具有一定的參考價(jià)值,感興趣的可以了解一下2024-08-08MySQL觸發(fā)器 Update觸發(fā)Insert失敗
這篇文章主要介紹了MySQL觸發(fā)器 Update觸發(fā)Insert失敗 的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07淺析CentOS6.8安裝MySQL8.0.18的教程(RPM方式)
這篇文章主要介紹了CentOS6.8安裝MySQL8.0.18(RPM方式)的詳細(xì)教程,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-1130個(gè)mysql千萬(wàn)級(jí)大數(shù)據(jù)SQL查詢優(yōu)化技巧詳解
本文總結(jié)了30個(gè)mysql千萬(wàn)級(jí)大數(shù)據(jù)SQL查詢優(yōu)化技巧,特別適合大數(shù)據(jù)里的MYSQL使用2018-03-03MySQL INSERT INTO SELECT時(shí)自增Id不連續(xù)問(wèn)題及解決
這篇文章主要介紹了INSERT INTO SELECT時(shí)自增Id不連續(xù)問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12