MySQL 8.0 创建 my.ini 配置文件并开始 Binlog 监听
使用管理员权限打开cmd(命令提示符)
Step1 win+R
Step2 输入 cmd
Step3 Ctrl+Shift+Enter
尝试找到my.ini配置文件路径
Step1 打开 MySQL
mysql -u 用户名 -p
-u 后面跟的是 MySQL 用户名(如 root)。
-p 表示需要输入密码。
输入命令后,按回车键,系统会提示你输入密码。输入密码后按回车即可登录。
Step2 尝试找到my.ini文件的路径
show variables like 'datadir';
但是该目录下根本就没有my.ini配置文件
新建my.ini文件
Step 1 在桌面新建一个txt文件
我的C:\Program Files\MySQL\MySQL Server 8.0下只能创建文件夹,所以要在别的地方创建空的my.ini文件
Step 2 修改txt文件为ini文件
通过重命名的方式将txt文件修改为int文件 “新建 文本文档.txt” -> “my.ini”
打开 my.ini,复制以下内容到 my.ini
# 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]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_bin
init_connect='SET NAMES utf8mb4'
# 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.
lc-messages-dir = C:\\Program Files\\MySQL\\MySQL Server 8.0\\share
basedir = C:\\Program Files\\MySQL\\MySQL Server 8.0
datadir = C:\\Program Files\\MySQL\\MySQL Server 8.0\\Data
port = 3306
# server_id = .....
# 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 = 16M
read_rnd_buffer_size = 16M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
log-bin=mysql-bin # 开启 binlog
binlog-format=ROW # 选择 ROW 模式
server_id=1 # 配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复
注:替换为你电脑的路径(如果没有Data文件夹,需要创建好)
Step 3 修改mysql的配置文件路径
打开cmd,进入命令行,输入(注:替换为你电脑的路径):
mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 8.0\my.ini"
重启 MySQL 服务
打开任务管理器
打开任务管理器,选择“服务”
重启 MySQL 服务
找到 MySQL,右键,选择“重新启动”
查看 Binlog 日志是否开启
执行 MySQL 执行命令查看 Binlog 日志是否开启。
show variables like 'log_%';
如果查询出的选型 log_bin 数据为 ON,Binlog 即为开启状态。输出如下:
参考文章
使用管理员权限打开cmd(命令提示符)的方法 (Windows10)
mysql 8.0找不到my.ini配置文件解决方案