Ravindra BagaleCourses & study guides

10. MySQL Part 1: Install, Create, Insert and SELECT

10.1 Installing MySQL or MariaDB

MariaDB he MySQL cha community fork aahe – aaplya kaamasathi purna compatible: tech mysql client, tech SQL, tech port 3306. Amazon Linux 2023 var MariaDB, Ubuntu var MySQL 8 vaparuya.

OS Package Service Admin login
Amazon Linux 2023 mariadb105-server mariadb sudo mysql
Ubuntu 22.04/24.04 mysql-server (MySQL 8.x) or mariadb-server mysql (or mariadb) sudo mysql (root uses auth_socket)
CentOS Stream 9 mariadb-server (or mysql-server for MySQL 8) mariadb (or mysqld) sudo mysql
Amazon Linux 2 (older) mariadb-server mariadb sudo mysql

Amazon Linux 2023

sudo yum install -y mariadb105-server
sudo service mariadb start
sudo systemctl enable mariadb
sudo service mariadb status

Ubuntu

sudo apt update
sudo apt install -y mysql-server
sudo service mysql start
sudo systemctl enable mysql
sudo service mysql status
sudo mysql_secure_installation      # remove anonymous users, test DB, remote root: answer Y
sudo mysql                          # log in as the admin (root) user
SELECT VERSION();
SHOW DATABASES;
EXIT;

Why this matters for security

A database should listen only on 127.0.0.1 (check sudo ss -tlnp | grep 3306) and port 3306 must never be open to the internet in the security group. Exposed databases with weak passwords are found by internet scanners and emptied or held for ransom.

Ravindra Bagale's Tip

Khup students 3306 port security group madhe "Anywhere" la ughadtat karan laptop varun Workbench ne connect karaycha asta. Asa karu naka! SSH tunnel vapra: ssh -i key.pem -L 3307:127.0.0.1:3306 ec2-user@<IP> aani Workbench la 127.0.0.1:3307 dya. Port band, kaam chalu.

Practice task

Install the database on one instance, run mysql_secure_installation, log in with sudo mysql and print the version.