1. 下載mysql壓縮包mysql-5.7.17-winx64.zip
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.17-winx64.zip
2. 解壓文件,解壓後mysql根目錄爲:D:\mysql\mysql-5.7.17-winx64
3. 建立my-default.ini的副本爲my.ini
4. 系統環境變量path中加入D:\mysql\mysql-5.7.17-winx64\bin
5. 命令行運行:
mysqld --initialize(初始化數據庫)
mysqld -install(註冊windows服務默認名爲MySQL)
6. (有可能初始化時已經自動完成了)打開註冊表regedit,路徑爲HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MySQL,找到字符串ImagePath,將值更改成"D:\mysql\mysql-5.7.17-winx64\bin\mysqld" MySQL
7. 啓動服務(在services.msc中,或命令行net start mysql)
8. 修改my.ini,在[mysqld]段中加入一行skip-grant-tables
9. 重啓mysql服務(命令行net stop mysql,net start mysql)
10. 命令行mysql -u root可直接登陸
11. 設置root密碼爲root
update mysql.user set authentication_string=password('root') where user='root' and host='localhost';
flush privileges;
quit
12. 修改my.ini將skip-grant-tables用#號註釋
13. 再次重啓mysql服務
14. mysql -u root -proot鏈接mysql
15. 設置root可遠程鏈接
set password=password('root');
alter user 'root'@'localhost' password expier never;
flush privileges;
(若是出錯,這裏能夠退出從新鏈接)
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;
16. 完畢!mysql