MariaDB is an open-source relational database management system that is a popular alternative to MySQL. It is widely used for its performance, scalability, and reliability. In this comprehensive guide, we will walk you through the steps on how to install MariaDB on Arch Linux.
Table of Contents:
- Update the System
- Install MariaDB
- Secure the Installation
- Start and Enable MariaDB Service
- Create a Database and User
- Connect to MariaDB
- Configure MariaDB for Remote Access
How to Install MariaDB on Arch Linux
Update the System
Before we proceed with the installation, it’s a good idea to update your system. Run the following command to update your Arch Linux system:
sudo pacman -Syu
Install MariaDB on Arch Linux
MariaDB is available in the official Arch Linux repositories. To install it, execute the following command:
sudo pacman -S mariadb
Once the installation is complete, you need to initialize the MariaDB data directory. Run the following command to do so:
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Secure MariaDB Installation
Securing your MariaDB installation is crucial for the overall security of your system. Use the
mysql_secure_installation script to improve the security of your MariaDB server:
This script will guide you through a series of prompts to set a root password, remove anonymous users, disallow remote root login, and remove the test database. Follow the on-screen instructions to complete the process.
Start and Enable MariaDB Service
Now that MariaDB is installed and secured, it’s time to start the service. Run the following command to start MariaDB:
sudo systemctl start mariadb
To make sure MariaDB starts automatically at boot, enable the service using the following command:
sudo systemctl enable mariadb
Create a Database and User
To create a new database and user, first log in to the MariaDB shell:
sudo mariadb -u root -p
Enter the root password you set during the secure installation process. Now, create a new database and user with the following commands:
CREATE DATABASE my_database; CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password'; GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost'; FLUSH PRIVILEGES; EXIT;
my_password with your desired database name, username, and password, respectively.
Connect to MariaDB on Arch Linux
To connect to your newly created database as the new user, run the following command:
mariadb -u my_user -p my_database
Enter the password for
my_user when prompted. You should now be connected to your MariaDB server and ready to execute SQL commands.
Configure MariaDB for Remote Access
By default, MariaDB only allows connections from the local host. If you need to access MariaDB remotely, you must update the configuration file to allow connections from other hosts. Open the MariaDB configuration file with a text editor like Vim or Nano:
sudo vi /etc/mysql/my.cnf
[mysqld] section and add the following line:
bind-address = 0.0.0.0
Save the file and exit the text editor. Restart MariaDB to apply the changes:
sudo systemctl restart mariadb
Now, you need to grant remote access to the user you created earlier. Log in to the MariaDB shell:
sudo mariadb -u root -p
Enter the root password and then run the following commands:
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'%' IDENTIFIED BY 'my_password'; FLUSH PRIVILEGES; EXIT;
my_password with your database name, username, and password, respectively. The
% symbol in
'my_user'@'%' allows connections from any IP address. You can replace it with a specific IP or a range of IPs if you want to restrict access further.
Finally, configure your firewall to allow incoming connections to MariaDB. If you’re using
ufw, run the following command:
sudo ufw allow 3306/tcp
For other firewalls, refer to their respective documentation to open the required port.
Congratulations! You have successfully installed and configured MariaDB on your Arch Linux system. You can now start using MariaDB to manage your databases and take advantage of its powerful features.
If you’re looking to further enhance your Arch Linux setup, consider learning how to install TensorFlow on Arch Linux or how to install Pip on Arch Linux. You can also explore how to install Nginx on Arch Linux or how to set up Apache Web Server on Arch Linux for hosting your websites and applications.