MySQL is one of the most popular relational database management systems in the world. It is used by millions of websites and applications to store, manage, and retrieve data. If you’re running a CentOS 7 server, you’ll need to know how to install, start, stop, and restart MySQL to keep your database running smoothly. In this guide, we’ll cover everything you need to know.
Prerequisites
Before we begin, there are a few prerequisites you need to meet:
- A CentOS 7 server
- Root or sudo access
- A terminal or SSH client
If you meet these prerequisites, you’re ready to start!
How to Install MySQL on CentOS 7
Step 1: Update Your System
The first step is to update your CentOS 7 system. You can do this by running the following command:
sql
sudo yum update
This command will update all the installed packages on your system to their latest versions.
Step 2: Install the MySQL Server
Once your system is up-to-date, you can proceed with the installation of the MySQL server. You can do this by running the following command:
sudo yum install mysql-server
This command will download and install the MySQL server and its dependencies.
Step 3: Start MySQL
After the installation is complete, you can start the MySQL server by running the following command:
sql
sudo systemctl start mysqld
This command will start the MySQL server and enable it to start automatically on boot.
Step 4: Secure MySQL
The last step is to secure your MySQL installation. You can do this by running the following command:
sudo mysql_secure_installation
This command will launch a script that will prompt you to perform several security-related tasks, such as setting the root password, removing anonymous users, and disabling remote root login.
How to Start MySQL on CentOS 7
If you have already installed MySQL on your CentOS 7 server, you can start it by running the following command:
sql
sudo systemctl start mysqld
This command will start the MySQL server.
How to Stop MySQL on CentOS 7
If you need to stop MySQL on your CentOS 7 server, you can do it with the following command:
arduino
sudo systemctl stop mysqld
This command will stop the MySQL server.
How to Restart MySQL on CentOS 7
If you need to restart MySQL on your CentOS 7 server, you’ll need to stop it first and then start it again. Here’s how:
Step 1: Stop MySQL
You can stop the MySQL server by running the following command:
arduino
sudo systemctl stop mysqld
This command will stop the MySQL server.
Step 2: Start MySQL
You can start the MySQL server again by running the following command:
sql
sudo systemctl start mysqld
This command will start the MySQL server.
How to Configure MySQL on CentOS 7
After you’ve installed MySQL, you may need to configure it to meet your specific needs. Here are a few examples of how to do this:
Change the MySQL Root Password
By default, the MySQL root user has no password. You should set a password to secure your database. You can do this by running the following command:
sudo mysqladmin -u root password NEW_PASSWORD
Replace NEW_PASSWORD
with the desired password
Create a MySQL User
You can create a new MySQL user with the following command:
sql
sudo mysql -u root -p
mysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
Replace username
and password
with the desired values.
Configure MySQL Remote Access
By default, MySQL is configured to listen for connections on the localhost (127.0.0.1) interface only. If you need to access MySQL remotely, you’ll need to modify the bind-address
configuration option. You can do this by following these steps:
Step 1: Open the MySQL configuration file
bash
sudo nano /etc/my.cnf
Step 2: Find the [mysqld]
section and add the following line:
css
bind-address = YOUR_SERVER_IP
Replace YOUR_SERVER_IP
with the IP address of your server.
Step 3: Save and close the file.
When you open the file using the nano
text editor as outlined in Step 1, you should see the contents of the file displayed in the terminal window. To save and close the file after making changes, follow these steps:
Press Ctrl+O
This will prompt you to confirm the filename you want to write to. By default, nano
will suggest the current filename (my.cnf
in this case). If you’re happy with this, simply press Enter
to confirm.
Confirm the filename
If you want to change the filename, you can do so at this prompt by typing the new filename and then pressing Enter
.
Press Ctrl+X
This will close the nano
text editor and return you to the terminal prompt.
At this point, you should have successfully saved and closed the my.cnf
file. You can verify this by checking the timestamp of the file (using the ls -l
command) to confirm that it has been updated since you made changes. If you encounter any issues, you can always repeat the steps above to make further changes and try again.
Step 4: Restart MySQL to apply the changes:
sudo systemctl restart mysqld
Conclusion
In this article, we’ve covered everything you need to know about installing, starting, stopping, and restarting MySQL on CentOS 7. We’ve also gone over some basic configuration options to help you get started. By following these steps, you’ll be able to keep your MySQL database running smoothly and securely.
Expert in Information Technology In addition to general monitoring and notification system administration, I am actively engaged in providing information security, monitoring, and TCP/IP. I spend the most of my time configuring and routing computer networks. Reading and going to comedy concerts are two of my favorite pastimes.