Ubuntu Install MySQL

Kevin FOO
1 min readJun 10, 2020

--

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

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

--

--

Kevin FOO
Kevin FOO

Written by Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.

No responses yet