Does the MySQL Command Line Interface (CLI) or "shell" offer the ability to establish a connection using environment variables? The PostgreSQL CLI psql does via libpq with connection variables:
PGHOSTPGPORTPGDATABASEPGUSERPGPASSWORDI know I can connect via command-line switches and a ~/my.cnf file, but I'm wondering if there is an environment variable option analogous to the way psql works. Thanks!
Yes, for some of them: https://dev.mysql.com/doc/refman/8.0/en/environment-variables.html
MYSQL_HOSTMYSQL_TCP_PORTMYSQL_PWD but this is deprecated and insecure and will be removed in a future version of MySQL. It's insecure for PostgreSQL for the same reason: another user can view your client's environment variables using ps.It's more secure to use ~/.my.cnf, or you can specify a different option file to use. You can even store the username/password in an encrypted options file. See https://dev.mysql.com/doc/refman/8.0/en/option-files.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With