What are the steps to install MySQL in Ubuntu?
The steps to install MySQL on Ubuntu are as follows:
- To update the apt package manager: First, run the following command to ensure that the apt package manager is up to date:
sudo apt update
- Install MySQL Server: Execute the following command to install the MySQL Server:
sudo apt install mysql-server
- Start the MySQL service: Once installation is complete, the MySQL service will start automatically. You can use the following command to check the status of the MySQL service:
sudo systemctl status mysql
- Secure setting: Execute the following commands to enhance the security of the MySQL server and remove default users and databases.
sudo mysql_secure_installation
- To log in to MySQL server, you can use the following command.
sudo mysql -u root -p
- To create a new user and database, you can refer to the following command:
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE new_database;
GRANT ALL PRIVILEGES ON new_database.* TO 'new_user'@'localhost';
FLUSH PRIVILEGES;
In this way, you have successfully installed and configured the MySQL server on Ubuntu.