How to install and configure a MySQL database in CentOS?
You can install and configure MySQL database in CentOS by following these steps:
- Update the system software package list: Run the following command to ensure that your system software package list is up to date:
sudo yum update
- Install the MySQL database server software package by running the following command:
sudo yum install mysql-server
- Start the MySQL service and configure it to start automatically on boot.
sudo systemctl start mysqld
sudo systemctl enable mysqld
- Run the MySQL security script to enhance security and set the root password.
sudo mysql_secure_installation
Answer the questions in order according to the prompts, you can choose whether to change the root password, remove anonymous users, or disable remote root login.
- Execute the following command to log in to the MySQL database server:
mysql -u root -p
Login to the MySQL database server using the root password you set in step 4.
- You have the option to create a new database and user to manage your data.
CREATE DATABASE your_database_name;
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost';
FLUSH PRIVILEGES;
- Exit the MySQL session:
exit
You have now successfully installed and configured the MySQL database in CentOS. You can use the following command to connect to the MySQL database server and manage your databases:
mysql -u your_username -p -h localhost your_database_name