Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Specific version of MySQL 5.6 install on Ubuntu 14.04
# This script is not fully tested against data safety. Backup data and use at your own risk.
# To get available MySQL 5.6 versions, refer to
version=$(cat /etc/*release | grep -Po '(?<=^VERSION_ID=")[0-9.]+')
sys_name=$(cat /etc/*release | grep -Po '(?<=^NAME=").*(?=")')
if [ "$sys_name" == 'Ubuntu' ] && [ "$version" == '14.04' ]; then
echo "This script only installs a specific minor version of MySQL 5.6."
echo "This script only runs on Ubuntu 14.04 system. Abort."
exit 1
echo "Please note that this script only runs with root privilege."
echo "If you are running with a user that needs password with sudo, you will need to enter your password now and probably later again."
if sudo echo -n ""
echo "Root privilege check PASS."
echo "Root privilege check FAIL. Abort."
exit 1
echo -n "Enter the minor version you want, e.g. for 5.6.33 in just type 33 and press [ENTER]: "
read -r version
if [[ ! $version =~ ^[0-9]+$ ]];then
echo "'${version}' isn't a valid number. Abort."
exit 1
# version_match(package_name)
# Returns 0 if the specified version of package is installed,
# otherwise returns 1.
version_match() {
test $(sudo dpkg -s "$1" | grep -Po '(?<=^Version:\s)[0-9.]+') == "$full_version"
return $?
# check for installed version
if version_match "mysql-server" && \
version_match "mysql-community-server" && \
version_match "mysql-client" && \
version_match "mysql-community-client" && \
version_match "mysql-common"; then
printf "\\nMySQL %s already installed. Abort.\\n\\n" "$full_version"
exit 0
exit 0
tmp_dir=$(mktemp -d)
mkdir "$download_dir"
printf "Downloading install package for MySQL %s to $download_dir.\\n\\n" "$full_version"
if ! wget -q "$full_version-1ubuntu14.04_amd64.deb-bundle.tar" -O "$download_dir/bundle.tar"
echo "Error downloading. Exit."
exit 1;
echo "Removing old packages..."
sudo dpkg -r "mysql-server" && \
sudo dpkg -r "mysql-community-server" && \
sudo dpkg -r "mysql-client" && \
sudo dpkg -r "mysql-community-client" && \
sudo dpkg -r "mysql-common"
if [ $? != 0 ]; then
printf "\\nError removing old packages. Abort for safe.\\n"
exit 1
echo "Installing new packages..."
cd "$download_dir" && tar xf bundle.tar
sudo dpkg -i "mysql-common_$full_version-1ubuntu14.04_amd64.deb" && \
sudo dpkg -i "mysql-community-client_$full_version-1ubuntu14.04_amd64.deb" && \
sudo dpkg -i "mysql-client_$full_version-1ubuntu14.04_amd64.deb" && \
sudo dpkg -i "mysql-community-server_$full_version-1ubuntu14.04_amd64.deb" && \
sudo dpkg -i "mysql-server_$full_version-1ubuntu14.04_amd64.deb"
if [ $? != 0 ]; then
printf "\\nError installing. Sorry but you have to fix manually.\\n"
exit 1
printf "\\nMySQL %s installed successfully.\\n" "$full_version"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.