Mysql Catalina

As you might know, the MySQL Community Edition is available for macOS. Usually, I install MySQL server on Linux server but this time, I want to try it on my Hackintosh macOS Catalina. Steps to Install MySQL Server on macOS Catalina Step 1. Download the MySQL Server installation package. Navigate to the following link to download your copy of. Note: This post assumes you followed installing Apache, PHP, and MySQL on Mac OS X Mojave and have since upgraded to macOS Catalina. If you did not follow the original post, you should follow installing Apache, PHP, and MySQL on macOS Catalina. When Mac OS X upgrades it overwrites previous configuration files.

What is MySQL Workbench?

MySQL Workbench is a GUI tool to manage your database. You can see the tables, records in the table, you can create a new schema, query, etc.

If you are more of a visual person who needs to deal with database (MySQL), MySQL Workbench is a very powerful and useful tool.

Before Installing MySQL Workbench on macOS

Before installing the MySQL Workbench, make sure you have access to the database. It is either db in your local system or it could be a remote database in your hosting server or even cloud database such as AWS RDS.

In this post, I will be using local MySQL server as an example. Please check out this post on installing MySQL server on your Mac.

Installing MySQL Workbench on macOS

Go to https://dev.mysql.com/downloads/workbench/

Click Download to get the DMG installer

Once Installer is downloaded, double click the installer. When you double clicked, you should see the screen like below. Follow the instruction to drag the MySQL Workbench icon to the Application folder to complete the installation of MySQL Workbench into your system.

Launching the MySQL Workbench App

Once the MySQL Workbench is installed and when you try to open the app, you might see the message like below. Press Open to proceed on launching the application.

Once the start up screen shows up, you will see a connection already added (assuming you have installed local MySQL server)

Click the Local instance 3306. It will ask for the password. Enter the password you entered when you set up the local MySQL server and press OK. (You can check the Save password in keychain. In this way you do not need to type the password every time you access to your database)

Creating the Schema

Now you have access to your local database server (MySQL server). You can start creating your own database. Schema is the main container of database where you put the tables. Let’s try to create a schema. Click the Create New Schema icon (highlight in below screenshot)

Assign some name on your new schema. In this example, let’s use test_db as a schema name and press Apply.

You will see a dialog box to review the SQL Script to execute by an app. Basically, it will execute an SQL statement of CREATE SCHEMA `test_db`;

Press Apply to create a new schema.

Select Schemas tab and verify the new schema is added.

Creating the Table

Once schema is created, you need to create a table to actually store the data in the “database”.

Expand the test_db schema and right click on the table.

Select Create Table...

Start entering values in the column section. This will be the identifier for the specific field in the database.

Enter the following entities in the table.

PK - Primary Key. Usually the “id” will be your primary key.

NN - Not Null. For entities, you don’t not want to have Null value (empty value) by the time the record is inserted. Put check on this if there is a specific entity you want have some value on it. For example, id entity must have a value always. So for id, put check on NN.

UQ - Unique. If the record entered in the table needs to be unique, put check on this. For example, “id” must be unique so that when you query for specific id, it will only return 1 result.

BIN - Binary

UN - Unsigned

ZF - ZeroFill

AI - Auto Increment. For values you want to automatically increment, put check on this. Typically id should have auto increment on. So every time there is a new record added, the id value will auto increment.

G - Generated

Press Apply and you will the above confirmation. Press Apply again to add some records in your table.

Go to your schema, and expand the table. You should be able to see the table you just created.

Access to the Table

To view the table you created, go to the table you created.

Right click and select Select Rows - Limit 1000

At this point, the table has 0 record. This is expected since the table has just created.

Adding Sample Records

Once you have your table opened, you can directly add some records to it by simply double click the columns. Try entering the following records as an example and press Apply.

Press Apply to confirm the records you want to add in the table.
Note: You can leave the id column blank since this column is set to auto increment. It will automatically assign value as a new record is added.

Now you can see there are 2 records added in your table. You can see the id is automatically added in ascending value.

