# 安裝 MySQL DB 兩種方式 ###### tags: `public` 以下以win10為例 ## ==1.XAMApp (較簡單)== https://www.apachefriends.org/zh_tw/download.html ![](https://i.imgur.com/Q3xZQVo.png) --- ## ==2.MySQL官網 (不推薦)== a.下載安裝管理器 https://dev.mysql.com/downloads/installer/ ![](https://i.imgur.com/WiAH03M.png) b.添加 MySQL Server和 Workbench 輸入密碼(要記好) ![](https://i.imgur.com/mNzeBXy.png) ![](https://i.imgur.com/54VK2Hd.png) c.完成安裝 ![](https://i.imgur.com/7FYLD5b.png) d.將b步驟2個執行起來 d-1 cmd輸入密碼,正確連線後的畫面 ![](https://i.imgur.com/NMynyYB.png) d-2 workbench 點設定,建立連線測試 ![](https://i.imgur.com/5fkftAc.png) ![](https://i.imgur.com/bcWTwqB.png) 完成後回到首頁會出現連線,點開 ![](https://i.imgur.com/kh6GnCz.png) ![](https://i.imgur.com/UGQaOi6.png) e.建表格和欄位 參考 https://ithelp.ithome.com.tw/articles/10215161 ## 其他 express js 後端語法 ![](https://i.imgur.com/AJU71rx.png) ```javascript= // "dependencies": { // "express": "^4.18.1", // "mysql": "^2.18.1" // } var express = require("express"); var app = express(); app.listen(3000); var mysql = require("mysql"); var conn = mysql.createConnection({ user: "root", password: "你的密碼", host: "localhost", port: 3306, database: "class" }) app.get('/', function (req, res) { conn.connect(function (error) { if (error) { res.send(JSON.stringify(error)); } else { res.send("OK 3"); } }); }) ``` ### Mysql 解决1251- Client does not support authentication protocol requested by server.. ##### 原因 mysql8版本太新,加密模式改變 https://blog.csdn.net/lovedingd/article/details/106728292 https://waylau.com/node.js-mysql-client-does-not-support-authentication-protocol/ ##### 解決 變更加密模式 select host,user,plugin,authentication_string from mysql.user; ![](https://i.imgur.com/qv2xECn.png) ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678'; ![](https://i.imgur.com/JlLJf38.png) ![](https://i.imgur.com/QVZABNu.png)