Install MySQL CentOS

Install MySQL CentOS

How to Install MySQL on CentOS

Installing MySQL on CentOS is a straightforward process. Follow these steps to set up MySQL on CentOS 7 or CentOS 8.


Step 1: Update the System

Update the package repository to ensure you have the latest information:

sudo yum update -y

Step 2: Add the MySQL Yum Repository

  1. Download the MySQL repository RPM package:

    sudo yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
    • Replace el7 with el8 for CentOS 8 if needed.
  2. Verify the repository is added:

    yum repolist all | grep mysql

Step 3: Install MySQL Server

Install the MySQL server package:

sudo yum install -y mysql-community-server

Step 4: Start and Enable MySQL Service

  1. Start the MySQL service:

    sudo systemctl start mysqld
  2. Enable the MySQL service to start on boot:

    sudo systemctl enable mysqld
  3. Check the status to ensure it's running:

    sudo systemctl status mysqld

Step 5: Secure the MySQL Installation

  1. Retrieve the temporary root password generated during installation:

    sudo grep 'temporary password' /var/log/mysqld.log
  2. Run the MySQL secure installation script:

    sudo mysql_secure_installation

    During this process:

    • Enter the temporary root password.
    • Set a new root password.
    • Answer the prompts to remove anonymous users, disable remote root login, and remove the test database.

Step 6: Log in to MySQL

  1. Log in as the root user:

    mysql -u root -p
  2. Enter the root password to access the MySQL prompt.

Step 7: Verify Installation

  1. Check the MySQL version:

    mysql --version
  2. Create a test database to confirm functionality:

    CREATE DATABASE test_db; SHOW DATABASES;

Step 8: Configure MySQL (Optional)

Edit MySQL Configuration File

The MySQL configuration file is typically located at:

/etc/my.cnf

You can modify settings like port, bind-address, and logging options. After making changes, restart the MySQL service:

sudo systemctl restart mysqld

Step 9: Allow Remote Connections (Optional)

To allow remote access to MySQL:

  1. Open the MySQL configuration file:

    sudo nano /etc/my.cnf
  2. Comment out or remove the bind-address line:

    # bind-address = 127.0.0.1
  3. Restart MySQL:

    sudo systemctl restart mysqld
  4. Grant access to remote users:

    GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
  5. Open port 3306 in the firewall:

    sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent sudo firewall-cmd --reload

Uninstall MySQL (If Needed)

To remove MySQL completely:

sudo yum remove mysql-community-server mysql-community-client mysql-community-common mysql-community-libs sudo rm -rf /var/lib/mysql sudo rm -rf /etc/my.cnf

Let me know if you encounter any issues or need additional help!

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close