1. 程式人生 > >MySQL 5.7.22 免安裝配置

MySQL 5.7.22 免安裝配置

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文件,內容如下:

  1. [mysqld]
  2. # set basedir to your installation path
  3. basedir=D:/mysql-5.7.22-winx64
  4. # set datadir to the location of your data directory
  5. datadir=D:/mysql-5.7.22-winx64/data

4、使用cmd進入解壓縮目錄下的bin/目錄下

  1. # 安裝mysql服務,安裝完成後,可在右鍵“計算機”-“管理”-“服務”中看到,默認服務名為“MySQL”,也可以在install後面指定服務名稱
  2. D:\mysql-5.7.22-winx64\bin>mysqld install
  3. Service successfully installed.

技術分享圖片

  1. # 初始化data目錄
  2. D:\mysql-5.7.22-winx64\bin>mysqld.exe --initialize

初始化後會在datadir路徑下生成一個*.err的文件,打開如下:

  1. 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).
  2. 2018-05-27T04:49:11.016957Z 0 [Warning] InnoDB: New log files created, LSN=45790
  3. 2018-05-27T04:49:11.546958Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
  4. 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.
  5. 2018-05-27T04:49:11.676958Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
  6. 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”冒號後面的就是臨時密碼;

  1. # 啟動MySQL服務
  2. D:\mysql-5.7.22-winx64\bin>net start mysql
  3. MySQL 服務正在啟動 .
  4. MySQL 服務已經啟動成功。

5、修改密碼

後面有兩種方式可以修改密碼,一種是使用剛才生成的臨時密碼登錄修改,另一種是修改配置文件跳過密碼登錄然後修改密碼;

5.1 通過臨時密碼登錄

  1. # 使用臨時密碼登錄
  2. E:\mysql-5.7.22-winx64\bin>mysql -u root -p
  3. Enter password: ************
  4. Welcome to the MySQL monitor. Commands end with ; or \g.
  5. Your MySQL connection id is 4
  6. Server version: 5.7.22
  7. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
  12. # 查看端口號
  13. mysql> show global variables like ‘port‘;
  14. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  15. # 通過ALTER語句修改密碼
  16. mysql> ALTER user ‘root‘@‘localhost‘ identified by ‘Jiubugaosuni_01‘;
  17. Query OK, 0 rows affected (0.00 sec)
  18. mysql> SHOW GLOBAL VARIABLES LIKE ‘port‘;
  19. +---------------+-------+
  20. | Variable_name | Value |
  21. +---------------+-------+
  22. | port | 3306 |
  23. +---------------+-------+
  24. 1 row in set, 1 warning (0.01 sec)

5.2 跳過密碼登錄

5.2.1 跳過密碼登錄MySQL

  1. # 停止MySQL服務
  2. D:\mysql-5.7.22-winx64\bin>net stop mysql
  3. MySQL 服務正在停止.
  4. MySQL 服務已成功停止。
  5. # 卸載MySQL服務
  6. D:\mysql-5.7.22-winx64\bin>mysqld remove
  7. Service successfully removed.
  1. # 編輯my.ini配置文件,在[mysqld]下添加skip-grant-tables
  2. [mysqld]
  3. # set basedir to your installation path
  4. basedir=D:/mysql-5.7.22-winx64
  5. # set datadir to the location of your data directory
  6. datadir=D:/mysql-5.7.22-winx64/data
  7. skip-grant-tables
  1. # 安裝MySQL服務
  2. D:\mysql-5.7.22-winx64\bin>mysqld install
  3. Service successfully installed.
  4. # 啟動MySQL服務
  5. D:\mysql-5.7.22-winx64\bin>net start mysql
  6. MySQL 服務正在啟動 .
  7. MySQL 服務已經啟動成功。

5.2.2 無密碼登錄

  1. D:\mysql-5.7.22-winx64\bin>mysql -u root -p
  2. Enter password:(回車,無需輸入密碼)
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.7.22 MySQL Community Server (GPL)
  6. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
  11. mysql>
  1. # 在這裏不能使用ALTER語句,否則報錯
  2. mysql> ALTER user ‘root‘@‘localhost‘ identified by ‘Jiubugaosuni_01‘;
  3. ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this
  4. statement
  1. # 而應該使用如下命令,設置臨時密碼
  2. mysql> use mysql;
  3. Database changed
  4. mysql> UPDATE user SET authentication_string = password("Jiubugaosuni_01") WHERE user = "root";
  5. Query OK, 1 row affected, 1 warning (0.07 sec)
  6. Rows matched: 1 Changed: 1 Warnings: 1
  7. mysql> FLUSH PRIVILEGES;
  8. Query OK, 0 rows affected (0.00 sec)
  9. mysql> QUIT;
  10. Bye

5.2.3 恢復密碼登錄

  1. # 停止MySQL服務
  2. D:\mysql-5.7.22-winx64\bin>net stop mysql
  3. MySQL 服務正在停止.
  4. MySQL 服務已成功停止。
  5. # 卸載MySQL服務
  6. D:\mysql-5.7.22-winx64\bin>mysqld remove
  7. Service successfully removed.
  1. # 修改my.ini配置文件,註釋或者刪除skip-grant-tables
  2. [mysqld]
  3. # set basedir to your installation path
  4. basedir=D:/mysql-5.7.22-winx64
  5. # set datadir to the location of your data directory
  6. datadir=D:/mysql-5.7.22-winx64/data
  7. # skip-grant-tables
  1. # 安裝MySQL服務
  2. D:\mysql-5.7.22-winx64\bin>mysqld install
  3. Service successfully installed.
  4. # 啟動MySQL服務
  5. D:\mysql-5.7.22-winx64\bin>net start mysql
  6. MySQL 服務正在啟動 .
  7. MySQL 服務已經啟動成功。

5.2.4 登錄並查看端口號

  1. # 使用修改的臨時密碼登錄
  2. D:\mysql-5.7.22-winx64\bin>mysql -u root -p
  3. Enter password: ***************
  4. Welcome to the MySQL monitor. Commands end with ; or \g.
  5. Your MySQL connection id is 3
  6. Server version: 5.7.22
  7. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
  12. # 必須通過ALTER語句修改密碼才算正式修改密碼成功
  13. mysql> show global variables like ‘port‘;
  14. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  15. mysql> ALTER user ‘root‘@‘localhost‘ identified by ‘Jiubugaosuni_01‘;
  16. Query OK, 0 rows affected (0.00 sec)
  17. mysql> SHOW GLOBAL VARIABLES LIKE ‘port‘;
  18. +---------------+-------+
  19. | Variable_name | Value |
  20. +---------------+-------+
  21. | port | 3306 |
  22. +---------------+-------+
  23. 1 row in set, 1 warning (0.04 sec)
  24. mysql> show databases;
  25. +--------------------+
  26. | Database |
  27. +--------------------+
  28. | information_schema |
  29. | mysql |
  30. | performance_schema |
  31. | sys |
  32. +--------------------+
  33. 4 rows in set (0.00 sec)
  34. mysql>

6、配置遠程登錄

  1. # 賦予全部權限在所有數據庫和所有表上給root用戶在任何主機上使用Jiubugaosuni_01這個密碼登錄
  2. mysql> GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘%‘ IDENTIFIED BY ‘Jiubugaosuni_01‘ WITH GRANT OPTION;
  3. Query OK, 0 rows affected, 1 warning (0.00 sec)
  4. mysql> FLUSH PRIVILEGES;
  5. Query OK, 0 rows affected (0.02 sec)

MySQL 5.7.22 免安裝配置