简述
原来没这个情况,后来更新了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,实际不执行
出错信和截图
2003 - Can't connect to MySQL server on '127.0.0.1' (61 "Connection refused")
首先可以看到3306是可以连接成功的,但是当打开某一个库时,出现报错  
经测试,命令行中可以使用命令来操作数据库,就是在客户端软件中不行。 
解决方式
配置文件增加
[client]
socket=/usr/local/mysql/data/mysql.sock
然后,设置 - mysql - 重启 
# 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 = 1mysql安装根目录
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 = 1200wait_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