一、my.cnf文件找不到

1、在安装完mysql之后,在终端输入:mysql —help|grep ‘my.cnf’,结果如下图。
image.png
这四个默认的指定路径,mysql按照顺序依次从第一个路径开始寻找my.cnf,所以我们直接将my.cnf创建在第一个路径下就行了。my.cnf文件内容如下
注意:下面配置已开启 log-bin=mysql-bin 和 binlog_format=ROW (canal使用)

  1. # Example MySQL config file for small systems.
  2. #
  3. # This is for a system with little memory (<= 64M) where MySQL is only used
  4. # from time to time and it's important that the mysqld daemon
  5. # doesn't use much resources.
  6. #
  7. # MySQL programs look for option files in a set of
  8. # locations which depend on the deployment platform.
  9. # You can copy this option file to one of those
  10. # locations. For information about these locations, see:
  11. # http://dev.mysql.com/doc/mysql/en/option-files.html
  12. #
  13. # In this file, you can use all long options that a program supports.
  14. # If you want to know which options a program supports, run the program
  15. # with the "--help" option.
  16. # The following options will be passed to all MySQL clients
  17. [client]
  18. default-character-set=utf8
  19. #password = your_password
  20. port = 3306
  21. socket = /tmp/mysql.sock
  22. # Here follows entries for some specific programs
  23. # The MySQL server
  24. [mysqld]
  25. default-storage-engine=INNODB
  26. character-set-server=utf8
  27. collation-server=utf8_general_ci
  28. port = 3306
  29. socket = /tmp/mysql.sock
  30. skip-external-locking
  31. key_buffer_size = 16K
  32. max_allowed_packet = 1M
  33. table_open_cache = 4
  34. sort_buffer_size = 64K
  35. read_buffer_size = 256K
  36. read_rnd_buffer_size = 256K
  37. net_buffer_length = 2K
  38. thread_stack = 128K
  39. # Don't listen on a TCP/IP port at all. This can be a security enhancement,
  40. # if all processes that need to connect to mysqld run on the same host.
  41. # All interaction with mysqld must be made via Unix sockets or named pipes.
  42. # Note that using this option without enabling named pipes on Windows
  43. # (using the "enable-named-pipe" option) will render mysqld useless!
  44. #
  45. #skip-networking
  46. server-id = 1
  47. # Uncomment the following if you want to log updates
  48. log-bin=mysql-bin
  49. # binary logging format - mixed recommended
  50. binlog_format=ROW
  51. # Causes updates to non-transactional engines using statement format to be
  52. # written directly to binary log. Before using this option make sure that
  53. # there are no dependencies between transactional and non-transactional
  54. # tables such as in the statement INSERT INTO t_myisam SELECT * FROM
  55. # t_innodb; otherwise, slaves may diverge from the master.
  56. #binlog_direct_non_transactional_updates=TRUE
  57. # Uncomment the following if you are using InnoDB tables
  58. #innodb_data_home_dir = /usr/local/mysql/data
  59. #innodb_data_file_path = ibdata1:10M:autoextend
  60. #innodb_log_group_home_dir = /usr/local/mysql/data
  61. # You can set .._buffer_pool_size up to 50 - 80 %
  62. # of RAM but beware of setting memory usage too high
  63. #innodb_buffer_pool_size = 16M
  64. #innodb_additional_mem_pool_size = 2M
  65. # Set .._log_file_size to 25 % of buffer pool size
  66. #innodb_log_file_size = 5M
  67. #innodb_log_buffer_size = 8M
  68. #innodb_flush_log_at_trx_commit = 1
  69. #innodb_lock_wait_timeout = 50
  70. [mysqldump]
  71. quick
  72. max_allowed_packet = 16M
  73. [mysql]
  74. no-auto-rehash
  75. # Remove the next comment character if you are not familiar with SQL
  76. #safe-updates
  77. [myisamchk]
  78. key_buffer_size = 8M
  79. sort_buffer_size = 8M
  80. [mysqlhotcopy]
  81. interactive-timeout

2、将上面my.cnf拷贝到/etc/my.cnf下

  1. # 创建文件,复制内容
  2. sudo vim /etc/my.cnf
  3. # 赋予权限
  4. sudo chmod 664 /etc/my.cnf //如果是修改为其他的777、666等mysql认为这是不安全的,所以自动忽略. 请将将文件权限改为mysql认可的664

3、进入mysql客户端验证
操作命令:show master status
结果如下:
image.png
看到如上信息则表示my.cnf读取成功(my.cnf中开启了bin.log,上图中bin.log记录)