Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install MySQL on Ubuntu without a password prompt

How do I write a script to install MySQL server on Ubuntu?

sudo apt-get install mysql will install, but it will also ask for a password to be entered in the console.

How do I do this in a non-interactive way? That is, write a script that can provide the password?

#!/bin/bash sudo apt-get install mysql  # To install MySQL server  # How to write script for assigning password to MySQL root user # End 
like image 238
Venkat Avatar asked Oct 12 '11 11:10

Venkat


People also ask

Do you need a password for MySQL?

If you have never assigned a root password for MySQL, the server does not require a password at all for connecting as root . However, this is insecure. For instructions on assigning a password, see Section 2.10.


1 Answers

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' sudo apt-get -y install mysql-server 

For specific versions, such as mysql-server-5.6, you'll need to specify the version in like this:

sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password password your_password' sudo debconf-set-selections <<< 'mysql-server-5.6 mysql-server/root_password_again password your_password' sudo apt-get -y install mysql-server-5.6 

For mysql-community-server, the keys are slightly different:

sudo debconf-set-selections <<< 'mysql-community-server mysql-community-server/root-pass password your_password' sudo debconf-set-selections <<< 'mysql-community-server mysql-community-server/re-root-pass password your_password' sudo apt-get -y install mysql-community-server 

Replace your_password with the desired root password. (it seems your_password can also be left blank for a blank root password.)

If your shell doesn't support here-strings (zsh, ksh93 and bash support them), use:

echo ... | sudo debconf-set-selections  
like image 109
Dimitre Radoulov Avatar answered Oct 21 '22 03:10

Dimitre Radoulov