How to Install/Upgrade MySQL Packages on Ubuntu Using dpkg Command

1. Download the MySQL packages for ubuntu.

2. Upload the zip file to the Ubuntu and unzip it. (unzip was not install by default on Ubuntu, to install you can use “apt install unzip”)

3. Below is the example for 5.7.18 file list after unzip.

-rw-r--r-- 1 root root 10512612 Mar 18 09:09 mysql-commercial-client_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 18741142 Mar 18 09:09 libmysqld-dev_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 32884156 Mar 18 09:09 mysql-commercial-server_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 6082 Mar 18 09:09 mysql-client_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 1348796 Mar 18 09:09 libmysqlclient20_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 6084 Mar 18 09:09 mysql-testsuite_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 1904082 Mar 18 09:09 libmysqlclient-dev_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 71710 Mar 18 09:09 mysql-common_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 26572174 Mar 18 09:09 mysql-commercial-test_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 6070 Mar 18 09:10 mysql-server_5.7.18+commercial-1ubuntu16.04_amd64.deb
-rw-r--r-- 1 root root 32517 Apr 8 19:48 README.txt

4. To install:

shell> dpkg -i mysql-{common,commercial-client,client,commercial-server,server}_*.deb
Selecting previously unselected package mysql-common.
(Reading database ... 59053 files and directories currently installed.)
Preparing to unpack mysql-common_5.7.18+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-common (5.7.18+commercial-1ubuntu16.04) ...
Selecting previously unselected package mysql-commercial-client.
Preparing to unpack mysql-commercial-client_5.7.18+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-commercial-client (5.7.18+commercial-1ubuntu16.04) ...
Selecting previously unselected package mysql-client.
Preparing to unpack mysql-client_5.7.18+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-client (5.7.18+commercial-1ubuntu16.04) ...
Selecting previously unselected package mysql-commercial-server.
Preparing to unpack mysql-commercial-server_5.7.18+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-commercial-server (5.7.18+commercial-1ubuntu16.04) ...
Selecting previously unselected package mysql-server.
Preparing to unpack mysql-server_5.7.18+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-server (5.7.18+commercial-1ubuntu16.04) ...
Setting up mysql-common (5.7.18+commercial-1ubuntu16.04) ...
update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Setting up mysql-commercial-client (5.7.18+commercial-1ubuntu16.04) ...
Setting up mysql-client (5.7.18+commercial-1ubuntu16.04) ...
Setting up mysql-commercial-server (5.7.18+commercial-1ubuntu16.04) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Setting up mysql-server (5.7.18+commercial-1ubuntu16.04) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...
root@ubuntu:/stage/mysql5718#

5. If you need test suite is to be installed, we also need:

dpkg -i libmysqlclient20_5.7.17+commercial-1ubuntu16.04_amd64.deb
dpkg -i libmysqlclient-dev_5.7.17+commercial-1ubuntu16.04_amd64.deb
dpkg -i mysql-commercial-test_5.7.17+commercial-1ubuntu16.04_amd64.deb
dpkg -i mysql-testsuite_5.7.17+commercial-1ubuntu16.04_amd64.deb

6. Login to database after installation, the root password was provided by you when installing the packages:

root@ubuntu:/stage/mysql5718# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18 MySQL Commercial Server (Advanced)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

To upgrade MySQL using dpkg command

1. Backup MySQL database first.

2. stop the mysql database

# service mysql stop

3. To confirm what MySQL packages have been installed first:

# dpkg -l|grep -i mysql
ii mysql-client 5.7.18+commercial-1ubuntu16.04 amd64 MySQL Client meta package depending on latest version
ii mysql-commercial-client 5.7.18+commercial-1ubuntu16.04 amd64 MySQL Client
ii mysql-commercial-server 5.7.18+commercial-1ubuntu16.04 amd64 MySQL Server
ii mysql-common 5.7.18+commercial-1ubuntu16.04 amd64 MySQL Common
ii mysql-server 5.7.18+commercial-1ubuntu16.04 amd64 MySQL Server meta package depending on latest version
root@ubuntu:/stage/mysql5718#

4. Download new version of MySQL from MOS, here is 5.7.19 for example:

# ls -lrt
total 92588
-rwxr-x--- 1 root root 31933 Aug 26 11:14 README.txt
-rwxr-x--- 1 root root 1904602 Aug 26 11:14 libmysqlclient-dev_5.7.19+commercial-1ubuntu16.04_amd64.deb
-rwxr-x--- 1 root root 1350452 Aug 26 11:14 libmysqlclient20_5.7.19+commercial-1ubuntu16.04_amd64.deb
-rwxr-x--- 1 root root 18845042 Aug 26 11:14 libmysqld-dev_5.7.19+commercial-1ubuntu16.04_amd64.deb
-rwxr-x--- 1 root root 6100 Aug 26 11:14 mysql-client_5.7.19+commercial-1ubuntu16.04_amd64.deb
-rwxr-x--- 1 root root 9801434 Aug 26 11:14 mysql-commercial-client_5.7.19+commercial-1ubuntu16.04_amd64.deb
-rwxr-x--- 1 root root 37170486 Aug 26 11:14 mysql-commercial-server_5.7.19+commercial-1ubuntu16.04_amd64.deb
-rwxr-x--- 1 root root 25596392 Aug 26 11:14 mysql-commercial-test_5.7.19+commercial-1ubuntu16.04_amd64.deb
-rwxr-x--- 1 root root 65552 Aug 26 11:14 mysql-common_5.7.19+commercial-1ubuntu16.04_amd64.deb
-rwxr-x--- 1 root root 6092 Aug 26 11:14 mysql-server_5.7.19+commercial-1ubuntu16.04_amd64.deb
-rwxr-x--- 1 root root 6110 Aug 26 11:14 mysql-testsuite_5.7.19+commercial-1ubuntu16.04_amd64.deb

