mysql5.7通過文件zip方式安裝-九五小龐
為什麼通過zip的方式進行安裝
電腦上已安裝過mysql資料庫,想要再安裝一個。
1.下載mysql安裝包
直接找到mysql官網,在官網上下載zip安裝包。
//downloads.mysql.com/archives/community/
解壓完成後是這個樣子的(注意:解壓完的文件放到一個合適的地方,不要亂放)

2.在mysql-5.7.38-winx64安裝包中創建my.ini文件,創建data文件夾
[mysql] # 設置mysql客戶端默認字符集 default-character-set=utf8 [mysqld] #skip-grant-tables #設置3310埠 port = 3310 #關閉ONLY_FULL_GROUP_BY sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' # 設置mysql的安裝目錄 basedir=G:\Program Files\mysql-5.7.37-winx64 # 設置mysql資料庫的數據的存放目錄 datadir=G:\Program Files\mysql-5.7.37-winx64\data # 允許最大連接數 max_connections=200 # 服務端使用的字符集默認為8比特編碼的latin1字符集 character-set-server=utf8 # 創建新表時將使用的默認存儲引擎 default-storage-engine=INNODB

3.初始化mysql資料庫
以管理員身份打開命令行

切換到mysql安裝包的目錄下

執行 mysqld --initialize初始化, 然後發現data文件夾多了mysql的文件夾,也就意味著資料庫正常生成了


4.安裝服務
在mysql安裝包目錄下創建bat文件
@set mysql_service="G:\Program Files\mysql-5.7.37-winx64\bin\mysqld.exe" ::設置服務名 @set service_name="MYSQL57" ::安裝服務 %mysql_service% --install %service_name% --defaults-file="G:\Program Files\mysql-5.7.37-winx64\my.ini" pause

然後以管理員身份運行【安裝.bat】
安裝成功後,在電腦服務中會有一個MYSQL57服務(注意,如果服務沒有啟動,需要手動啟動一下服務)

5.修改root管理員密碼和許可權
修改my.ini文件,在[mysqld]節點中加上 skip-grant-tables參數
說明:skip-grant-tables參數的作用是,通過root用戶登錄資料庫,不需要輸入密碼,直接繞過密碼
改完配置後,記得需要重啟一下mysql57服務

連接上mysql資料庫,進行修改

G:\Program Files\mysql-5.7.37-winx64\bin>mysql -u root -p123456 -P 3310 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 8 Server version: 5.7.37 Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> flush privileges; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. mysql> SET PASSWORD = PASSWORD('123456'); Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> quit
修改root用戶的鏈接訪問許可權
G:\Program Files\mysql-5.7.37-winx64\bin>mysql -u root -p123456 -P 3310 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 9 Server version: 5.7.37 MySQL Community Server (GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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> select host, user from user; +-----------+---------------+ | host | user | +-----------+---------------+ | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+---------------+ 3 rows in set (0.00 sec) mysql> update user set host = '%' where user = 'root' and host='localhost'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select host, user from user; +-----------+---------------+ | host | user | +-----------+---------------+ | % | root | | localhost | mysql.session | | localhost | mysql.sys | +-----------+---------------+ 3 rows in set (0.00 sec) mysql> quit Bye

