brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mysql_config_editor saves login details under a login path

Mysql
~/tips/tip-mysql-config-editor-login-path

mysql_config_editor set --login-path=shop \

Stores host, user and password so you stop typing them in commands.

I wouldn’t type a password after -p, because it lands in your shell history. MySQL ships a small tool that remembers it for you under a name.

Create an entry and type the password at the prompt:

mysql_config_editor set --login-path=shop \
  --host=db.example.com --user=appadmin --password

From then on, one option replaces all of that:

mysql --login-path=shop
mysqldump --login-path=shop shopdb > shop.sql

Make as many paths as you have servers. To review them, with passwords masked:

mysql_config_editor print --all

Entries go into .mylogin.cnf in your home directory. It must be readable and writable by you alone, otherwise the programs ignore it. Anything you add on the command line still overrides the stored value, so --host can point the same credentials at another machine.

Don’t mistake it for a vault. The manual says plainly that the file is obfuscated, and that someone with administrator rights on the machine can recover the password with some effort. It keeps the secret out of history files, process lists and scripts you share, which is a real gain, and nothing more than that.

This tool belongs to MySQL’s own client package. MariaDB doesn’t include it, so on a MariaDB machine you’d use an option file with tight permissions.

Further reading: mysql_config_editor

More Mysql tips FOR UPDATE SKIP LOCKED; SET PERSIST max_connections = 300; ALTER TABLE orders ADD COLUMN note VARCHAR(100), ALGORITHM=INSTANT; ALTER USER 'appuser'@'192.0.2.10' SELECT * FROM sys.schema_unused_indexes All Mysql tips (8) All topics

Link