If you are using Big Sur on Apple’s new Silicon M1, checkout Using MySQL Workbench on macOS Big Sur blog post.

Latest Posts

PREREQUISITES:


In order to follow this guide, you should have a Mac computer with the Catalina OS installed.

I was using for several years MAMP, Fywheel, as well as package managers like brew, and all work pretty well, but why not using the preinstalled Apache and PHP that is shipped in almost all macOS?

In this tutorial, I will show you how to setup/install Apache, PHP, and MySQL on macOS Catalina.

Open the Terminal app and switch to the root user so you can run the commands in this post without any permission issues:

Enable Apache on macOS

Check if works by accessing:
http://localhost

Enable PHP for Apache

First, let’s make a backup of the default Apache configuration


Edit the Apache configuration


Uncomment the following line

Restart Apache:


You can verify PHP is enabled by creating a phpinfo() page in your DocumentRoot.

The default DocumentRoot for macOS Catalina is /Library/WebServer/Documents. In order to verify this, we run the command below to find out our Apache configuration.


Create the phpinfo() page in your DocumentRoot:

Verify PHP by accessing http://localhost/phpinfo.php

Mysql

Customizing PHP settings (php.ini)

MacOS’ PHP uses a default php.ini file based on /private/etc/php.ini.default.
To customize your PHP environment, if a php.ini file doesn’t already exist at /private/etc/php.ini, copy the default template to create a main php.ini file:

Make any changes you wish to php.ini and restart apache to reload all configuration files:

If you were to run phpinfo() in a PHP file from the web server, you should now see that the Loaded Configuration File property now has the value /etc/php.ini.

A very common tweak to the default PHP configuration is to allow larger file upload sizes. The post_max_size and upload_max_filesize properties are only a few megs by default. These limits can be raised as you see fit.

Many developers also tweak the max_execution_time, max_input_time, and memory_limit settings depending on their project.

Always remember to restart apache after making changes to your PHP configuration.

Install MySQL on macOS Catalina

Download and install the latest MySQL version for your macOS.


Setup
Open a new terminal and run the code below this will update the mysql path on your ~/.profile


Please run mysql_secure_installation to make your MySQL secured

Recommended setup:
Strong Password? Yes
Change the root password? Yes
Remove anonymous users? yes
Disallow root login remotely? Yes
Remove test database? Yes
Reload privileges tables now? Yes

We can set a command shortcut for mysql:

Now, to access mysql console, we can run below short command:


Useful mysql commands

Connect PHP and MySQL

Create symlink to ensure PHP and MySQL can communicate each other.

Edited my Apache Configuration:


Uncommented the following lines

Brew

Virtual Hosts

Edit the Apache configuration file:


Add the below line after this included #Include /private/etc/apache2/extra/httpd-vhosts.conf


Create the apache2 vhosts directory.


Create the default virtual host configuration file.


Add the following configuration:


The default virtual host was created for when the Apache web server can’t find a virtual host, it will use this configuration. By prefixing this file with an underscore, Apache will include it first.

Now we can create our first virtual host. The example below contains the virtual host configuration for my test site.

Create the virtual host configuration file:


Add the following configuration:

This VirtualHost configuration allows me to access my site from http://nuno-test.test for local development.


The final step is to restart Apache:


Test our apache configuration/strong>

Start, Stop, Restart and test Apache server config


I know it is a little bit daunting but I promise that we’ll never come back to this nasty lengthy configuration file again. Four simple commands are everything that we need to remember from now on. Start, stop, restart and configuration test.

Mapping our vhosts on macOS hosts file


Add your virtual host to the bottom of the file. It should match the value you used for the ServerName configuration.


Flush macOS DNS cache:

Permissions

You may receive 403 Forbidden when you visit your local site. This is likely a permissions issue. Simply put, the Apache user (_www) group (_www) needs to have access to read, and sometimes write, to your web directory.

Conclusion

Mysql Catalina Download

By using the macOS preinstalled Apache and PHP we can avoid installing extra software on our macOS which sometimes could lead us to conflicts/errors/miss configuration on our Mac Operating system.