MySQL 8.0 Setup
Install MySQL on Ubuntu servers
- Step 1 — Installing MySQL
- Step 2 — Configuring MySQL
- Step 3 — Creating a Dedicated MySQL User and Granting Privileges
- MySQL Extra
Step 1 — Installing MySQL
-
Update the package index
sudo apt update
-
Install the MySQL server package
sudo apt install mysql-server
-
Start MySQL server
sudo systemctl start mysql.service
-
Check MySQL server status
sudo systemctl status mysql
- The status should look like this
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-04-21 12:56:48 UTC; 6min ago
Main PID: 10382 (mysqld)
Status: "Server is operational"
Tasks: 39 (limit: 1137)
Memory: 370.0M
CGroup: /system.slice/mysql.service
└─10382 /usr/sbin/mysqld
Step 2 — Configuring MySQL
- Open MySQL prompt
sudo mysql |
- Change the root user’s authentication method to one that uses a password
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
- Exit the MySQL prompt
exit
- Authenticate as the root MySQL user using a password
mysql -u root -p |
- Go back to using the default authentication method
ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
- Exit the MySQL prompt
exit
- Run the security script
sudo mysql_secure_installation |
- Following configuration is shown
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:
2
Output
Please set the password for root here.
New password:
Re-enter new password:
Output
Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
Step 3 — Creating a Dedicated MySQL User and Granting Privileges
- Open MySQL prompt
mysql -u root -p
- Create a new User
CREATE USER 'username'@'host' IDENTIFIED WITH authentication_plugin BY 'password';
or
CREATE USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
- Grant privileges
GRANT PRIVILEGE ON database.table TO 'username'@'host';
MySQL Extra
-
Start MySQL server
sudo systemctl start mysql.service
-
Check MySQL status
sudo systemctl status mysql
-
Restart MySQL server
sudo systemctl restart mysql
-
Uninstall MySQL
sudo systemctl stop mysql
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*
sudo rm -rf /etc/mysql /var/lib/mysql
-
Unmask MySQL
sudo systemctl unmask mysql.service