When setting up automated tasks, such as cron jobs for regular database backups, the password prompt for mysqldump can be an obstacle. To avoid manual password input during automated processes, follow these solutions:
For Ubuntu users, creating a .my.cnf file in the home directory eliminates the password prompt. Set the file permissions to 600 and add the following content:
[mysqldump] user=mysqluser password=secret
Alternatively, use the following command-line syntax, but be aware of security implications:
mysqldump -u [user name] -p[password] [database name] > [dump file]
However, with this method, the password is visible to other system users during the dump process.
To enhance security, it's recommended to use an SSH key or sudo with appropriate permissions to connect to the database without providing the password. For instance, use sudo -u mysqluser mysqldump ....
By implementing these methods, you can automate mysqldump tasks without compromising security or manual password input.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3