Search code examples
mysqldatabasepasswordsinimy.ini

Is it possible to store a password in my.ini file?


I am using MySQL 5.5. It contains (commented) lines in my.ini:

[client]
#password   = your_password

If I uncomment "password" line, it does not see it, and allows me to connect with an empty password.

[client]
user = root
password    = password

This does not work too.

If this is not possible, then what are these lines intended for?


Solution

  • The [client] section in the my.ini (or my.cnf) file is used to provide settings for client programs like the MySQL client application mysql. See the documentation about the option files:

    The [client] option group is read by all client programs provided in MySQL distributions (but not by mysqld). To understand how third-party client programs that use the C API can use option files, see the C API documentation at Section 28.7.7.50, “mysql_options()”.

    The [client] group enables you to specify options that apply to all clients. For example, [client] is the appropriate group to use to specify the password for connecting to the server. (But make sure that the option file is accessible only by yourself, so that other people cannot discover your password.)

    The client applications have a lot of settings/parameters (see mysql --help) and if you want to predefine some values as a convenient so they don't need to be written all the time, you can use the [client] section.