
[Cloud SQL]建立 MySQL 個體(Instance)並連線到資料庫
第一次使用的話,點擊使用免費抵免額建立執行個體
按鈕
點擊選擇「MySQL」
按鈕

輸入相關資訊





- 執行個體 ID: 小寫英文字母、數字或連字號,並以英文字母開頭
- 密碼: 自行輸入
- 資料庫版本: MySQL 8.0
- Cloud SQL 版本: Enterprise
- 預設設定: 開發
- 地區: asia-east1(台灣)
- 可用區可用性: 單一可用區
- 機器類型: 共用核心 1 vCPU,0.614 GB
- 儲存空間類型: SSD (建議選項)
- 儲存空間容量: 10 GB
- 勾選「啟用自動增加儲存空間」
- 加密: Google 代管的加密金鑰
- 執行個體的 IP 指派設定: 公開 IP
- 名稱: All
- 網路: 0.0.0.0/0
點擊建立執行個體
按鈕

建立成功!


點擊右上方的Cloud Shell
按鈕

終端機就會出現在最下方

登入資料庫
輸入以下指令
gcloud sql connect [INSTANCE NAME] --user=root
- INSTANCE NAME: 改成你的 instance id

輸入y
安裝API [sqladmin.googleapis.com]

輸入密碼


建立資料庫
CREATE DATABASE [DATABASE NAME];
※備註: 記得結尾要加;
,否則指令不會執行
指定資料庫
USE [DATABASE NAME];
建立 Table
CREATE TABLE member(member_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
account VARCHAR(256) NOT NULL UNIQUE KEY,
password VARCHAR(256) NOT NULL,
member_name VARCHAR(256) NOT NULL,
email VARCHAR(256) NOT NULL,
gender VARCHAR(256),
region VARCHAR(256),
address VARCHAR(256),
birth_date DATE,
create_date DATETIME);
插入一筆資料
INSERT INTO member (account, `password`, member_name, email) VALUES ('peggy', '123', '林曉彤', '[email protected]');
查詢資料
SELECT * FROM member;
