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:
Step 2: Add the MySQL Yum Repository
Download the MySQL repository RPM package:
- Replace
el7
withel8
for CentOS 8 if needed.
- Replace
Verify the repository is added:
Step 3: Install MySQL Server
Install the MySQL server package:
Step 4: Start and Enable MySQL Service
Start the MySQL service:
Enable the MySQL service to start on boot:
Check the status to ensure it's running:
Step 5: Secure the MySQL Installation
Retrieve the temporary root password generated during installation:
Run the MySQL secure installation script:
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
Log in as the root user:
Enter the root password to access the MySQL prompt.
Step 7: Verify Installation
Check the MySQL version:
Create a test database to confirm functionality:
Step 8: Configure MySQL (Optional)
Edit MySQL Configuration File
The MySQL configuration file is typically located at:
You can modify settings like port, bind-address, and logging options. After making changes, restart the MySQL service:
Step 9: Allow Remote Connections (Optional)
To allow remote access to MySQL:
Open the MySQL configuration file:
Comment out or remove the
bind-address
line:Restart MySQL:
Grant access to remote users:
Open port
3306
in the firewall:
Uninstall MySQL (If Needed)
To remove MySQL completely:
Let me know if you encounter any issues or need additional help!