使用 Helm 部署 MySQL、Redis 和 Golang 應用到 GKE
在上一篇文章中,我們成功使用 Helm 將 Nginx 部署到 GKE 上。這次,我們將更進一步,建立一個完整的三層架構應用:包含 MySQL 資料庫、Redis 快取服務,以及一個 Golang 後端應用。這個實作將更貼近實際的生產環境部署需求。
Continue Reading在上一篇文章中,我們成功使用 Helm 將 Nginx 部署到 GKE 上。這次,我們將更進一步,建立一個完整的三層架構應用:包含 MySQL 資料庫、Redis 快取服務,以及一個 Golang 後端應用。這個實作將更貼近實際的生產環境部署需求。
Continue ReadingIn MySQL, both LEFT JOIN
and FOREIGN KEY
serve different purposes and come with their own advantages and disadvantages.
The decision on which to use depends on your needs regarding flexibility, data integrity, and performance. Let’s break down each approach:
Continue ReadingWhen developing and optimizing MySQL databases, we often face the choice of using JSON fields or relational tables to manage data. This article will explore performance optimization methods for using JSON fields and relational tables in MySQL.
The advantages of JSON fields are compact data structure, reduced number of tables, and fewer join operations. However, parsing JSON fields incurs significant overhead, has limited index support, and may have lower query efficiency on large datasets.
The advantages of relational tables are clear relationship models, comprehensive index support, and efficient query optimization. However, it requires additional tables and join operations, which are typically efficient in relational databases.
In scenarios with millions and tens of millions of users, what are the advantages and disadvantages of these two approaches in terms of efficient querying and flexibility? Here are the considerations:
Scenario: A membership system that allows members to create organizations and share them with other members. In the struct of Organization, Permissions are used to record member IDs and roles. Under the organization, the ability to add courses and units while allowing member sharing at different levels needs to be maintained.
Continue ReadingDatabase slow query is a normalized case in operation situation. For example, if a new feature in production has a long data loading time, we can check this situation in the application log or database slow query.
Here, is how to set MySql slow query log.
Continue ReadingLaradock 在開發測試環境相當方便,但是若是對外暴露的情況下,則會由一定的安全設定需要處理。
這裡記錄過去在開設測試環境時,經常會使用到的設定方式:
Continue ReadingGraphQL Facebook 發佈於 2015,是一個 API 設計理念,主要以 “A query language for your API” 為出發點,並且有以下重點:
Redis pub/sub 連線一段時間出現訂閱失敗的處理方式
Redis subscribe 在訂閱一段時間可能失敗的情況有兩種, 1. 啟動沒多久就發生超時, 2. 長期才發生的連結斷開
在實際開發過程,兩種方式情境都可以同時設置,處理方式如下:
Continue Reading在 AWS 的 RDS Instance ,不同方案 CPU跟記憶體 都有差別,因此在預設時,都會針對主機規格幫你配置好可負載的人數,避免Instance崩壞,通常可以針對你的網站預估同時在線人數來推估適用的方案。
首先,先說明關於 RDS 針對使用者連線相關的配置參數。
Continue Reading在 Mac 直接透過 brew 安裝 MySQLdb,會出現錯誤提示:No matching distribution found for MySQLdb
解決方式:
brew install mysql-connector-c
pip install mysqlclient
這時會出現錯誤,請前往
cd /usr/local/Cellar/mysql-connector-c/6.1.11/bin/
cp mysql_config mysql_config.bak #備份
chmod u+w mysql_config
vi mysql_config
將 114 行的 ```libs="$libs
接著再執行安裝就成功了
CVT2HUGO: -l "``` 改為 ```libs="$libs -lmysqlclient -lssl -lcrypto"```
pip install mysqlclient
Continue Reading
MySql 主要的鎖可以分為幾種類型:
MyISAM與 InnoDB 都支援表級別與行級別鎖: X 鎖、 S 鎖
InnoDB的表級別鎖:IX鎖、IS 鎖
Continue ReadingMySQL 在操作資料庫的部署方式,其中一種是採取主從式讀寫分離的方式處理。
主(master) 主要用於寫入資料,從(Slave)主要進行讀取。在一般情況,資料庫採取這樣的方式與傳統單一部署方式並不會有太大的差異,但是在百萬等級的操作時,就可以明顯的分擔資料庫的處理程序。
原因在於資料庫在寫入相關操作速度會有 X鎖及 S 鎖的競爭關係,速度較慢。
Continue Reading正式網站使用 phpMyAdmin 建議一定要限制允許IP來源,避免目錄被訪問
這裡說明如何透過 Web Server 端來設置允許白名單
(建議!盡可能的不要使用 phpmyadmin)
Continue Reading在執行 phpunit 時,透過 sqlite 可以快速的執行測試,而避免掉需要建立關聯資料庫的流程
在 Laravel 設置方式如下
將資料庫連線設定為 sqlite,以及
DB_CONNECTION=sqlite
DB_HOST=localhost
DB_PORT=8000
DB_DATABASE=':memory:'
在資料庫存取的連結,需要將所有 http 開頭的連結改為 https
可以透過以下方法直接一次完成
UPDATE table_name
set url_columns = REPLACE(url_columns, 'http:', 'https:')
WHERE url_columns like 'http:%';
例如
pdf 資料表的 path 欄位需要行搜尋http並取代為https:
UPDATE pdfs
set path = REPLACE(path, 'http:', 'https:')
WHERE path like 'http:%';
如果有些欄位並非單純連結,例如,用 json 來存取網址
{"url":"http://xxx.xxx.xxx","url2":"http://yyy.yyy.yyy"... }
則直接將 WHERE 條件設定較為寬鬆即可
例如
UPDATE pdfs
set path = REPLACE(path, 'http:', 'https:')
WHERE path <> '';
紀錄如何查詢 MySQL 資料庫中,所有 database size
語法如下:
SELECT table_schema "DB Name",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;
Heroku 的 Add on 擴充功能,提供了資料庫的項目
在 MySQL 會選擇 “ClearDB MySQL :: Database” 這個 AddOn
這項服務是免費的,但是必須要先填寫信用卡資料,才能完成啟用
啟用後,就能在 local cli 登入 heroku
接著執行
heroku config | grep CLEARDB_DATABASE_URL
或者
Continue ReadingLaradock 在目前釋出的最新版本,會直接引用 MySQL latest version (MySQL 8.x)
由於 MySQL 8.x 版本的新密碼格式會引發 mysql container 一些錯誤,
The server requested authentication method unknown to the client...
因此,必須在安裝 laradock 調整 MySQL 版本
(若已經安裝且執行過 docker-compose up..,同樣可適用)
Continue ReadingMySQL 是一個廣泛被使用,開源的關聯式資料庫管理系統( relational database management system, RDBMS)
目前的MySQL執行效能不斷提升,可靠且易於使用,
因此經常被作為網路應用程式開發資料庫的首選.
其中包括 Facebook, Twitter, YouTube, Yahoo 等公司都有使用。
詳細說明可參考官網: www.mysql.com.
這裡將說明如何在 Docker 安裝即執行 MySQL 環境
Continue Reading