iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 22
0
自我挑戰組

資訊技術解戈迪安繩結系列 第 21

IT|資料庫|MySQL 安裝於 Mac OS

安裝 MySQL


[開始下載]

MySQL官網下載頁面:https://dev.mysql.com/downloads/mysql/
https://ithelp.ithome.com.tw/upload/images/20171229/20107621zH8bCqpvNz.png

[安裝]

在此選擇的是最後一個 dmg 格式的安裝檔,下載後直接安裝製可

Mac OS 安装 MySQL 需要注意事項


[關於 my.cnf 路徑]

透過以下指令查詢 my.inf 路徑

mysql --help | grep 'Default options' -A 1

Kevins-MacBook-Pro:etc Kevin$ mysql --help | grep 'Default options' -A 1
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf /usr/local/mysql/my.cnf ~/.my.cnf

Mac MySQL 軟體安裝在此
/usr/local/mysql-5.7.17-macos10.12-x86_64

將 my-default-cnf 檔案拷貝到 /etc 目錄
sudo cp /usr/local/mysql-5.7.17-macos10.12-x86_64/support-files/my-default.cnf /etc/my.cnf

[修改使用者密碼]

方法一:使用有權限或要修改的使用者本身登入mysql

# mysql -u root -p
mysql> SET PASSWORD FOR ‘username'@'localhost' = PASSWORD('password');
mysql> flush privileges;

方法二:使用有權限的使用者登入mysql

# mysql -u 登入使用者 -p
mysql> use mysql;
mysql> UPDATE user SET Password=PASSWORD("密碼") WHERE User='目標使用者';
mysql> flush privileges;

[忘記 root 密碼怎麼辦?]

如果忘記 root 密碼可以用以下方式重設

# /etc/init.d/mysql stop
# mysqld_safe --skip-grant-tables &

用上面方式啟動 mySQL 後可以不用輸入密碼直接連入

# mysql -u root

接者使用修改使用者密碼修改 root 密碼
mysql> use mysql;
mysql> UPDATE user SET Password=PASSWORD("password") WHERE User='root';
mysql> flush privileges;
mysql> quit

後重新啟動mysql

# /etc/init.d/mysql stop
# /etc/init.d/mysql start

中文化


顯示系統預設編碼設定
show variables like 'character%’;

設定步驟:

1.修改資料庫編碼方式:alter database test (資料庫名稱) character set utf8;
3、創建資料庫時指定資料庫的編碼方式:createdatabase test(資料庫名稱) character set utf8;
4、執行查看編碼方式的命令後,出現如圖所示信息。
5、配置 my.inf

https://ithelp.ithome.com.tw/upload/images/20171229/20107621cpBeoB4tOu.png

配置 my.inf
https://ithelp.ithome.com.tw/upload/images/20171229/20107621HRlh7gNHmW.png

大功告成!


上一篇
IT|軟體|測試|JMeter 自動生成測試報告
下一篇
IT|資料庫|PostgreSQL 安裝於 Mac OS、Ubuntu Linux
系列文
資訊技術解戈迪安繩結29
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
zhijiun
iT邦新手 4 級 ‧ 2022-11-20 14:41:47

請問為什麼我的mysql 一直出現這些資訊

Cannot Connect to Database Server

Your connection attempt failed for user 'root' from your host to server at 127.0.0.1:3306:Can't connect to mysql server on '127.0.0.1'(10061)

Please:

Check that mysql is running on server 127.0.0.1
Check that mysql is running on port 3306 (note: 3306 is the default, but this can be changed)
Check the root has rights to connect to 127.0.0.1 from your address (mysql rights define what clients can connect to the server and from which machines)
Make sure you are both providing a password if needed and using the correct password for 127.0.0.1 connecting from the host address you're connecting from

您好, 請先確認下面兩點,一般來說不脫這兩個問題
1 首先確認資料庫是否已經啟動
2 如果資料庫已經啟動,則密碼是否正確

zhijiun iT邦新手 4 級 ‧ 2022-11-21 10:37:20 檢舉

(已解決)
您好,這兩點都確認沒有錯誤
後來我把locolhost更改成127.0.0.1後才順利進入sql
謝謝您的回答

我要留言

立即登入留言