Linux下的MySQL服務需要通過配置文件進行設置以實現其正常運行,并且MySQL的配置文件位于/etc/my.cnf中。
下面是一個典型的MySQL配置文件:
# For advice on how to change settings please see # https://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html [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 # # 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 skip-name-resolve datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
在/etc/my.cnf配置文件中,我們需要指定下列幾項配置:
datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock symbolic-links=0 //是否啟用符號連接 log-error=/var/log/mysqld.log //指定錯誤日志的位置 pid-file=/var/run/mysqld/mysqld.pid //指定PID文件的位置
這是MySQL的基本配置,如果需要更改其他的高級設置,可以通過修改配置文件實現,同時也可以參考MySQL的官方文檔進行自定義配置。