編碼的世界 / 優質文選 / 歷史

Windows 安裝 mysql 5.7.27


2021年10月22日
-   

 

1. 安裝軟件下載


百度雲盤:  https://pan.baidu.com/s/1Bob80HghfLtKJ2l8FEiB4Q  密碼:spvf
官網下載: https://dev.mysql.com/downloads/mysql/5.7.html#downloads

選擇自己的版本下載

 
選這裏跳過登錄

 

2. 將下載後的壓縮包解壓


如圖路徑: D:Toolsmysql-5.7.27-winx64

 

3. 創建配置文件  my.ini


創建一個空的文件 my.ini 內容如下 . 自行更改安裝目錄以及數據存放目錄.
 數據存放目錄需要自己手動創建 : D:Toolsmysql-5.7.27-winx64data 
[mysql]
# 設置mysql客戶端默認字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
skip-grant-tables
#設置3306端口
port = 3306
# 設置mysql的安裝目錄
basedir=D:Toolsmysql-5.7.27-winx64
# 設置mysql數據庫的數據的存放目錄
datadir=D:Toolsmysql-5.7.27-winx64data
# 允許最大連接數
max_connections=200
# 服務端使用的字符集默認為8比特編碼的latin1字符集
character-set-server=utf8
# 創建新表時將使用的默認存儲引擎
default-storage-engine=INNODB

 

4.配置環境變量



 
MYSQL_HOME
D:Toolsmysql-5.7.27-winx64
 

 
 
Path
%MYSQL_HOME%in;
 
 
 

 

5. 注冊 mysql 服務



 

6. 執行初始化 . mysqld initialize


 

 
7. 開啟 mysql 服務 

 

8.配置 MySQL root 賬戶


 
在“命令提示符”中,執行net stop mysql關閉 MySQL Server。
再執行mysqld skip-grant-tables開啟無密碼的 MySQL Server。

 
打開一個新的“命令提示符”,執行mysql -u root登陸 MySQL Server。
執行flush privileges;刷新權限。
執行grant all privileges on *.* to 'root'@'localhost' identified by '你想設置的密碼' with grant option;
執行flush privileges;刷新新的 root 用戶密碼。
執行exit退出 MySQL。

 
mysqld skip-grant-tables 命令窗口 按  contral+C  取消,
或者在任務管理器裏面 殺掉 mysqld.exe  

 
在“命令提示符”下執行net start mysql重新開啟MySQL Server,再次使用mysql -u root -p 你設置的密碼    即可安全登陸 MySQL。

 

9. 開啟遠程登錄


更改 mysql 數據庫中的user 表, 使得 name 為 root 的賬戶對應的 host 為'%'
D:Toolsmysql-5.7.27-winx64in>mysql -u root -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, 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>
mysql>
mysql>
mysql> show databases;
++
| Database |
++
| information_schema |
| mysql |
| performance_schema |
| sys |
++
4 rows in set (0.00 sec)
mysql>
mysql>
mysql>
mysql> use mysql
Database changed
mysql>
mysql>
mysql> select user, host from user ;
+-+-+
| user | host |
+-+-+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+-+-+
3 rows in set (0.00 sec)
mysql>
mysql>
mysql>
mysql> update user set host = '%' where user = 'root' ;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
mysql>
mysql>
mysql> select user, host from user ;
+-+-+
| user | host |
+-+-+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
+-+-+
3 rows in set (0.00 sec)
mysql>
mysql>
mysql>
mysql> exit
Bye

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

熱門文章