MYSQL設定Root帳號密碼與初始權限(Ubuntu 20.04)

分享
MYSQL設定Root帳號密碼與初始權限(Ubuntu 20.04)

Ubuntu 安裝完Mysql的時候預設是沒有root密碼以及相關設定的

這時候就需要先用mysql_secure_installation這個指令來對本機的MySQL進行初始化設定

輸入指令

root@zabbix-server:/home/albertyu# mysql_secure_installation

是否為Root用戶設定密碼並且選擇難度 基本上都是輸入Y

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

選擇密碼難度,這邊基本上都建議是最高強度,輸入2

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

輸入密碼

Please set the password for root here.

New password: 

Re-enter new password: 

系統判斷密碼強度並且確認是否使用該密碼最強為100,如果強度到80分以上就輸入Y

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

預設安裝好了之後會有匿名用戶是否刪除,建議刪除所以輸入Y

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.

是否禁止遠端登入,如果禁止就只能本機登入,無特殊用途建議輸入Y,如果有外部連入需求任意鍵跳過

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 

 ... skipping.

是否刪除測試資料庫,建議輸入Y把多餘不需要的都刪除

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

設定最後一個步驟重新載入權限表,輸入Y 重新載入

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done! 

設定完成!

Read more

雲端架構延遲問題:為什麼AP與DB不能放太遠?

雲端與地端的架構差異認知不足導致的效能陷阱 前言 許多企業在上雲初期,經常基於成本考量或錯誤認知,將應用程式伺服器(AP)與資料庫(DB)部署在不同區域。這種做法在地端環境中影響較小,但在雲端環境中卻會造成嚴重的效能問題。本文透過台北-東京的實際案例,說明距離對雲端架構的致命影響。 核心問題: * 地端思維:同個機房內不同區域延遲可忽略 * 雲端現實:跨區域延遲可達數十毫秒 * 結果:連線建立時間從毫秒級暴增到秒級 1. 地端 vs 雲端的延遲差異 1.1 地端環境的延遲特性 傳統地端機房: 同機房不同機櫃:RTT < 1ms 同城市不同機房:RTT < 5ms 同國家不同城市:RTT < 20ms 地端架構師的經驗: * AP和DB分別放在不同機櫃:幾乎無延遲影響 * 災備機房放在不同城市:RTT約10-15ms,可接受 * 習慣性認為「網路延遲不是問題」

By Albert Yu
常用指令-Docker

常用指令-Docker

這篇整理 Docker 的常用指令與實務心得:從安裝、映像檔與容器的日常操作、資料保存與網路,到 Dockerfile 的寫法、Docker Compose、清理空間、推送到 Registry,以及最常遇到的問題怎麼查。指令以 Docker Engine 28 與 Docker Compose v2 為準(Compose 已經是 docker compose 子指令,不再是舊的 docker-compose)。 這篇不是官方文件的翻譯,而是我自己在家用伺服器、公司專案、CI/CD 流水線裡反覆用到的東西:哪些參數幾乎每次都要加、哪些指令看起來無害其實會刪資料、輸出要怎麼讀、出問題時先查哪裡。文中的 Dockerfile 與 compose 範例,大部分都實際在 Docker 28

By Albert Yu
常用指令-MAC

常用指令-MAC

這篇整理我在 Mac 上最常用的終端機指令:Homebrew 套件管理、系統資訊與更新、網路診斷、檔案與 Finder、磁碟與備份、電源與排程、效能與日誌、SSH 與鑰匙圈、隱私權與安全性,以及一些很實用但不常被提到的 macOS 專屬指令。內容以 Apple 晶片(M 系列)的 Mac、近年的 macOS 版本為準,Intel Mac 大多也適用,差異的地方會特別標註。文中的指令我都在自己的 Mac(Apple 晶片、macOS 27、zsh、Homebrew 7)上確認過指令與參數存在;少數因為需要管理員權限、會改動系統、或本機沒有安裝而無法實際驗證的部分,會在旁邊註明「本機未驗證」。 這篇文章很長,建議把它當成工具書:先看目錄式的章節標題,

By Albert Yu
常用指令-ubuntu

常用指令-ubuntu

這篇是我平常維運 Ubuntu 主機時最常用的指令整理,從系統更新、套件管理、服務管理、磁碟與網路,到憑證、資料庫、效能分析、排程、SSH、安全加固與疑難排解,盡量把「指令本身」和「什麼時候用、輸出怎麼讀、要注意什麼」放在一起。內容以 Ubuntu 24.04 LTS 為準,大部分指令在 22.04 也一樣能用;遇到版本差異的地方會另外註明。 這篇很長,建議當成工具書使用:先看目錄找到需要的章節,或直接跳到文末的「常見情境 SOP」與「速查表」。文中的指令、參數與設定檔範例,都在乾淨的 Ubuntu 24.04 環境裡實際跑過或用工具檢查過語法;少數需要實體硬體或完整 systemd 才能驗證的部分,我會在旁邊說明。

By Albert Yu