5. Upgrade the binaries:

# dpkg -i mysql-{common,commercial-client,client,commercial-server,server}_*.deb
(Reading database ... 59314 files and directories currently installed.)
Preparing to unpack mysql-common_5.7.19+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-common (5.7.19+commercial-1ubuntu16.04) over (5.7.18+commercial-1ubuntu16.04) ...
Preparing to unpack mysql-commercial-client_5.7.19+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-commercial-client (5.7.19+commercial-1ubuntu16.04) over (5.7.18+commercial-1ubuntu16.04) ...
Preparing to unpack mysql-client_5.7.19+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-client (5.7.19+commercial-1ubuntu16.04) over (5.7.18+commercial-1ubuntu16.04) ...
Preparing to unpack mysql-commercial-server_5.7.19+commercial-1ubuntu16.04_amd64.deb ...
.
Unpacking mysql-commercial-server (5.7.19+commercial-1ubuntu16.04) over (5.7.18+commercial-1ubuntu16.04) ...
Preparing to unpack mysql-server_5.7.19+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-server (5.7.19+commercial-1ubuntu16.04) over (5.7.18+commercial-1ubuntu16.04) ...
Setting up mysql-common (5.7.19+commercial-1ubuntu16.04) ...
Setting up mysql-commercial-client (5.7.19+commercial-1ubuntu16.04) ...
Setting up mysql-client (5.7.19+commercial-1ubuntu16.04) ...
Setting up mysql-commercial-server (5.7.19+commercial-1ubuntu16.04) ...
Setting up mysql-server (5.7.19+commercial-1ubuntu16.04) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu16) ...
Processing triggers for ureadahead (0.100.0-19) ...

Note: dpkg command will start the database after upgrading. It may take some time to start the database, you may see the process is waiting after “Preparing to unpack mysql-commercial-server….”

6. Verify the packages:

# dpkg -l|grep -i mysql
ii mysql-client 5.7.19+commercial-1ubuntu16.04 amd64 MySQL Client meta package depending on latest version
ii mysql-commercial-client 5.7.19+commercial-1ubuntu16.04 amd64 MySQL Client
ii mysql-commercial-server 5.7.19+commercial-1ubuntu16.04 amd64 MySQL Server
ii mysql-common 5.7.19+commercial-1ubuntu16.04 amd64 MySQL Common
ii mysql-server 5.7.19+commercial-1ubuntu16.04 amd64 MySQL Server meta package depending on latest version

7. To upgrade from 5.7 to 8.0, you need run following commands:

# apt-get install libcurl3

# dpkg -i mysql-{common,commercial-client,client,commercial-server,server,commercial-server-core,commercial-client-core}_*.deb

(Reading database ... 64420 files and directories currently installed.)
Preparing to unpack mysql-common_8.0.11+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-common (8.0.11+commercial-1ubuntu16.04) over (8.0.11+commercial-1ubuntu16.04) ...
Preparing to unpack mysql-commercial-client_8.0.11+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-commercial-client (8.0.11+commercial-1ubuntu16.04) over (8.0.11+commercial-1ubuntu16.04) ...
Preparing to unpack mysql-client_8.0.11+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-client (8.0.11+commercial-1ubuntu16.04) over (8.0.11+commercial-1ubuntu16.04) ...
Preparing to unpack mysql-commercial-server_8.0.11+commercial-1ubuntu16.04_amd64.deb ...
.
Unpacking mysql-commercial-server (8.0.11+commercial-1ubuntu16.04) over (8.0.11+commercial-1ubuntu16.04) ...
Preparing to unpack mysql-server_8.0.11+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-server (8.0.11+commercial-1ubuntu16.04) over (8.0.11+commercial-1ubuntu16.04) ...
Selecting previously unselected package mysql-commercial-server-core.
Preparing to unpack mysql-commercial-server-core_8.0.11+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-commercial-server-core (8.0.11+commercial-1ubuntu16.04) ...
Selecting previously unselected package mysql-commercial-client-core.
Preparing to unpack mysql-commercial-client-core_8.0.11+commercial-1ubuntu16.04_amd64.deb ...
Unpacking mysql-commercial-client-core (8.0.11+commercial-1ubuntu16.04) ...
Setting up mysql-common (8.0.11+commercial-1ubuntu16.04) ...

8. run mysql_upgrade

mysql_upgrade -uroot -p
Enter password:
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv OK
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
The sys schema is already up to date (version 1.5.1).
Checking databases.
sys.sys_config OK
Upgrade process completed successfully.
Checking if update is needed.

8. Restart the database to complete the upgrade.

# service mysql restart