Script Installing a mysql server without asking for a password through CentOS

My OS is CentOS 6.6, and I want to know how to install a mysql server automatically through a shell script.

I found that there is a topic dedicated to the same problem, but it did not cope with CentOS 6: install mysql on ubuntu without a password prompt

sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password your_password' sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password your_password' 

Error message

 bash: debconf-set-selections: command not found 

Here is my main script

 #!/bin/sh # Make sure only root can run our script if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" 1>&2 exit 1 fi #password setting root_password='abc123' #install mysql-server yum install mysql mysql-server #start service service mysqld start #MySQL Initial Setup mysql_secure_installation #This command needs root password and answers(y/n) for secure questions 

Are there any methods to automatically populate the root password and answer "y" to most of the secure questions.

Or he has an alternative way to achieve the same. That is, a script to install myaql server automatically and without a password prompt.

very grateful for your help.

+4
source share
3 answers

mysql_secure_installation is a shell script. therefore, you can edit the set_root_password () function in a script or any other custom interactive sections.

+2
source

What about

 echo "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('secret');" | mysql -u root 
0
source

This code works for me on vagrantfile:

 password_match='awk '/A temporary password is generated for/ {a=$0} END{ print a }' /var/log/mysqld.log | awk '{print $(NF)}'' mysql -u root -p$password_match --connect-expired-password -e "SET password FOR root@localhost =password('$password_match');" mysql -u root -p$password_match -e "SHOW VARIABLES LIKE 'validate_password%';" mysql -u root -p$password_match -e "SET GLOBAL validate_password_length=4;" mysql -u root -p$password_match -e "SET GLOBAL validate_password_policy=LOW;" mysql -u root -p$password_match -e "SHOW VARIABLES LIKE 'validate_password%';" mysql -u root -p$password_match -e "SET password for root@localhost =password('root');" mysql -u root -proot -e "flush privileges;" echo "character-set-server=utf8" >> /etc/my.cnf echo "default_password_lifetime=0" >> /etc/my.cnf echo "validate_password_policy=LOW" >> /etc/my.cnf echo "validate_password_length=4" >> /etc/my.cnf systemctl restart mysqld 
0
source

All Articles