How to Install MySQL on Mac?

how to install mysql on mac

Install MySQL on Mac is an essential skill for developers who work with databases, especially if you’re building applications or websites. While it may seem tricky at first, the installation process is actually straightforward when you follow the right steps. Whether you’re a beginner or a seasoned developer, this guide will walk you through the process of getting MySQL up and running on macOS. By the end, you’ll be able to start managing your databases in no time!

Step 1: Download the MySQL DMG Archive

The first step in installing MySQL on your Mac is to download the MySQL installer. Here’s how:

  1. Go to the official MySQL download page.
  2. Select the macOS platform.
  3. Choose the version that suits your macOS version. Typically, you’ll want to choose the DMG Archive package, which is a disk image file.
  4. Click Download.

Note: You may need to sign up for an Oracle account, but you can also choose the No thanks, just start my download option.

Step 2: Install MySQL

Once you’ve downloaded the DMG file, follow these steps:

  1. Open the DMG File: Locate the downloaded file (usually in your Downloads folder) and double-click it to open the disk image.
  2. Start the Installation Process: In the opened folder, double-click the mysql-<version>-macos10.x-x86_64.pkg file to launch the installer. The MySQL installation wizard will guide you through the process.
  3. Follow the On-Screen Instructions: The installation wizard will ask for a few basic details, like agreeing to the license and choosing the installation destination. Simply follow the prompts, and MySQL will be installed on your Mac.
  4. Complete the Installation: After installation, the installer will show a confirmation screen. Click Close to finish the process.
how to install mysql on mac

Step 3: Start MySQL

Once MySQL is installed, it’s time to start the service. You can do this in several ways:

Option 1: Using the MySQL Preference Pane

MySQL comes with a Preference Pane that allows you to easily start and stop the MySQL server from the macOS System Preferences.

  1. Go to System Preferences on your Mac.
  2. You should see a MySQL option at the bottom of the System Preferences window.
  3. Click on the MySQL icon, and you’ll see an option to Start MySQL Server. Click it to start the server.

Option 2: Using the Terminal

Alternatively, you can start MySQL via the terminal by running the following command:

bashCopysudo /usr/local/mysql/support-files/mysql.server start

This will start the MySQL server.

Step 4: Set Up MySQL

After MySQL is running, you’ll want to configure it. The installation includes a root user account by default. You’ll be asked to set a root password during installation, but if you missed that step, here’s how you can set it manually:

  1. Open Terminal.
  2. To access the MySQL command line, type:bashCopysudo /usr/local/mysql/bin/mysql -u root -p
  3. You’ll be prompted to enter the root password. Enter the password you set earlier (or leave it blank if you haven’t set one yet).
  4. Once logged in, you can create a new user and set up databases. For example, to create a new user:sqlCopyCREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'new_user'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES;

Step 5: Verify the Installation

To ensure MySQL is running properly, you can verify the installation by checking the MySQL version. In Terminal, type the following command:

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

Once you log in, run the following SQL query to check the MySQL version:

sqlCopySELECT VERSION();

This will return the version of MySQL that’s running on your machine, confirming that MySQL is installed correctly.

Step 6: Using MySQL Workbench (Optional)

If you prefer a graphical interface over the command line, you can install MySQL Workbench, which is a GUI tool that makes it easier to interact with MySQL databases.

  1. Download MySQL Workbench from the official MySQL website.
  2. Install MySQL Workbench following the standard macOS installation process.
  3. Open MySQL Workbench and connect to your local MySQL server by entering localhost as the host and the root password you set up.

Step 7: Stopping MySQL

When you’re done with MySQL, you can stop the server in a few ways:

  1. Using System Preferences: Go to System Preferences, click on the MySQL icon, and click Stop MySQL Server.
  2. Using the Terminal: To stop MySQL via the terminal, run the following command:bashCopysudo /usr/local/mysql/support-files/mysql.server stop

Troubleshooting

If you run into any issues during installation, here are a few common problems and solutions:

  1. MySQL Not Starting:
    • Check if another application is using the same port (3306 by default).
    • Try restarting your Mac and running the start command again.
  2. Permission Issues:
    • Make sure you’re using sudo when running commands that require administrative privileges.
  3. MySQL Not Found in Terminal:
    • If Terminal says MySQL is not found, check if you need to add MySQL to your PATH. You can add the MySQL binaries to your PATH by adding the following line to your .bash_profile or .zshrc file:bashCopyexport PATH=$PATH:/usr/local/mysql/bin

Conclusion

Congratulations, you’ve successfully install MySQL on Mac! Whether you’re using the command line or MySQL Workbench, you’re now ready to create, manage, and manipulate databases on your local machine. MySQL is a powerful and flexible tool for any developer, and now that it’s installed, you can dive into all the exciting possibilities it offers.

If you run into any issues, don’t hesitate to refer back to this how to install guide or consult the official MySQL documentation for additional support. Happy coding!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top