Mac?Homebrew安裝的MySQL無法遠(yuǎn)程登錄的解決
對(duì)于Mac上Homebrew安裝的MySQL,默認(rèn)情況下只能使用本地登錄。
而使用其它主機(jī)遠(yuǎn)程登錄Mac上的MySQL則會(huì)被拒絕訪問。
下面修改MySQL的相關(guān)配置并使其能被遠(yuǎn)程主機(jī)訪問。
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
對(duì)于Homebrew安裝的MySQL,默認(rèn)的配置文件路徑是/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重啟失敗,有以下兩種解決方案:
進(jìn)入/usr/local/Cellar/mysql/<version>/bin目錄下,使用mysql.server restart命令重啟MySQL。注意"version"是你Mac上安裝MySQL的版本號(hào),請(qǐng)根據(jù)實(shí)際安裝版本號(hào)來替換
可以選擇重啟Mac來達(dá)到重啟MySQL服務(wù)的目的。重啟Mac后,如果沒有設(shè)置MySQL服務(wù)自啟動(dòng),需要手動(dòng)拉起MySQL服務(wù):mysql.server start
驗(yàn)證
$ 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>
遠(yuǎn)程登錄成功。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Mysql查詢時(shí)間區(qū)間日期列表實(shí)例代碼
最近常用到mysql的日期范圍搜索,下面這篇文章主要給大家介紹了關(guān)于Mysql查詢時(shí)間區(qū)間日期列表的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-04-04