Ubuntu Install MySQL

For a small project, it is more economical to run MySQL server in Ubuntu 20.04 than to subscribe Amazon RDS. To install run the commands below.

sudo apt update
sudo apt upgrade -y
sudo apt install -y mysql-server

By default MySQL server bind address is set to 127.0.0.1. Run the command below to edit the configuration file and set it to 0.0.0.0 which binds to all addresses.

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
Image for post
Image for post

After the installation, run the below command to get into MySQL prompt.

sudo mysql -uroot

Run this command to check the available users in MySQL.

select user, host, plugin from mysql.user;

Lets change the MySQL user “root” to login with a password. At present “root” can only login from localhost even though the server bind address is set to all addresses.

Command below will allow “root” to login from anywhere with a “%”. I prefer to do this and control white listed IP through Amazon EC2 security group.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
update mysql.user set host='%' where user='root';
exit;

Lastly restart the MySQL server.

sudo systemctl restart mysql

< Back to all the stories I had written

Written by

A software engineer, a rock climbing, diving & rollerblading enthusiast, a husband, a father.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store