To install MySQL, first log in to the server using terminal. I will log in using my SSH
ssh root@{ip}
Then run following commands
sudo apt update
sudo apt install mysql-server
Then start the service using
sudo systemctl start mysql.service
Now, we need to install the security services
sudo mysql_secure_installation
This will show the below output
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: Y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
0
For testing purposes, I chose 0. That is the bare minimum password for the users and the root password won't be set. Then some prompt will open, press Y or N depending on your choice.
After all the prompt is done,enter the MySQL console
sudo mysql
CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';
Be sure to change the sammy
to your user and password
to your password.
Then set the privileges
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, INDEX, DELETE, SELECT, REFERENCES, RELOAD on *.* TO 'sammy'@'localhost' WITH GRANT OPTION;
You are all set. You can clear the cache using
FLUSH PRIVILEGES;
Exit the MySQL console and check the status by running
systemctl status mysql.service
Output:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
Active: active (running) since Thu 2023-11-16 02:44:55 UTC; 1h 8min ago
Process: 10804 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=>
Main PID: 10812 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 1116)
Memory: 361.8M
CPU: 30.669s
CGroup: /system.slice/mysql.service
└─10812 /usr/sbin/mysqld
lines 1-11/11 (END)
If the above output shows, congratulations, Mysql is not installed.
Top comments (0)