mac下navicat连接出现2003_-_Can‘t_connect_to_MySQL_server_on_‘127.0.0.1‘_(61__Connection_refused_)

2023-10-11 15:22:30 浏览数 (3)

简述

原来没这个情况,后来更新了Mac OS11后,会隔一段时间会出现.mac下navicat连接出现2003 - Can’t connect to MySQL server on ‘127.0.0.1’ (61 “Connection refused”)

前情提示

系统:Mac 12.1 mysql8 navicat 新建的库没这个问题,都是老的库,隔三差五出现。

一说

  • **最新版、完整版**请移步PUSDN  Powered By PUSDN - 平行宇宙软件开发者网www.pusdn.com ,转载请标明出处!
  • 部分截图、链接等因过期、更换域名、MD语法等可能不显示,可联系反馈(备注好博文地址),谢谢❤
  • 带有#号、删除线、不操作、不执行字样的为提示或者备份bash,实际不执行

出错信和截图

代码语言:javascript复制
2003 - Can't connect to MySQL server on '127.0.0.1' (61 "Connection refused")

首先可以看到3306是可以连接成功的,但是当打开某一个库时,出现报错 ![image.png](https://img-blog.csdnimg.cn/img_convert/14a85ceb2a995644815c9c681a4eb564.png#clientId=u03ef6514-14c2-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=657&id=u519e3763&margin=[object Object]&name=image.png&originHeight=1314&originWidth=1420&originalType=binary&ratio=1&rotation=0&showTitle=false&size=225486&status=done&style=none&taskId=u0446ed2c-d85f-4b2b-8b94-917ae440f16&title=&width=710) ![image.png](https://img-blog.csdnimg.cn/img_convert/ede8668d458cb22f8892fab4ba05d0ac.png#clientId=u03ef6514-14c2-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=265&id=ud7721265&margin=[object Object]&name=image.png&originHeight=530&originWidth=1742&originalType=binary&ratio=1&rotation=0&showTitle=false&size=245257&status=done&style=none&taskId=u646829fa-d0d6-4235-9a43-44ff3a1121c&title=&width=871)

经测试,命令行中可以使用命令来操作数据库,就是在客户端软件中不行。 ![image.png](https://img-blog.csdnimg.cn/img_convert/5bdc62f2ebcf031aa2b226d8c3d560c8.png#clientId=u03ef6514-14c2-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=371&id=qWE2z&margin=[object Object]&name=image.png&originHeight=742&originWidth=1170&originalType=binary&ratio=1&rotation=0&showTitle=false&size=97098&status=done&style=none&taskId=u87616dd3-a04e-4991-a718-fec8927b082&title=&width=585)

解决方式

配置文件增加

代码语言:javascript复制
[client]
socket=/usr/local/mysql/data/mysql.sock

然后,设置 - mysql - 重启 ![image.png](https://img-blog.csdnimg.cn/img_convert/7def8d2c8950f02287dd5812aab6f381.png#clientId=u03ef6514-14c2-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=562&id=ub8185393&margin=[object Object]&name=image.png&originHeight=1124&originWidth=1336&originalType=binary&ratio=1&rotation=0&showTitle=false&size=299406&status=done&style=none&taskId=ubce8cbca-6e0f-4a5c-9489-011acd7f1e2&title=&width=668)

代码语言:javascript复制
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[client]
socket=/usr/local/mysql/data/mysql.sock

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....

#服务端口号 默认3306
port = 3306
server_id = 1
# mysql安装根目录
basedir = /usr/local/mysql
# mysql数据文件所在位置
datadir = /usr/local/mysql/data
# pid
pid-file = /usr/local/mysql/data/mysql.pid
# 设置socke文件所在目录
socket = /usr/local/mysql/data/mysql.sock

# 跳过密码登录
# skip-grant-tables

# 数据库默认字符集,主流字符集支持一些特殊表情符号(特殊表情符占用4个字节)
# character-set-server = utf8mb4
 
# 数据库字符集对应一些排序等规则,注意要和character-set-server对应
# collation-server = utf8mb4_general_ci
 
# 设置client连接mysql时的字符集,防止乱码
# init_connect='SET NAMES utf8mb4'
 
# 是否对sql语句大小写敏感,1表示不敏感,8.0需要在初始化时候设置
# lower_case_table_names = 1

# 最大连接数
max_connections = 1000

#最大错误连接数
max_connect_errors = 1200


# wait_timeout = 1814400
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 


# 二进制日志目录
log_bin = /usr/local/mysql/logs/mysql-bin
# 自动删除过期日志的天数
expire_logs_days = 10
# 限制单个文件大小
max_binlog_size = 100M

# 查询日志
general_log = 1
# 查询日志文件位置
general_log_file = /usr/local/mysql/logs/query.log

# 数据库错误日志文件
log_error = /usr/local/mysql/logs/error.log


# sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

0 人点赞