mysql backup password without root home

All we need is an easy explanation of the problem, so here it is.

What’s the best way to provide a MySql root password (~/.my.cnf) to cron job without root to have the home folder?
the server I’m using is centos

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

What’s the best way to provide a MySql … password

Using a separate configuration file, as described in the Manual.

What’s the best way to provide a MySql root password

You should not use any high-level credentials for Application connectivity. Not root, not mysql.
Always created a dedicated account for your Application, grant it appropriate permissions, and use that.

Why? You should always keep the Best Tools in the ToolBox for yourself – so that you can clean up the mess made by everybody else!

… without root to have the home folder?

The Linux root account will always have access to the mysql home folder.
By design, root must have access to everything.

Method 2

Use mysql_config_editor

mysql_config_editor set -G project_name -u database_name -p -h localhost

Notes

  • The -p prompts for the password
  • -P 3306 for port (default 3306)
  • -h could point to a remote server
  • Other options are possible

Docker example:

mysql_config_editor set -G o8016 -P 8016 -u root -p -h `hostname`

Usage:

mysql  --login-path=o8016

mysql_config_editor hides the pwd in a ‘dot file’ in your home directory is such a way that access is limited to you and, of course, "root".

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply