The method of installing MariaDB or MySQL to CentOS is as follows: 1. Install MariaDB: After updating the system, use yum to install mariadb-server, start the service and run the security initialization script; 2. Install MySQL: Add the official source and then use yum to install mysql-community-server, start the service and view the log to get the temporary password, and then run the security initialization script. MariaDB is the default recommended option, suitable for development and testing environments; MySQL is suitable for scenarios with specific enterprise needs, the community version has limited functions, and the enterprise version requires a fee. Common problems include port conflicts, permission issues, and database status checks, which can be resolved by opening firewall ports, modifying directory permissions, and executing the systemctl or \s command.
Installing MariaDB or MySQL to CentOS is not complicated, but it requires selecting the database type and version according to your specific needs. CentOS itself contains MariaDB in the default repository, while MySQL needs to add an additional official source. Next, I will explain how to operate it in a few steps.
How to install MariaDB
MariaDB is the default database replacement for CentOS, is MySQL-compatible, and is available out of the box.
- Update the system package : Run
sudo yum update
first to ensure that the system is up to date. - Install the MariaDB server : directly use the command
sudo yum install mariadb-server
. - Start and enable the service : start the service with
sudo systemctl start mariadb
, and then usesudo systemctl enable mariadb
to set up the startup. - Run the secure initialization script : execute
sudo mysql_secure_installation
to set the root password, remove anonymous users, etc.
If you just want to quickly build a database environment that is available, MariaDB is the most recommended option, especially for development or testing environments.
Steps to install MySQL
If you want to use real MySQL (such as enterprise projects have specific requirements), you need to manually add the official YUM source of MySQL.
- Download and add MySQL source:
- For example, in MySQL 8.0, you can use the command
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
(note that the link is adjusted according to your CentOS version).
- For example, in MySQL 8.0, you can use the command
- Install the MySQL Community Edition server:
- Use
sudo yum install mysql-community-server
.
- Use
- The startup service and initialization process are similar to MariaDB:
- Start the service:
sudo systemctl start mysqld
- Start the computer automatically:
sudo systemctl enable mysqld
- View temporary password: After the installation is completed, MySQL will generate a temporary root password, which can be found in the log:
sudo grep 'temporary password' /var/log/mysqld.log
- Then run
mysql_secure_installation
to reset your password and other security settings.
- Start the service:
It should be noted that the MySQL Community Edition is different from the Enterprise Edition, and the Community Edition is free but has limited functions. If the project requires high functionality, you can consider the Enterprise version, but that is paid.
Frequently Asked Questions and Solutions
-
Port conflict or inaccessible?
- By default, MySQL/MariaDB uses port 3306 to check whether the firewall opens this port.
- You can add rules with
sudo firewall-cmd --permanent --add-port=3306/tcp
, and then restart the firewall service.
-
Data directory permissions issue?
- If you have modified the data directory location, remember to change the folder permission to
mysql:mysql
, otherwise the service may fail to start.
- If you have modified the data directory location, remember to change the folder permission to
-
How to view the database status?
- Use
systemctl status mysqld
orsystemctl status mariadb
. - After logging in to the database, you can use
\s
to quickly view the current connection status.
- Use
Basically that's it. The installation process of MariaDB and MySQL is similar, and the difference is mainly in source configuration and subsequent management. Which one you choose depends on your project needs and habits.
The above is the detailed content of How to install MariaDB or MySQL on CentOS?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

To migrate from CentOS8 to AlmaLinux or RockyLinux, follow the clear steps. First, choose AlmaLinux (suitable for long-term enterprise support) or RockyLinux (emphasizing exactly the same as RHEL) according to your needs. Secondly, prepare the system environment: update the software package, back up key data, check third-party repositories and disk space. Then, the conversion is automatically completed using the official migration script. RockyLinux needs to clone the repository and run the switch-to-rocky.sh script. AlmaLinux replaces the repository and upgrades with one click through the remote deployment script. Finally, verify system information, clean up residual packets, and update GRUB and ini if ??necessary

To correctly install the local RPM file and handle dependencies, you should first use dnf to install it directly, because it can automatically obtain the required dependencies from the configured repository; if the system does not support dnf, you can use yum's localinstall command instead; if the dependency cannot be resolved, you can manually download and install all related packages; finally, you can also forcefully ignore the dependency installation, but this method is not recommended. 1. Use sudodnfinstall./package-name.rpm to automatically resolve dependencies; 2. If there is no dnf, you can use sudoyumlocalinstall./package-name.rpm; 3. Force installation and execute sudorpm-ivh--nod

AminimalinstallofCentOSisalightweightsetupthatincludesonlyessentialcomponents,makingitidealforserversorsystemsrequiringfullcontrol.Itcontainscoreutilitieslikebash,yum/dnf,networkingtools,andsecuritypackages,whileexcludingdesktopenvironments,webserver

How to set a static IP address using nmcli on CentOS8 or 9? 1. First run the nmcliconnectionshow and ipa commands to view the current network interface and its configuration; 2. Use the nmcliconnectionmodify command to modify the connection configuration, specify parameters such as ipv4.methodmanual, ipv4.addresses (such as 192.168.1.100/24), ipv4.gateway (such as 192.168.1.1), and ipv4.dns (such as 8.8.8.8). 3. Run the nmcliconnectiondown and up commands to restart the connection to make the changes take effect, or

Installing and configuring fail2ban on CentOS is not complicated, it mainly includes the following steps: 1. Install fail2ban using yum; 2. Manually enable and start the service; 3. Create a jail.local file for custom configuration; 4. Set SSH defense rules, including enabling sshd, specifying the blocking time and retry times; 5. Configure firewalld as an action actuator; 6. Regularly check the blocking IP and logs. Fail2ban detects abnormal login behavior through monitoring logs and automatically blocks suspicious IPs. Its core mechanism relies on key parameters such as bantime (banned time), findtime (statistic window time) and maxretry (maximum failure number).

KernelCare and kpatch are both tools for implementing hot patches in the Linux kernel, but the applicable scenarios are different. 1. KernelCare is a commercial service that supports CentOS, RHEL, Ubuntu and Debian, automatically applies patches without restarting, and is suitable for hosting service providers and enterprise production environments; 2. kpatch is an open source tool developed by Red Hat. It is based on the ftrace framework and requires manual construction of patch modules. It is suitable for RHEL and compatible systems, and is suitable for organizations that need to finely control the patch process or use customized kernels. When choosing, automation requirements, system distribution, whether official support is required, and the degree of control over open source tools should be considered. Neither of them can fix all vulnerabilities, some still need to be restarted, and

How to add or remove a service in FirewallD? 1. Add a service: First use firewall-cmd-get-services to view available services, temporarily add --add-service=service name, and permanently add --permanent parameter; 2. Remove service: Use --remove-service=service name to temporarily remove, add --permanent permanently remove, and after modification, all need to perform --reload reload configuration; 3. Custom service: Use --new-service to create a service and edit the XML file to define the port, and then add it according to the standard service. Pay attention to distinguish between temporary and permanent settings during operation, and reload the firewall in time.

The method of installing MariaDB or MySQL to CentOS is as follows: 1. Install MariaDB: After updating the system, use yum to install mariadb-server, start the service and run the security initialization script; 2. Install MySQL: After adding the official source, then use yum to install mysql-community-server, start the service and view the log to get the temporary password, and then run the security initialization script. MariaDB is the default recommended option, suitable for development and testing environments; MySQL is suitable for scenarios with specific enterprise needs, the community version has limited functions, and the enterprise version requires a fee. Frequently asked questions include port conflicts, permission issues, and database status checks, which can be accessed through open firewall ports.
