How to set default comments in MySQL?

The default comments in MySQL can be adjusted by modifying the MySQL configuration file.

In the MySQL configuration file, the init-connect parameter can be used to set default comments. This parameter allows executing an SQL statement when the client connects to the server.

Open the MySQL configuration file, locate the [mysqld] section, and then add the following line:

init-connect='SET collation_connection = utf8mb4_unicode_ci'

This way, every time a client connects to the MySQL server, this SQL statement will be executed to set the connection character set to utf8mb4_unicode_ci.

Save and close the configuration file, then restart the MySQL server to apply the changes.

Please note that modifying the MySQL configuration file requires administrative privileges. On Windows, the default configuration file path is C:\ProgramData\MySQL\MySQL Server X.X\my.ini, while on Linux it is typically found at /etc/mysql/my.cnf or /etc/my.cnf.

If you want to add default comments only in specific databases or tables, you can use the ALTER TABLE statement to set comments at the database or table level. For example:

ALTER TABLE your_table COMMENT 'Your comment here';

Add a comment to the specified table.

bannerAds