MySQL Server 手動安裝

MySQL 有兩種安裝方式。一種是精靈,一種是 zip。

  1. 下載 zip 檔案
  2. 解壓縮 zip 檔案
  3. 設置環境變數
  4. 建立 my.ini
  5. 初始化
  6. 安裝服務
  7. 啟動服務
  8. 登入資料庫
  9. 修改密碼

下載 zip 檔案

https://dev.mysql.com/downloads/

因為不是 Installer,所以只選 Server

需要登入 Oracle 帳戶

解壓縮 zip 檔案

直接解壓縮即可

設置環境變數

方便後續操作,若未設置則要額外指定指令位置

cd C:\mysql\bin

建立 my.ini

[mysqld]
port=3306
basedir=C:\mysql
datadir=C:\mysql\data
max_connections=200
max_connect_errors=10
character-set-server=utf8
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
[mysql]
default-character-set=utf8
[client]
port=3306
default-character-set=utf8

my.ini 是初始化用到的配置檔
應放在 mysql 目錄下,初始化會自動讀取
若不是放在 mysql 目錄下,初始化時要額外指定 my.ini 的位置

初始化

請以系統管理員身分執行CMD,避免權限問題

mysqld –-initialize-insecure
mysqld --initialize-insecure --user=mysql
::mysqld --defaults-file=../my.ini --initialize-insecure

安裝服務

mysqld install

若已有服務必須刪除

mysqld remove

啟動服務

net start mysql
net stop mysql

登入資料庫

cd C:\mysql\bin
mysql -u root -p

因為是 insecure 所以無密碼,直接 Enter

修改密碼

方法一

ALTER user 'root'@'localhost' IDENTIFIED BY '12345'

方法二

mysqladmin -u root -p password
Enter
Enter password:
Confirm new password:

過時的方法

use mysql;

update user set authentication_string=password('1234') where user='root' and host='localhost';
-- update user set password=password('1234') where user='root' and host='localhost';
-- set password for root@localhost = password('1234');

flush privileges;