-1

Is it possible to save the password in .my.cnf or similiar on Windows for mysql?

2
  • 1
    yes it is
    – danblack
    Jul 28 at 22:37
  • Thus makes no sense - you'd edit my.ini and restart server each time when you need to use another account. Save it into the client settings or its command line.
    – Akina
    Jul 29 at 4:29

2 Answers 2

0

Yes , it is possible.

I posted something similar on StackOverflow.

On your my.cnf file create a [client] session , in my case it was on /etc/mysql/my.cnf.

root@ergesttstsrv:~# cat /etc/mysql/my.cnf

[client]
host=localhost
user=root
password=*********
#database=gesti     

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

Uncomment #database=gesti if you want to use a default login database.

Restart MySQL service

root@ergesttstsrv:~# service mysql restart


root@ergesttstsrv:~# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.00 sec)
0

https://dev.mysql.com/doc/refman/8.0/en/mysql-config-editor.html

mysql_config_editor is a convenient tool for hiding login credentials. On *nix, I use it plus an alias so I can log into a variety of servers and databases with a simple command. (I don't know if Windows has the equivalent of alias.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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