Skip to main content

[MySQL] MySQL 安裝

透過 brew 安裝 MySQL#

需要先安裝過 homebrew 和 brew services

$ brew install mysql
$ brew services start mysql
$ mysql.server start # 若不需要 mysql 在背景執行
# 設定 mysql 密碼
# 或者連進 SQL 之後輸入:
# ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password'
$ mysqladmin -u root password 'your_password'
# mysql -h hostname -u username -p database_name
# 登入 user name 為 root 的使用者
$ mysql -u root -p # 預設密碼 root
# 建立資料庫(database)
mysql> CREATE DATABASE forum;

完整移除 MySQL#

Remove MySQL completely

$ brew services stop mysql
# 清除所有和 MySQL 有關的程序
$ ps -ax | grep mysql
# 移除透過 homebrew 安裝的 mysql
$ brew remove mysql
$ brew cleanup
# 移除可能的檔案
$ sudo rm /usr/local/mysql
$ sudo rm -rf /usr/local/var/mysql
$ sudo rm -rf /usr/local/mysql*
$ sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
$ sudo rm -rf /Library/StartupItems/MySQLCOM
$ sudo rm -rf /Library/PreferencePanes/My*
# 移除先前 homebrew 在電腦登入時會自動啟動 mysql
$ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
# 移除之前 mysql 的 preference
$ rm -rf ~/Library/PreferencePanes/My*
$ sudo rm -rf /Library/Receipts/mysql*
$ sudo rm -rf /Library/Receipts/MySQL*
$ sudo rm -rf /private/var/db/receipts/*mysql*
# 重新開機
Last updated on