為何選擇MariaDB呢?
因為我之前學資料庫時使用MySQL,但是MySQL是昇陽公司產品,怕未來商用會被收錢。
MariaDB跟MySQL就跟親兄弟一樣…唯一不同的是開源免費。(窮窮的只能當個免費仔)
因為我很菜,使用上與MySQL並無感受到差異。
廢話不多說,讓我們開始吧!
需具備:Homebrew
1.查看homebrew上有哪些MariaDB版本:
brew search mariadb
2.安裝:
brew instal mariadb@10.3
3.添加環境變數(可利用終端機使用:mariadb_config):
echo 'export PATH="/usr/local/opt/mariadb@10.3/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/usr/local/opt/mariadb@10.3/lib"
export CPPFLAGS="-I/usr/local/opt/mariadb@10.3/include"
source ~/.zshrc
4.啟動:
brew services restart mariadb@10.3
5.安裝資料庫管理介面(sequel pro):
brew instal sequel-pro
6.初始化資料庫:
sudo mysql_secure_installation
Password:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] Y
... Success!
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? [Y/n] Y
... Success!
By default, MariaDB 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? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
7.利用資料庫管理介面連接資料庫:
Host:127.0.0.1
帳號:root
密碼:初始化資料庫設定的密碼
Port:3306左下角有一個+號可以新增一組你的連接設定,填寫完後如圖。

中間下方有一個儲存按鈕,可以將你的設定儲存,下次就不用輸入。
其他留空點擊連線(connect)。
(如果碰到連線問題,請檢查電腦是否有執行mariadb,再來檢查port是否有被使用,防火牆是否開啟是否有阻擋,重開機試試。)
(查Port 3306 : sudo lsof -i :3306)
8.添加用戶:
右上角有Users點擊進入可看到目前用戶,點擊右下角+(Add User),輸入新用戶名與密碼,進入Global Privlleges點選Check All,點擊Applay即可建立一個「最高權限用戶」。
9.將root與anonymous刪除,避免不認識的人亂連線。(本機使用不做此操作沒問題)
10.使用你新建立的用戶操作資料庫,別忘了儲存新的連接設定。
恭喜你!完成資料庫設定。