HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Does mysql configuration options accepts - instead of _?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
acceptsoptionsinsteadmysqldoesconfiguration

Problem

Mysql 5.7 Documentation mentions that innodb_buffer_pool_instances can be set in /etc/mysql/mysqld.conf.d/mysqld.cnf as follows:

[mysqld]
innodb_buffer_pool_instances    = 16


However, an existing setup uses mysql configuration as follows (passed in /etc/mysql/mysqld.conf.d/mysqld.cnf):

[mysqld]
innodb-buffer-pool-instances    = 16


And it seems to be working.

Does mysql configuration options accept - instead of _ in variables or am I missing something here?

Solution

https://dev.mysql.com/doc/refman/8.0/en/command-line-options.html says:


Within option names, dash (-) and underscore (_) may be used
interchangeably. For example, --skip-grant-tables and
--skip_grant_tables are equivalent. (However, the leading dashes cannot be given as underscores.)

This applies to options when you use them in option files, as well as command-line flags.

However, when using option variables in SQL queries, like in SET GLOBAL read_only=ON, you must use underscores only. Even putting the variable in back-ticks doesn't allow you to use hyphens.

mysql> set global `read_only`=ON;
Query OK, 0 rows affected (0.00 sec)

mysql> set global `read-only`=ON;
ERROR 1193 (HY000): Unknown system variable 'read-only'

mysql> select @@`read_only`;
+---------------+
| @@`read_only` |
+---------------+
|             1 |
+---------------+
1 row in set (0.01 sec)

mysql> select @@`read-only`;
ERROR 1193 (HY000): Unknown system variable 'read-only'

Code Snippets

mysql> set global `read_only`=ON;
Query OK, 0 rows affected (0.00 sec)

mysql> set global `read-only`=ON;
ERROR 1193 (HY000): Unknown system variable 'read-only'

mysql> select @@`read_only`;
+---------------+
| @@`read_only` |
+---------------+
|             1 |
+---------------+
1 row in set (0.01 sec)

mysql> select @@`read-only`;
ERROR 1193 (HY000): Unknown system variable 'read-only'

Context

StackExchange Database Administrators Q#227644, answer score: 3

Revisions (0)

No revisions yet.