MySQL 5.7.22 免安裝配置
阿新 • • 發佈:2018-07-14
before 修改配置 location state input tail article tex sun
轉自https://blog.csdn.net/hellboy0621/article/details/80458892
1、官網下載對應版本,下載地址為https://dev.mysql.com/downloads/mysql/5.7.html#downloads,我下載的文件為“mysql-5.7.22-winx64.zip”;
2、考慮到數據庫容量會增加,建議解壓縮到可用容量較大的盤符,我解壓縮到D盤;
3、進入解壓縮目錄,新建my.ini文件,內容如下:
- [mysqld]
- # set basedir to your installation path
-
basedir=D:/mysql-5.7.22-winx64
- # set datadir to the location of your data directory
- datadir=D:/mysql-5.7.22-winx64/data
4、使用cmd進入解壓縮目錄下的bin/目錄下
- # 安裝mysql服務,安裝完成後,可在右鍵“計算機”-“管理”-“服務”中看到,默認服務名為“MySQL”,也可以在install後面指定服務名稱
- D:\mysql-5.7.22-winx64\bin>mysqld install
- Service successfully installed.
-
# 初始化data目錄
- D:\mysql-5.7.22-winx64\bin>mysqld.exe --initialize
初始化後會在datadir路徑下生成一個*.err的文件,打開如下:
- 2018-05-27T04:49:08.182952Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
-
2018-05-27T04:49:11.016957Z 0 [Warning] InnoDB: New log files created, LSN=45790
- 2018-05-27T04:49:11.546958Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
- 2018-05-27T04:49:11.676958Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 4c70979b-6169-11e8-9db4-00ff13a6d817.
- 2018-05-27T04:49:11.676958Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
- 2018-05-27T04:49:11.696958Z 1 [Note] A temporary password is generated for root@localhost: q&10*I#<fi-w
最後一行“A temporary password is generated for root@localhost: q&10*I#<fi-w”冒號後面的就是臨時密碼;
- # 啟動MySQL服務
- D:\mysql-5.7.22-winx64\bin>net start mysql
- MySQL 服務正在啟動 .
- MySQL 服務已經啟動成功。
5、修改密碼
後面有兩種方式可以修改密碼,一種是使用剛才生成的臨時密碼登錄修改,另一種是修改配置文件跳過密碼登錄然後修改密碼;
5.1 通過臨時密碼登錄
- E:\mysql-5.7.22-winx64\bin>mysql -u root -p
- Enter password: ************
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 4
- Server version: 5.7.22
- Copyright (c) 2000, 2018, 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> show global variables like ‘port‘;
- ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
- mysql> ALTER user ‘root‘@‘localhost‘ identified by ‘Jiubugaosuni_01‘;
- Query OK, 0 rows affected (0.00 sec)
- mysql> SHOW GLOBAL VARIABLES LIKE ‘port‘;
- +---------------+-------+
- | Variable_name | Value |
- +---------------+-------+
- | port | 3306 |
- +---------------+-------+
- 1 row in set, 1 warning (0.01 sec)
5.2 跳過密碼登錄
5.2.1 跳過密碼登錄MySQL
- # 停止MySQL服務
- D:\mysql-5.7.22-winx64\bin>net stop mysql
- MySQL 服務正在停止.
- MySQL 服務已成功停止。
- # 卸載MySQL服務
- D:\mysql-5.7.22-winx64\bin>mysqld remove
- Service successfully removed.
- # 編輯my.ini配置文件,在[mysqld]下添加skip-grant-tables
- [mysqld]
- # set basedir to your installation path
- basedir=D:/mysql-5.7.22-winx64
- # set datadir to the location of your data directory
- datadir=D:/mysql-5.7.22-winx64/data
- skip-grant-tables
- # 安裝MySQL服務
- D:\mysql-5.7.22-winx64\bin>mysqld install
- Service successfully installed.
- # 啟動MySQL服務
- D:\mysql-5.7.22-winx64\bin>net start mysql
- MySQL 服務正在啟動 .
- MySQL 服務已經啟動成功。
5.2.2 無密碼登錄
- D:\mysql-5.7.22-winx64\bin>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.22 MySQL Community Server (GPL)
- Copyright (c) 2000, 2018, 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> ALTER user ‘root‘@‘localhost‘ identified by ‘Jiubugaosuni_01‘;
- ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this
- statement
- # 而應該使用如下命令,設置臨時密碼
- mysql> use mysql;
- Database changed
- mysql> UPDATE user SET authentication_string = password("Jiubugaosuni_01") WHERE user = "root";
- Query OK, 1 row affected, 1 warning (0.07 sec)
- Rows matched: 1 Changed: 1 Warnings: 1
- mysql> FLUSH PRIVILEGES;
- Query OK, 0 rows affected (0.00 sec)
- mysql> QUIT;
- Bye
5.2.3 恢復密碼登錄
- # 停止MySQL服務
- D:\mysql-5.7.22-winx64\bin>net stop mysql
- MySQL 服務正在停止.
- MySQL 服務已成功停止。
- # 卸載MySQL服務
- D:\mysql-5.7.22-winx64\bin>mysqld remove
- Service successfully removed.
- # 修改my.ini配置文件,註釋或者刪除skip-grant-tables
- [mysqld]
- # set basedir to your installation path
- basedir=D:/mysql-5.7.22-winx64
- # set datadir to the location of your data directory
- datadir=D:/mysql-5.7.22-winx64/data
- # skip-grant-tables
- # 安裝MySQL服務
- D:\mysql-5.7.22-winx64\bin>mysqld install
- Service successfully installed.
- # 啟動MySQL服務
- D:\mysql-5.7.22-winx64\bin>net start mysql
- MySQL 服務正在啟動 .
- MySQL 服務已經啟動成功。
5.2.4 登錄並查看端口號
- D:\mysql-5.7.22-winx64\bin>mysql -u root -p
- Enter password: ***************
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 3
- Server version: 5.7.22
- Copyright (c) 2000, 2018, 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> show global variables like ‘port‘;
- ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
- mysql> ALTER user ‘root‘@‘localhost‘ identified by ‘Jiubugaosuni_01‘;
- Query OK, 0 rows affected (0.00 sec)
- mysql> SHOW GLOBAL VARIABLES LIKE ‘port‘;
- +---------------+-------+
- | Variable_name | Value |
- +---------------+-------+
- | port | 3306 |
- +---------------+-------+
- 1 row in set, 1 warning (0.04 sec)
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | sys |
- +--------------------+
- 4 rows in set (0.00 sec)
- mysql>
6、配置遠程登錄
- # 賦予全部權限在所有數據庫和所有表上給root用戶在任何主機上使用Jiubugaosuni_01這個密碼登錄
- mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘Jiubugaosuni_01‘ WITH GRANT OPTION;
- Query OK, 0 rows affected, 1 warning (0.00 sec)
- mysql> FLUSH PRIVILEGES;
- Query OK, 0 rows affected (0.02 sec)
MySQL 5.7.22 免安裝配置