Mac Homebrew安装的MySQL无法远程登录的解决

作者:TCatTime 时间:2024-01-14 12:12:56 

对于Mac上Homebrew安装的MySQL,默认情况下只能使用本地登录。

而使用其它主机远程登录Mac上的MySQL则会被拒绝访问。

下面修改MySQL的相关配置并使其能被远程主机访问。

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. 刷新权限

flush privileges;

4. 退出MySQL

exit

5. 修改MySQL服务绑定的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服务

brew services restart mysql

💡如果brew重启失败,有以下两种解决方案:

进入/usr/local/Cellar/mysql/<version>/bin目录下,使用mysql.server restart命令重启MySQL。注意"version"是你Mac上安装MySQL的版本号,请根据实际安装版本号来替换

可以选择重启Mac来达到重启MySQL服务的目的。重启Mac后,如果没有设置MySQL服务自启动,需要手动拉起MySQL服务: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>

远程登录成功。

来源:https://blog.csdn.net/TCatTime/article/details/112501966

标签:Mac,Homebrew,MySQL,远程登录
0
投稿

猜你喜欢

  • 微信小程序之多文件下载的简单封装示例

    2023-10-19 21:10:06
  • 微信小程序访问mysql数据库流程详解

    2024-01-23 10:34:43
  • mysql8.0.30安装配置最详细教程(windows 64位)

    2024-01-16 10:01:35
  • 10个有用的Python字符串函数小结

    2023-08-13 11:26:28
  • Jupyter Notebook打开任意文件夹操作

    2021-04-25 17:11:45
  • Python使用shutil操作文件、subprocess运行子程序

    2021-03-01 00:19:19
  • NumPy进行统计分析

    2023-09-21 00:16:15
  • python引用DLL文件的方法

    2021-01-17 03:35:19
  • Django项目使用ckeditor详解(不使用admin)

    2022-12-15 01:52:52
  • Python 6种基本变量操作技巧总结

    2023-04-03 21:50:04
  • MySQL中的 Binlog 深度解析及使用详情

    2024-01-19 04:15:48
  • SQL Server并发处理存在就更新解决方案探讨

    2024-01-17 16:54:06
  • 如何从0开始用node写一个自己的命令行程序

    2024-05-03 15:56:26
  • ASP(JScript)构建SQL语句“类”

    2008-04-30 07:12:00
  • CentOS7 LNMP+phpmyadmin环境搭建 第三篇phpmyadmin安装

    2023-10-17 03:23:18
  • Python开根号的几种方式详解

    2021-07-10 20:37:34
  • python使用插值法画出平滑曲线

    2021-07-14 03:59:02
  • DreamweaverMX2004的一句话技巧

    2009-05-22 18:23:00
  • 如何“看看”服务器上的那个文件还在不在?

    2009-11-02 20:17:00
  • 利用python为PostgreSQL的表自动添加分区

    2023-07-07 14:44:58
  • asp之家 网络编程 m.aspxhome.com