HomeLinuxHow To Set up MySQL on Ubuntu 22.04/Ubuntu 20.04

How To Set up MySQL on Ubuntu 22.04/Ubuntu 20.04


MySQL neighborhood server is a free open-source, widespread, and cross-platform database administration system, which helps each SQL and NoSQL and has a pluggable storage engine structure.

Moreover, it additionally comes with a number of database connectors for various programming languages, permitting you to develop functions utilizing any of the well-known languages, and lots of different options.

It has many use circumstances below doc storage, cloud, excessive availability techniques, IoT (Web of Issues), hadoop, large information, information warehousing, LAMP or LEMP stack for supporting high-volume web sites/apps, and way more.

On this article, we’ll clarify a recent set up of the MySQL 8.0 database system on Ubuntu 22.04, Ubuntu 20.04, and Ubuntu 18.04 releases. Earlier than we transfer on to the precise set up steps, let’s take a look at a abstract of:

What’s New in MySQL 8.0

  • The database now incorporates a transactional information dictionary.
  • Comes with Atomic DDL assertion help.
  • Enhanced safety and account administration.
  • Enhancements to useful resource administration.
  • A number of InnoDB enhancements.
  • A brand new kind of backup lock.
  • The default character set has modified to utf8mb4 from latin1.
  • A few JSON enhancements.
  • Comes with common expression help utilizing Worldwide Elements for Unicode (ICU).
  • New error logging which now makes use of the MySQL element structure.
  • Enhancements to MySQL replication.
  • Helps widespread desk expressions(each non-recursive and recursive).
  • Has an enhanced optimizer.
  • Further window capabilities and extra.

Step 1: Udating Ubuntu Server

Fortunately, you should utilize the default APT package deal repository for putting in the MySQL server, consumer, and different parts. On the time of writing this text, the accessible MySQL model is 8.0.28.

To put in it, you need to replace the package deal index in your Ubuntu server by operating the next apt instructions.

$ sudo apt replace
$ sudo apt improve

Subsequent, use the apt-cache command (queries the package deal cache) to seek for MySQL server and consumer packages in your Ubuntu server.

$ apt-cache search mysql-server


mysql-server - MySQL database server (metapackage relying on the newest model)
mysql-server-8.0 - MySQL database server binaries and system database setup
mysql-server-core-8.0 - MySQL database server binaries
default-mysql-server - MySQL database server binaries and system database setup (metapackage)
default-mysql-server-core - MySQL database server binaries (metapackage)
mariadb-server-10.6 - MariaDB database server binaries
mariadb-server-core-10.6 - MariaDB database core server recordsdata

Step 2: Set up MySQL on Ubuntu Server

Then run the next command to put in packages for the MySQL neighborhood server, consumer, and the database widespread recordsdata.

$ sudo apt-get set up mysql-server
Install MySQL 8.0 in Ubuntu 18.04
Set up MySQL 8.0 in Ubuntu 18.04

The default MySQL configuration file and an error log file shall be situated on the following location, you may view them utilizing the nano editor or tail command as proven.

$ sudo nano /and so forth/my.cnf
$ sudo tail -f /var/log/mysql/error.log

Step 3: Managing MySQL Server by way of Systemd

On Ubuntu, after putting in the MySQL server package deal, its service(s) are normally began mechanically as soon as the package deal is configured. You’ll be able to verify if the MySQL server is up and operating utilizing the next systemctl command.

$ sudo systemctl standing mysql.service
Check MySQL Server Status
Verify MySQL Server Standing

If for one cause or the opposite, it isn’t auto-started, use the instructions under to begin and allow it to begin at system boot time, as follows.

$ sudo systemctl begin mysql.service
$ sudo systemctl standing mysql.service
$ sudo systemctl begin mysql.service
$ sudo systemctl restart mysql.service

Step 4: Set MySQL Root Password

First, open up the MySQL immediate:

$ sudo mysql

Subsequent, run the next ALTER USER command to set the MySQL root password utilizing the mysql_native_password authentication methodology as proven.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR-STRONG-PASSWORD';

After setting the password, exit the MySQL immediate:

mysql> exit
Set MySQL Password in Ubuntu
Set MySQL Password in Ubuntu

Step 5: Safe MySQL Server Set up

By default, the MySQL set up is unsecure. To safe it, run the safety script which comes with the binary package deal.

$ sudo mysql_secure_installation

You may be requested to enter the root password you simply set above.

Then enter sure/y to the next safety questions:

  • Take away nameless customers? (Press y|Y for Sure, another key for No) : y
  • Disallow root login remotely? (Press y|Y for Sure, another key for No) : y
  • Take away the take a look at database and entry to it? (Press y|Y for Sure, another key for No) : y
  • Reload privilege tables now? (Press y|Y for Sure, another key for No) : y
Secure MySQL in Ubuntu
Safe MySQL in Ubuntu

To additional safe your MySQL server, learn our article 12 MySQL Safety Finest Practices for Linux.

Step 6: Create MySQL Database with Consumer

The MySQL set up comes with a root account, which you should utilize to handle the entire database, however for safety causes, I recommend you create a standard consumer account with restricted privileges to databases as proven.

$ mysql -u root -p
mysql> CREATE DATABASE tecmintdb;
mysql> CREATE USER 'aaron'@'localhost' IDENTIFIED BY 'rig!43B#web1rdl0gn1';
mysql> GRANT ALL PRIVILEGES ON tecmintdb.* TO 'aaron'@'localhost';

Now to log in as your new MySQL consumer, use the next command.

$ mysql -u aaron -p
Create MySQL Database with User
Create MySQL Database with Consumer

Step 7: Set up Additional MySQL Merchandise and Elements

As well as, you may set up additional MySQL parts that you simply really feel you want with the intention to work with the server, akin to mysql-workbench-community, libmysqlclient18, and lots of others.

$ sudo apt-get replace
$ sudo apt-get set up mysql-workbench-community libmysqlclient18

Lastly, to entry the MySQL shell, subject the next command.

$ sudo mysql -u root -p
Connect to MySQL Server
Connect with MySQL Server

That’s It! On this article, we’ve got defined tips on how to set up MySQL in Ubuntu 22.04 and Ubuntu 20.04. If in case you have any questions or ideas to share, use the remark kind under to achieve us.

If You Respect What We Do Right here On TecMint, You Ought to Contemplate:

TecMint is the quickest rising and most trusted neighborhood website for any form of Linux Articles, Guides and Books on the net. Hundreds of thousands of individuals go to TecMint! to look or browse the 1000’s of printed articles accessible FREELY to all.

In case you like what you might be studying, please contemplate shopping for us a espresso ( or 2 ) as a token of appreciation.

Support Us

We’re grateful in your by no means ending help.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments