我的 mysqldump 腳本一直失敗,說 my.cnf 中沒有前面的組

我的 mysqldump 腳本一直失敗,說 my.cnf 中沒有前面的組

所以 mysqldump 會拋出以下錯誤:

mysqldump: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 22!
mysqldump: [ERROR] Fatal error in defaults handling. Program aborted!

我的 my.cnf 非常基本:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html 
#

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
event-scheduler=ENABLED

附帶問題:我應該在設定檔中添加一些內容以提高安全性嗎?我可以以某種方式壓縮我的表嗎?

答案1

您可能會看到這種情況的原因有兩個:

原因1

您的my.cnf文件沒有UTF-8編碼。您可以使用該od命令進行檢查,看看是否有不在此編碼中的內容。

原因2

[mysqld]您的文件頂部缺少指令。據我所知,您沒有該選項,因此只需添加它並重試即可。

附帶問題:我應該在設定檔中添加一些內容以提高安全性嗎?

通常執行 MySQL 只進行監聽127.0.0.1是一個很好的做法,因為它只允許來自本機的連線。其餘的安全選項是基於您授予資料庫、表格等的權限。

我可以以某種方式壓縮我的表嗎?

InnoDB 允許壓縮。請參閱參考手冊了解更多。

相關內容