How to install and configure a MySQL database in CentOS?

You can install and configure MySQL database in CentOS by following these steps:

  1. 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
  1. Install the MySQL database server software package by running the following command:
sudo yum install mysql-server
  1. Start the MySQL service and configure it to start automatically on boot.
sudo systemctl start mysqld
sudo systemctl enable mysqld
  1. 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.

  1. 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.

  1. 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;
  1. 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
Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds