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

2

1

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?

Lederer answered 11/8, 2019 at 9:51 Comment(4)
What do you mean by "allows me to connect with an empty password"? So when you specify the password in the my.ini file, it does work as expected? And do you have a mysql user login who doesn't need a password or has an empty password?Glowing
No, it does not work with specified password. The mysql has user root with empty password. If I have to change password in database, then for what are ini file?Lederer
Wait, is the question how to change the password of a user login in mysql? Or do you want to know what the my.ini file with the [client] section is for?Glowing
I want to know what the my.ini file with the [client] section is for.Lederer
G
1

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.

Glowing answered 11/8, 2019 at 10:53 Comment(0)
Y
1

For example on Windows, you can set the user john and the password banana under [client] in my.ini as shown below. *My answer explains [client] and my answer explains where my.ini is located on Windows and my answer explains how to log in by setting only the password banana under [client] in my.ini:

# "my.ini"

[client]
user="john"
password="banana"

Then, you can log in by setting my.ini's location to --defaults-file= or --defaults-extra-file= as shown below:

mysql --defaults-file='C:\ProgramData\MySQL\MySQL Server 8.0\my.ini'

Or:

mysql --defaults-extra-file='C:\ProgramData\MySQL\MySQL Server 8.0\my.ini'

*Not setting my.ini's location to --defaults-file= or --defaults-extra-file= gets error as shown below:

mysql
ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)
Yasmeen answered 11/11, 2023 at 17:46 Comment(1)
Thank you. I tried to connect with client section in my.ini, but username and password are stored in database, and not in my.ini, so I did it incorrectly. So I (still) don't know why client section in my.ini is necessary, if you have to specify a password in database and enter it manually in client software (of course, not "all client programs provided in MySQL distributions", but a third-party client App). So, sorry that my question (and answer) was incorrect. It should be rephrased (or deleted).Lederer

© 2022 - 2025 — McMap. All rights reserved.