🐬 Install MySQL Server¶

MySQL is an open-source relational database management system. It is a popular choice of database for use in web applications, and is a central component of the widely used LAMP open-source web application software stack (Linux, Apache, MySQL, Perl/PHP, Python).
Info
MySQL is written in C and C++.
📥 Installation¶
MySQL can be installed easily on debian system using apt.
sudo apt-get install mysql-server
Important
The root user authenticates via the system socket: no password is prompted during installation.
Connect as root using sudo mysql.
⚙️ Configuration¶
In order to finalize the MySQL installation, it is recommended to execute the following procedure:
# execute secure installation
sudo mysql_secure_installation
# Change the root password? [Y/n] [y] ← set a strong password
# Remove anonymous users? [Y/n] [y]
# Disallow root login remotely? [Y/n] [y]
# Remove test database and access to it? [Y/n] [y]
# Reload privilege tables now? [Y/n] [y]
# login as root via system socket
sudo mysql
Tip
The MySQL server is up and running at this point.
👤 Create an Application User¶
Never use the root account for application access. Create a dedicated user with privileges limited to a specific database.
-- create the application database
CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- create a user restricted to localhost
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'strongpassword';
-- grant access only to the application database
GRANT ALL PRIVILEGES ON mydb.* TO 'appuser'@'localhost';
-- apply changes
FLUSH PRIVILEGES;
-- check the user was created and grants are correct
SHOW GRANTS FOR 'appuser'@'localhost';
Important
Replace mydb, appuser, and strongpassword with your own values.