Quick local mysql access without password entry
Using mysql_config_editor
which stores a ~/.mylogin.cnf
file we can have easy access to mysql as a privileged user from the terminal without needing to enter your password nor needing to use sudo.
Step 1. Create the user
CREATE USER 'USERNAMEHERE'@'localhost' IDENTIFIED BY 'PASSWORDHERE';
Step 2. Privileges, e.g. this would give you everything:
GRANT ALL PRIVILEGES ON *.* TO 'USERNAMEHERE'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES
Step 3. Use the config editor to generate your file.
mysql_config_editor set --user=USERNAMEHERE --password
# it'll then ask for your password once
Step 4. Profit.
mysql
^-- you should now be able to access your local mysql with a single command and no password entry needed.
You can also run mysql_config_editor
with a --login-path=NAME
flag to create multiple of these, then when starting mysql you can add that flag again to login to them.
More info about this command here:
https://www.prisma.io/dataguide/mysql/tools/mysql-config-editor