Image Description

MySql in Arch or other Distros :#

MySQL provides prebuilt .deb packages for Debian and Ubuntu, which can be installed using the APT package manager.

If you’re setting up a database on Arch Linux, you might notice something unexpected β€” MySQL isn’t in the official repositories. Instead, you’ll find MariaDB, a drop-in replacement. So, why does Arch provide MariaDB instead of MySQL? The answer lies in a mix of open-source values, community trust, and long-term sustainability.

Arch’s Philosophy and the Community Preference#

Arch Linux is known for its rolling-release model and a strong emphasis on simplicity and openness. It avoids software with unclear or restrictive licenses whenever possible. Given that MariaDB is licensed under the GNU General Public License (GPL) and developed in the open, it aligns more closely with Arch’s values than Oracle’s MySQL.

πŸ“¦ 1. Download MySQL Binary#

In such cases, you can install MySQL directly from the generic binary tarball provided by Oracle. This method gives you more control over the version and setup, making it ideal for custom or production environments. Below is a step-by-step guide to installing MySQL on Arch Linux using the official binary distribution.

Go to: https://dev.mysql.com/downloads/mysql/
Choose the latest Linux Generic binary (e.g., mysql-8.4.5-linux-glibc2.28-x86_64.tar.xz).

cd ~/Downloads
tar -xvf mysql-8.4.5-linux-glibc2.28-x86_64.tar.xz
sudo mv mysql-8.4.5-linux-glibc2.28-x86_64 /usr/local/mysql

πŸ‘€ 2. Create MySQL User and Group#

sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql

πŸ”§ 3. Set Permissions#

cd /usr/local/mysql
sudo mkdir mysql-files
sudo chown -R mysql:mysql .
sudo chmod 750 mysql-files

πŸ› οΈ 4. Initialize MySQL Data Directory#

sudo ./bin/mysqld --initialize --user=mysql

πŸ” Important: This will output a temporary root password, like:

A temporary password is generated for root@localhost: aB1cDe2FgH!

➑️ Note it down, you’ll need it to log in for the first time.


βš™οΈ 5. Create a MySQL Configuration File#

sudo nano /usr/local/mysql/my.cnf

Paste:

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
pid-file=/usr/local/mysql/data/mysqld.pid
user=mysql

βš™οΈ 6. Create systemd Service#

sudo nano /etc/systemd/system/mysql.service

Paste:

[Unit]
Description=MySQL Community Server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/my.cnf
ExecStop=/usr/local/mysql/bin/mysqladmin shutdown
User=mysql
Group=mysql
TimeoutSec=600
Restart=on-failure

[Install]
WantedBy=multi-user.target

πŸ”„ 7. Enable and Start MySQL#

sudo systemctl daemon-reload
sudo systemctl enable mysql
sudo systemctl start mysql

πŸ” 8. Verify MySQL Is Running#

sudo systemctl status mysql

Expected output: active (running)


πŸ” 9. Log In with Temporary Password and Set New Root Password#

/usr/local/mysql/bin/mysql -u root -p

πŸ”‘ Enter the temporary password from step 4.

Then run:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_secure_password';

βœ… Now you have full access with your new password.


πŸ›‘οΈ 10. Optional: Run Secure Installation Script#

sudo /usr/local/mysql/bin/mysql_secure_installation

This will:

  • Remove anonymous users
  • Disallow remote root login
  • Remove test database
  • Reload privilege tables

🧠 Tip: Add MySQL to Your PATH#

To avoid typing full paths every time:

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bashrc
source ~/.bashrc