If you need to complete an unattended installation or scripted install of MySQL On Ubuntu Linux you can do so easily by setting the necessary variable with debconf-set-selections. Typically when you install MySQL on Ubuntu it will pop up a window and ask for you to enter a password even when you have specified -y with apt-get install. Below are the commands necessary to set the password variable which then allow you to automatically install MySQL on Ubuntu.
Set MySQL Install Variable On Ubuntu Linux:
- echo mysql-server mysql-server/root_password select PASSWORD | debconf-set-selections
- echo mysql-server mysql-server/root_password_again select PASSWORD | debconf-set-selections
You simply add the above lines to your shell script or run the above commands from an Ubuntu terminal window. Make sure to change PASSWORD on each line to whatever you want the MySQL password to be. Once you have run the above commands you can install mysql-server which will also install mysql-server-core without any interaction as shown in the below example.
Install MySQL Automatically On Ubuntu:
- root@ubuntu-dev:~# apt-get -y install mysql-server
- Reading package lists... Done
- Building dependency tree
- Reading state information... Done
- The following extra packages will be installed:
- mysql-server-5.5 mysql-server-core-5.5
- Suggested packages:
- tinyca
- Recommended packages:
- libhtml-template-perl
- The following NEW packages will be installed:
- mysql-server mysql-server-5.5 mysql-server-core-5.5
- 0 upgraded, 3 newly installed, 0 to remove and 40 not upgraded.
- Need to get 0 B/14.9 MB of archives.
- After this operation, 52.9 MB of additional disk space will be used.
- Preconfiguring packages ...
- Selecting previously unselected package mysql-server-core-5.5.
- (Reading database ... 71643 files and directories currently installed.)
- Unpacking mysql-server-core-5.5 (from .../mysql-server-core-5.5_5.5.24-0ubuntu0.12.04.1_amd64.deb) ...
- Selecting previously unselected package mysql-server-5.5.
- Unpacking mysql-server-5.5 (from .../mysql-server-5.5_5.5.24-0ubuntu0.12.04.1_amd64.deb) ...
- Selecting previously unselected package mysql-server.
- Unpacking mysql-server (from .../mysql-server_5.5.24-0ubuntu0.12.04.1_all.deb) ...
- Processing triggers for man-db ...
- fopen: Permission denied
- Processing triggers for ureadahead ...
- Setting up mysql-server-core-5.5 (5.5.24-0ubuntu0.12.04.1) ...
- Setting up mysql-server-5.5 (5.5.24-0ubuntu0.12.04.1) ...
- 121208 5:25:51 [Note] Plugin 'FEDERATED' is disabled.
- 121208 5:25:51 InnoDB: The InnoDB memory heap is disabled
- 121208 5:25:51 InnoDB: Mutexes and rw_locks use GCC atomic builtins
- 121208 5:25:51 InnoDB: Compressed tables use zlib 1.2.3.4
- 121208 5:25:51 InnoDB: Initializing buffer pool, size = 128.0M
- 121208 5:25:51 InnoDB: Completed initialization of buffer pool
- 121208 5:25:51 InnoDB: highest supported file format is Barracuda.
- 121208 5:25:51 InnoDB: Waiting for the background threads to start
- 121208 5:25:52 InnoDB: 1.1.8 started; log sequence number 1595675
- 121208 5:25:52 InnoDB: Starting shutdown...
- 121208 5:25:52 InnoDB: Shutdown completed; log sequence number 1595675
- mysql start/running, process 8468
- Setting up mysql-server (5.5.24-0ubuntu0.12.04.1) ...
- root@ubuntu-dev:~#
You should now be able to login to MySQL using the below syntax and after enter is clicked the password that was set using the debconf-set-selections command above.
- root@ubuntu-dev:~# mysql -u root -p
- Enter password:
On another note if you are going to be scripting package installation on Ubuntu the debconf-set-selections command will become your best friend.