1.下載mysql5.7.13-windows版本
(1)mysql5.7.13-win64版本百度雲下載鏈接分享地址:鏈接:http://pan.baidu.com/s/1slMl4Ah 密碼:w60l
(2)mysql5.7.13-win32版本百度雲下載鏈接分享地址:鏈接:http://pan.baidu.com/s/1c2kcwFI 密碼:qk3n
2.解壓下載的mysql文件到自己電腦的指定路徑
在這里我解壓的路徑如下圖一:
圖一:我的mysql下載文件解壓路徑
3.配置mysql環境變量
(1)右鍵單擊我的電腦->屬性->高級系統設置(高級)->環境變量
點擊系統變量下的新建按鈕
輸入變量名:MYSQL_HOME
輸入變量值:F:\mysql
#即為mysql的自定義解壓目錄,具體如下圖二所示:
圖二:為mysql配置環境變量
(2)選擇系統變量中的Path
點擊編輯按鈕
在變量值中添加變量值:%MYSQL_HOME%\bin
注意是在原有變量值后面加上這個變量,用;隔開,不能刪除原來的變量值。具體如下圖三所示(PS:我目前計算機是WIN10系統,直接填寫%MYSQL_HOME%\bin即可)
圖三:mysql環境變量配置
4.在解壓后的mysql文件中添加一個my.ini文件
在F:\mysql路徑下,新建一個txt文本,然后修改擴展名,並命名為my.ini,在該文件中放入以下代碼(PS:經過下面的設置后,隨后建立數據庫時不會出現中文亂碼和中文無法插入的問題喲):
####################配置文件開始################### # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [client] default-character-set=utf8 [mysqld]
character-set-server=utf8 port=3306 basedir ="F:\mysql/" datadir ="F:\mysql/data/" tmpdir ="F:\mysql/data/" socket ="F:\mysql/data/mysql.sock" log-error="F:\mysql/data/mysql_error.log" #server_id = 2 #skip-locking max_connections=100 table_open_cache=256 query_cache_size=1M tmp_table_size=32M thread_cache_size=8 innodb_data_home_dir="F:\mysql/data/" innodb_flush_log_at_trx_commit =1 innodb_log_buffer_size=128M innodb_buffer_pool_size=128M innodb_log_file_size=10M innodb_thread_concurrency=16 innodb-autoextend-increment=1000 join_buffer_size = 128M sort_buffer_size = 32M read_rnd_buffer_size = 32M max_allowed_packet = 32M explicit_defaults_for_timestamp=true sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" #sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ####################配置文件結束###################
其中有關路徑的地址均填寫自己解壓mysql文件的實際存放地址
5.安裝mysql服務和登錄mysql
首先,以管理員身份打開cmd,接下來進行以下步驟:
(1)使用命令:mysqld --initialize-insecure,這個命令會生成無密碼的root用戶。而命令mysqld --initialize自動生成帶隨機密碼的root用戶。這里建議使用mysqld --initialize-insecure命令生成無密碼的root用戶。
提示:使用mysqld --initialize-insecure命令后結果:因為解壓后的mysql文件夾中沒有data文件夾,此處進行該命令后便會自動生成data文件夾
(2)緊接着,使用命令:mysqld --install ,安裝mysql服務(PS:mysql remove為卸載mysql服務)
(3)啟動mysql服務使用命令:net start mysql,開啟mysql服務
(4)使用命令:首先輸入mysql -u root -p,enter鍵進入到mysql,再次enter鍵進入(注意此處是不需要輸入密碼的)
如果在第一步中使用mysqld --initialize-insecure命令,安裝成功后,mysql的root賬戶密碼為空,現在可以按照如下所示,進行修改密碼:
操作步驟:
use mysql; update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root'; FLUSH PRIVILEGES;
具體演示結果:
修改密碼
密碼修改成功后,在cmd中重新登陸
C:\Users\Administrator>mysqld --initialize-insecure C:\Users\Administrator>mysqld --install Service successfully installed. C:\Users\Administrator>net start mysql MySQL 服務正在啟動 . MySQL 服務已經啟動成功。 C:\Users\Administrator>mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.13 MySQL Community Server (GPL) Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use mysql; Database changed mysql> update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec)
一款mysqlIDE下載推薦:鏈接:https://pan.baidu.com/s/152dLe2b9I6rmeJCmDIOeMg 密碼:168a
附:進行到步驟(3)時,無法啟動服務,可能會出現以下錯誤:
錯誤1:mysql服務啟動發現系統錯誤2
解決方法:
(1)
(2)
錯誤2:mysql服務啟動發現系統錯誤193
解決辦法:
也有可能是如下:
錯誤3:mysql服務啟動發現系統錯誤3
解決辦法:
錯誤4:mysql服務啟動 系統沒有報告任何錯誤
解決辦法:
錯誤5:mysql服務無法啟動,有可能是3306端口被占
解決辦法:
打開cmd,輸入netstat -ano,查看端口使用情況