Installing mysql-server in vagrant bootstrap shell script (how to skip setup?)
Solution 1
You can set the MySQL root password in your bootstrap file by adding debconf-set-selections commands before running your apt-get install:
#!/usr/bin/env bash
debconf-set-selections <<< 'mysql-server mysql-server/root_password password MySuperPassword'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password MySuperPassword'
apt-get update
apt-get install -y mysql-server
I presume this to work on any Debian based system. I use it everyday, box is built completely automatically.
Solution 2
You might want to look into Puppet - it is excellent for installing and configuring software automatically. There's also a MySQL module, but I haven't tried it.
Related videos on Youtube
Betimen
Hoosier living in the UK. Self-taught Ruby automation developer focused on business process optimization and data gathering, with a love of stable, open-source tools like CentOS, MySQL and Ruby. Powered by filtered coffee and podcasts. New D&D 5e nerd.
Updated on September 18, 2022Comments
-
Betimen over 1 year
I did try to install mysql-server on my Vagrant Ubuntu 12.04 LTS virtual machine. When I did so, the setup auto-starts. I can see this in the Vagrant output:
While not mandatory, it is highly recommended that you set a password ││ for the MySQL administrative "root" user.││││ If this field is left blank, the password will not be changed.││││ New password for the MySQL "root" user
After that the output text goes haywire —
± ├⎺ ⎼␊⎻┌▒␌␊ ┌␋␉⎽─┌␋├␊3-0 3.7.9-2┤␉┤┼├┤1 (┤⎽␋┼± ...
— but is rather lengthy and full of green and red colors, so I believe the rest of the install is completing.But I can confirm the lack of install after:
sudo apt-get install --just-print mysql-server-5.5 ... The following NEW packages will be installed: mysql-server-5.5
How can I send the right signals through a shell script to configure the MYSQL server? Or if I cannot, how can I stop the automatic launching of the configuration or kill the setup once launched while still having the package installed?
-
Admin almost 10 yearsIf the rest of the install is completing, it would not allow you to install again. Have you tried setting up a password before installation?
-
Admin almost 10 years@Anthon Sorry I do not think I explained this well in my post: I can manually configure all of this, but my goal is to automate as much of my setup as possible. And I have many steps after this that depend on mysql being installed (installing rvm for instance).
-
Admin almost 10 yearsUnless the problems are caused by an unclean system (try to install in a clean virtual machine setup) this sounds like a problem with the package itself. In such cases I have sometimes patched the installation file (not a complete rebuild, just extract/change/put-together) and served it from a local repository.
-
Admin almost 10 years@Anthon :/ I was hoping to find a solution like either a) A MYSQL server package exists that does not auto-launch the configuration wizard or b) there was a bash-y way to trap these kinds of launches (
apt-get install mysql-server | some_trap_cmd >> some.file
). Sounds like maybe no such thing exists? -
Admin almost 10 yearsThe problem is that apt-get runs scripts within the installer file, you are not going to catch a trap in those unless you patch the scripts. You could also take a look at the 5.6 mysql and install it from launchpad, but that could create more trouble pulling in all of the dependencies, but maybe the installation problems are gone.
-
-
AlvaroAV over 9 yearsAwesome! I didn't know this command
-
Betimen over 9 yearsI didn't
debconf-set-selections
existed. This worked perfectly. Thank you! -
Anthony Horne about 2 yearsNot really what the user is asking. Puppet is great, but is either open source or very costly. Doesn't really solve the OP's actual question. Won't mark you down, but something to consider.