1.首先下載mysql安裝包
https://dev.mysql.com/downloads/mysql/
這個(gè)版本不要聽網(wǎng)上說的新建data文件夾和my.ini 或 my-default.ini 按我說的 本人親測(cè)
配置環(huán)境變量在Path下添加 D:\mysql-8.0.19-winx64\bin
以管理員身份運(yùn)行,在命令行輸入cd+mySQL的bin目錄的安裝路徑
C:\Windows\system32>cd C:\Program Files\MySQL\MySQL Server5.6\bin
2. MySQL的初始化及服務(wù)安裝
2.1 按“win”鍵打開開始菜單聪姿,在搜索框中輸入“cmd”末购,在搜索結(jié)果中選中“命令提示符”程序,右鍵選擇“以管理員身份運(yùn)行”
2.2 初始化
用管理員權(quán)限打開CMD或者Windows Powershell
使用命令:mysqld --initialize --console
使用CMD命令操作后如下:
C:\Windows\system32>D:\Python\mysql-8.0.12-winx64\bin\mysqld --initialize --console
2018-09-13T14:36:55.758742Z 0 [System] [MY-013169] [Server] D:\Python\mysql-8.0.12-winx64\bin\mysqld (mysqld 8.0.12) initializing of server in progress as process 3104
2018-09-13T14:37:12.072904Z 5 [Note] [MY-010454] [Server] A temporary *password is generated for root@localhost: `Gaz7FGbaTwe
2018-09-13T14:37:23.274980Z 0 [System] [MY-013170] [Server] D:\Python\mysql-8.0.12-winx64\bin\mysqld (mysqld 8.0.12) initializing of server has completed
記錄下密碼,這里的密碼是Gaz7FGbaTw*e曹货,密碼是隨機(jī)生成的每個(gè)人都不一樣顶籽,此處生成的密碼在后面修改密碼時(shí)要用银觅。
2.3 安裝mysql服務(wù)
使用命令: mysqld --install
C:\Windows\system32>D:\Python\mysql-8.0.12-winx64\bin\mysqld --install
Service successfully installed.
2.4 啟用服務(wù)
使用命令: net start mysql
C:\Windows\system32>D:\Python\mysql-8.0.12-winx64\bin>net start mysql
MySQL 服務(wù)正在啟動(dòng) ..
MySQL 服務(wù)已經(jīng)啟動(dòng)成功礼饱。
2.5 修改密碼
輸入命令登陸: mysql -u root -p
輸入剛才保存的密碼,如 Gaz7FGbaTw*e
使用命令: ALTER USER ‘root'@‘localhost' IDENTIFIED WITH mysql_native_password BY ‘新密碼';
注意密碼一定要6位數(shù)以上
比如我設(shè)置的密碼是123456
D:\Python\mysql-8.0.12-winx64\bin>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY '123456'
-> ;
Query OK, 0 rows affected (1.98 sec)
2.6 使用新密碼登陸
使用命令:mysql -u root -p
D:\Python\mysql-8.0.12-winx64\bin>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.12 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>
總結(jié)問題:2.4 執(zhí)行 net start mysql 命令啟動(dòng)服務(wù)時(shí) 一直出錯(cuò) 啟動(dòng)不了
我的錯(cuò)誤是開始進(jìn)入的文件夾位置不對(duì)究驴,所以需要去除服務(wù)從新進(jìn)入對(duì)的文件夾下載安裝啟動(dòng)
以管理員身份運(yùn)行镊绪,在命令行輸入cd+mySQL的bin目錄的安裝路徑
C:\Windows\system32>cd C:\Program Files\MySQL\mysql-8.0.19-winx64\bin
C:\Program Files\MySQL\mysql-8.0.19-winx64\bin>mysqld --remove
Service successfully removed.
C:\Program Files\MySQL\mysql-8.0.19-winx64\bin>mysqld --install
Service successfully installed.
C:\Program Files\MySQL\mysql-8.0.19-winx64\bin>net start mysql
MySQL 服務(wù)正在啟動(dòng) .
MySQL 服務(wù)已經(jīng)啟動(dòng)成功。