How to Install and Secure MySQL on Ubuntu
MySQL is a popular relational database. This guide installs it and runs the security hardening script.
1. Install MySQL Server
sudo apt update
sudo apt install -y mysql-server2. Run the security script
sudo mysql_secure_installationThis lets you set a root password and remove insecure defaults (anonymous users, test database, remote root login). Answer Yes to the hardening prompts.
3. Create a database and user
sudo mysql
CREATE DATABASE myapp;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON myapp.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;4. Connect
mysql -u myuser -p myappAlways use a strong, unique password and grant each application user only the privileges it needs.