Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to install MySQL on Ubuntu Natty from a shell script. However, I keep running into one major issue: when I try to define the password outside of the shell script.

Below is the code to my shell script (which I have saved in /etc/init.d/install_mysql:

export DEBIAN_FRONTEND=noninteractive
echo mysql-server-5.1 mysql-server/root_password password $dbpass | debconf-set-selections
echo mysql-server-5.1 mysql-server/root_password_again password $dbpass | debconf-set-selections
apt-get -y install mysql-server

So what I enter in the terminal is:

dbpass="mysqlpass"
chmod +x /etc/init.d/install_mysql
/etc/init.d/install_mysql

MySQL installs, but it installs without a password, so I can just do something like mysql -uroot to access mysql (which I don't want).

The funny thing is if I put the password in the shell script as regular text, it works ok. So if I my install script is as follows, everything works (i.e. I must specify a password to access mysql):

export DEBIAN_FRONTEND=noninteractive
echo mysql-server-5.1 mysql-server/root_password password mysqlpass | debconf-set-selections
echo mysql-server-5.1 mysql-server/root_password_again password mysqlpass | debconf-set-selections
apt-get -y install mysql-server

Is there a way I can use a shell script variable to define my password in the shell script, instead of entering the password literally?!

Thanks in advance.

EDIT

I've found the answer to this.

The following is what I should have entered in the terminal:

dbpass="mysqlpass"
export dbpass
chmod +x /etc/init.d/install_mysql
/etc/init.d/install_mysql

It works like a charm now.

share|improve this question
add comment

1 Answer

You can use preseeding to configure the mysql-server.

The installation progress would look like this:

Create a file /var/cache/local/preseeding/mysql-server.seed which contains your password.

mysql-server-5.0        mysql-server/root_password_again        select YOUR PASSWORD
mysql-server-5.0        mysql-server/root_password              select YOUR PASSWORD

Now install your mysql-server with this config file.

debconf-set-selections /var/cache/local/preseeding/mysql-server.seed
apt-get -y install mysql-server

There are even many more configuration options possible inside the seeding file.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.