Heim  >  Artikel  >  Datenbank  >  Wie automatisiere ich die MySQL-Installation unter Ubuntu ohne Passwortabfrage?

Wie automatisiere ich die MySQL-Installation unter Ubuntu ohne Passwortabfrage?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-15 01:22:02775Durchsuche

How to Automate MySQL Installation on Ubuntu Without Password Prompts?

Automating MySQL Installation on Ubuntu without Password Prompts

Installing MySQL server on Ubuntu using the command sudo apt-get install mysql requires a password to be entered manually. To streamline this process and eliminate the need for user interaction, a script can be created to provide the password automatically.

Script Syntax

The following script will install MySQL server and assign a custom password to the root user:

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

Explanation

  • sudo debconf-set-selections is used to set debconf configuration values.
  • The <<< operator redirects the following string to stdin.
  • mysql-server/root_password and mysql-server/root_password_again are the configuration keys.
  • your_password is the desired root password.

Specific Version Support

For specific MySQL versions, such as 5.6, specify the version in the configuration keys:

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

MySQL Community Server

For MySQL Community Server, the configuration 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

Alternative Shell Syntax

If your script is using a non-bash shell, use the following syntax to pass multiline strings:

echo ... | sudo debconf-set-selections 

Or, using heredocs (requires bash, zsh, or ksh93 shell):

cat << EOF | sudo debconf-set-selections
mysql-server mysql-server/root_password password your_password
mysql-server mysql-server/root_password_again password your_password
EOF

Verification

To check if the configuration was set correctly, run the following command:

sudo debconf-get-selections | grep ^mysql

This should output the values set for the MySQL configuration keys.

Das obige ist der detaillierte Inhalt vonWie automatisiere ich die MySQL-Installation unter Ubuntu ohne Passwortabfrage?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn