3

Runningshow variables like 'server%' shows server_id as variable name.

But in my.cnf, there's an entry for server-id (although commented out)

Is there any differece between the them?

IMB
  • 15,163
  • 19
  • 82
  • 140
  • 1
    `-` and `_` in the config file are mapped into `_` when looking at the `VARIABLES`. That is, they are equivalent. – Rick James Jan 06 '19 at 17:56
  • @RickJames Does that apply to all variables on both MySQL and MariaDB? – IMB Jan 06 '19 at 18:16
  • 1
    As far as I know, yes, it applies to all variables in both products. I have seen lots of examples of `-` in use in my.cnf, yet never a verifiable case of failure to map to `_`. There _may_ be a sentence buried in the documentation. – Rick James Jan 06 '19 at 18:20

2 Answers2

3

MySQL

4.2.9 Using Options to Set Program Variables:

...

If you like, underscores in a variable name can be specified as dashes. The following option groups are equivalent. Both set the size of the server's key buffer to 512MB:

[mysqld]
key_buffer_size=512M

[mysqld]
key-buffer-size=512M

...

MariaDB

Server System Variables and mysqld Options:

...

By convention, server variables have usually been specified with an underscore in the configuration files, and a dash on the command line. You can however specify underscores as dashes - they are interchangeable.

...

Test MySQL

File: my.cnf

[mysqld]
. 
.
.
server_id=987
.
.
.

Command-Line:

$ mysql --execute="SELECT VERSION(), @@server_id"
+-----------+-------------+
| VERSION() | @@server_id |
+-----------+-------------+
| 8.0.13    |         987 |
+-----------+-------------+

File: my.cnf

[mysqld]
.
.
.
server-id=321
.
.
.

Command-Line:

$ sudo systemctl restart mysql

$ mysql --execute="SELECT VERSION(), @@server_id"
+-----------+-------------+
| VERSION() | @@server_id |
+-----------+-------------+
| 8.0.13    |         321 |
+-----------+-------------+
wchiquito
  • 16,177
  • 2
  • 34
  • 45
2

They are same but as it is stated in this post, if your server-id is not changed by setting my.cfg you can try setting it by underscore

[mysqld]
server_id = 2
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
  • In Ubuntu 18, with a percona 5.7.32-35-log version, I actually discovered that server_id does not force a new UUID value if you delete the aut.cnf, but if you use server-id and do the same the UUID does change. Hope this is helpful for those doing binary slave copies. – Ross Jan 25 '21 at 11:33