How To Use MySql On Mac

MySql is a very popular relational sql database server software. It is widely used in huge of websites as the database server. This article will tell you how to install MySql database server and GUI client tool on MacOS to make MySql database management easily.

1. Install MySql Database Server On Mac.

  1. Download MySql Server community version for MacOS.
  2. Click the downloaded dmg file to open the MySql server installer package.
    double click mysql installer package to install
  3. Click Next button in the wizard dialog until go to the Change Install Location… dialog, then click Install button to install it.
    change install location before install
  4. After installation, it will display Configure MySQL Server dialog, input root user’s password. And click Finish button to complete MySql server installation.
    insert root user password
  5. Now MySql server has been installed successfully.
    mysql installation successful

2. Start, Stop, Configure MySql Server.

  1. Open MacOS System Preferences.
    mysql is installed in macos system preferences
  2. Click MySQL button to open MySQL configuration dialog. Then you can start, stop and configure MySQL server in it.
    start stop configure mysql server panel

3. Manage MySQL Database With MySQL Workbench.

  1. Download MySQL Workbench community version.
  2. Click the downloaded dmg file to install it.
  3. Open MySQL workbench application.
  4. Connect to the local MySQL database server.
  5. Click the Create a new schema in the connected server button to create a database.
    mysql workbench create database
  6. Input mysql database name and select database character set and collation. Click Apply button to create the database.
    mysql workbench input database name
  7. Right click the Tables item under dev2qa database then click Create Table… menu item to create table.
    mysql workbench create table
  8. Input table name at top text box. Then click table row to add one column, input column name, select datatype and other column options(Primary Key, Not Null, Unique, Auto Increment, Binary etc).
    mysql workbench add table column
  9. Right click user_account table, click Select Rows – Limit 1000 menu item to open edit table data dialog in right panel to insert data into the table.
    add row in mysql db table
READ :   How To Enable Root User Or Change Root Password In MacOS

4. Create MySQL User and Assign Privileges To The User.

  1. Click Users and Privileges menu item in left MySQL workbench panel.
    create mysql user and assign privileges to it
  2. Click Add Account button at the bottom of right panel.
  3. Input user name and password in the new panel.
  4. Click Administrative Roles tab to select related roles and assign them to the newly created MySQL user.
  5. Click Schema Privileges tab to assign MySQL database (schema) privileges to the user by click Add Entry… button. You can select all database, or special database either by matching string pattern or exactly string match.
  6. Then select desired Object Rights, DDL Rights or Other Rights checkboxes at bottom, then click Apply button to apply the selected privileges to the created user.

5. Create Example User Account Table.

In our mysql jdbc examples, we always use a table user_account, so we should create this table use MySQL workbench. Below is the table DDL sql code, you can also run it to create this table.

To execute below DDL code, just click Create a new SQL tab for executing queries button ( open mysql sql command execution window ) at mysql workbench tool bar top left corner to open a sql command execute window, and then copy below code into it. Then click execute button(the first lightning icon mysql execute sql code button) at the top tool bar of the sql window to execute the code.

mysql user_account example table columns

CREATE TABLE `user_account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(100) COLLATE utf8_bin NOT NULL,
`password` varchar(100) COLLATE utf8_bin NOT NULL,
`email` varchar(100) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
(Visited 18 times, 1 visits today)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.