Setup mysql or mariadb on macos without homebrew

Introduction

Setting up MySQL or MariaDB on macOS Sonoma without using Homebrew or MacPorts can be achieved by manually installing the database software. This tutorial will guide you through the process of installing mysql or mariadb manually on macOS step-by-step:

  • Step 1: Download MySQL or MariaDB First, you need to download the MySQL or MariaDB package for macOS Ventura. Visit the official website of MySQL (https://dev.mysql.com/downloads/mysql/) or MariaDB (https://mariadb.org/download/) and download the macOS version of the software.

  • Step 2: Extract the Downloaded Package Once the package is downloaded, locate it in your Downloads folder or the location where you saved it. Then, extract the contents of the package to a desired location on your macOS Ventura system.

  • Step 3: Rename and Move the Folder After extracting, you will have a folder with the name of the MySQL or MariaDB version. To make it easier to manage, rename the folder to "mysql" or "mariadb" respectively. For example:

    For MySQL:

    mv mysql-8.0.27-macos11-x86_64 mysql

    For MariaDB:

    mv mariadb-10.6.5-macos11-arm64 mariadb

    Next, move the folder to the "Applications" directory for better organization:

    sudo mv mysql /Applications/

    or

    sudo mv mariadb /Applications/
  • Step 4: Configure Environment Variables (Optional) You can set up environment variables to access MySQL or MariaDB from the terminal more easily. Open the Terminal and create or edit the `.bash_profile` file:

    nano ~/.bash_profile

    Add the following lines for MySQL:

    export PATH=$PATH:/Applications/mysql/bin

    Or the following lines for MariaDB:

    export PATH=$PATH:/Applications/mariadb/bin

    Save and exit the text editor (Press `CTRL + X`, then `Y`, then `ENTER`).

    To apply the changes, either restart your Terminal or run the following command:

    source ~/.bash_profile
  • Step 5: Initialize the Database Before you can start using MySQL or MariaDB, you need to initialize the database:

    For MySQL:

    cd /Applications/mysql
    sudo bin/mysqld --initialize --user=_mysql

    For MariaDB:

    cd /Applications/mariadb
    sudo scripts/mysql_install_db --user=_mysql
  • Step 6: Start and Stop the Database Server To start the MySQL or MariaDB server, run the following command:

    For MySQL:

    sudo /Applications/mysql/support-files/mysql.server start

    For MariaDB:

    sudo /Applications/mariadb/bin/mysqld_safe --user=mysql &

    To stop the server, run:

    For MySQL:

    sudo /Applications/mysql/support-files/mysql.server stop

    For MariaDB:

    sudo /Applications/mariadb/bin/mysqladmin -u root -p shutdown
  • Step 7: Connect to MySQL or MariaDB You can now connect to MySQL or MariaDB from the terminal using the `mysql` client:

    For MySQL:

    mysql -u root -p

    For MariaDB:

    mysql -u root -p

    Enter your root password when prompted, and you should now be connected to the MySQL or MariaDB server.

Conclusion

By following this tutorial, you have manually installed MySQL or MariaDB on your macOS Ventura system without using Homebrew or MacPorts. Manually installing the database software allows you to have more control over the installation process. You can now use MySQL or MariaDB to manage databases and build applications on your macOS Ventura machine. Remember to keep your database server secure by setting strong passwords and regularly updating the software.

Copyright © 2024 Kshitij Deota

Latest Build: 20 March 2024