0

I am experimenting with option files in MySQL. I have a ~/.my.cnf file which includes only the following:

!include /Users/myself/Workspace/project_time/mysql/foo.cnf

[client]
i_am_a_dummy

And I have a file /Users/myself/Workspace/project_time/mysql/foo.cnf which includes only the following:

[mysqld]
skip_column_names

I have newlines at the end of each file.

I also have a database, new_database, which includes a table t1.

I run MySQL with the command mysql -uroot -p new_database; and type in my password at the prompt, after which I see the MySQL prompt. When I type select * from t1; at the prompt, I would expect to see the output without headers, like so:

mysql> select * from t1;
+------+------+------+
| 2001 | 1    | 1    |
| 2001 | 1    | 20   |
| 2001 | 1    | 30   |
| 2001 | 2    | 2    |
| 2001 | 2    | 23   |
| 2001 | 2    | 23   |
+------+------+------+
6 rows in set (0.00 sec)

Unfortunately, instead I see the following:

mysql> select * from t1;
+------+-------+------+
| year | month | day  |
+------+-------+------+
| 2001 |     1 |    1 |
| 2001 |     1 |   20 |
| 2001 |     1 |   30 |
| 2001 |     2 |    2 |
| 2001 |     2 |   23 |
| 2001 |     2 |   23 |
+------+-------+------+
6 rows in set (0.00 sec)

I have already tried to use [client] as the option group in foo.cnf instead of [mysqld], but that did not work.

When I add skip_column_names directly to ~/.my.cnf (just below i_am_a_dummy), it works as expected.

What am I missing?

1
  • 1
    Settings for the server go under [mysqld]. Settings for the commandline mysql need to be under [mysql] or [client]. (Put them under both.)
    – Rick James
    Commented Dec 15, 2020 at 1:40

1 Answer 1

0

When I created foo.cnf, I set the permissions to 777. Apparently world-writable config files are ignored:

~/Workspace/project_time/mysql ()  $ mysql --print-defaults -uroot -p<secret> new_database;
mysql: [Warning] World-writable config file '/Users/myself/Workspace/project_time/mysql/foo.cnf' is ignored.
mysql would have been started with the following arguments:
--i_am_a_dummy -uroot -p<secret> new_database 

When I reset the permissions for foo.cnf to 755 and re-run the command, I get the following:

~/Workspace/project_time/mysql ()  $ chmod 755 foo.cnf 
~/Workspace/project_time/mysql ()  $ mysql --print-defaults -uroot -p<secret> new_database;
mysql would have been started with the following arguments:
--skip_column_names --i_am_a_dummy -uroot -p<secret> new_database 

And when I invoke the aforementioned SELECT statement in the CLI, it appears as expected:

mysql> select * from t1;
+------+------+------+
| 2001 | 1    | 1    |
| 2001 | 1    | 20   |
| 2001 | 1    | 30   |
| 2001 | 2    | 2    |
| 2001 | 2    | 23   |
| 2001 | 2    | 23   |
+------+------+------+
6 rows in set (0.00 sec)

EDIT: The warning is actually printed out even when not passing the --print-defaults flag, I just didn't notice it among the other output in the CLI. Since --print-defaults results in much less output on start-up, the warning was easier to notice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.