Mac?Homebrew安裝的MySQL無法遠程登錄的解決
對于Mac上Homebrew安裝的MySQL,默認情況下只能使用本地登錄。
而使用其它主機遠程登錄Mac上的MySQL則會被拒絕訪問。
下面修改MySQL的相關(guān)配置并使其能被遠程主機訪問。
1. 登錄MySQL
mysql -u root -p -D mysql
2. 修改user表中root用戶的Host值
update user set host='%' where user='root';
查看下修改情況:
mysql> select user,host from user; +------------------+-----------+ | user ? ? ? ? ? ? | host ? ? ?| +------------------+-----------+ | root ? ? ? ? ? ? | % ? ? ? ? | | mysql.infoschema | localhost | | mysql.session ? ?| localhost | | mysql.sys ? ? ? ?| localhost | +------------------+-----------+ 4 rows in set (0.00 sec)
3. 刷新權(quán)限
flush privileges;
4. 退出MySQL
exit
5. 修改MySQL服務(wù)綁定的IP
對于Homebrew安裝的MySQL,默認的配置文件路徑是/usr/local/etc/my.cnf:
# Default Homebrew MySQL server config [mysqld] # Only allow connections from localhost bind-address = 127.0.0.1 mysqlx-bind-address = 127.0.0.1
將bind-address值修改為0.0.0.0:
# Default Homebrew MySQL server config [mysqld] # Only allow connections from localhost bind-address = 0.0.0.0 mysqlx-bind-address = 127.0.0.1
6. 重啟MySQL服務(wù)
brew services restart mysql
??如果brew重啟失敗,有以下兩種解決方案:
進入/usr/local/Cellar/mysql/<version>/bin目錄下,使用mysql.server restart命令重啟MySQL。注意"version"是你Mac上安裝MySQL的版本號,請根據(jù)實際安裝版本號來替換
可以選擇重啟Mac來達到重啟MySQL服務(wù)的目的。重啟Mac后,如果沒有設(shè)置MySQL服務(wù)自啟動,需要手動拉起MySQL服務(wù):mysql.server start
驗證
$ mysql -u root -p -h 192.168.0.100 Enter password: Welcome to the MySQL monitor. ?Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.21 Homebrew ? Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. ? Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. ? Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. ? mysql>
遠程登錄成功。
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。