Home  >  Article  >  Database  >  How do `init_connect` and `init-connect` Differ in MySQL Configuration?

How do `init_connect` and `init-connect` Differ in MySQL Configuration?

Susan Sarandon
Susan SarandonOriginal
2024-11-03 01:21:29606browse

How do `init_connect` and `init-connect` Differ in MySQL Configuration?

Exploring Sections in the MySQL Configuration File

Navigating the MySQL configuration file can be confusing, especially when deciphering the different sections. Here's a comprehensive guide to help you understand each section:

Optional Sections in my.ini

  • [client] - Applies to all connecting clients (including mysql CLI) and allows for various client settings.
  • [mysql] - Specific to the mysql command line client, enabling control over its options.
  • [mysqld] - Configures the MySQL server, including its behavior and performance settings.
  • [mysqldump] - Tailored to the mysqldump utility, granting customization of its operation.
  • ...and so on for other utilities and plugins.

Distinguishing init_connect from init-connect

The distinction lies in their syntax:

  • init_connect (with an underscore) is used within option files to specify commands to be executed after establishing a connection.
  • init-connect (with a hyphen) is used as a command-line parameter to run commands before establishing a connection.

For example, in the my.ini file:

[client]
init_connect = "SET sql_log_bin=ON"

This command will set the sql_log_bin variable to ON after connecting.

On the command line:

mysql -u username -p --init-connect="SET sql_log_bin=ON" database_name

This will execute the same command before connecting to the database database_name as user username.

Refer to the MySQL documentation for detailed information on all optional sections and the syntax of init_connect and init-connect:

http://dev.mysql.com/doc/refman/5.5/en/option-files.html

The above is the detailed content of How do `init_connect` and `init-connect` Differ in MySQL Configuration?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn