Creating MySQL Database on local macOS

Creating MySQL Database on local macOS

1: Download MySQL

by default, macOS uses SQLite database. so you have to download MySQL by yourself.

I strongly recommend using home-brew to install MySQL. You can also install many other packages like Python, jdk etc. with home-brew. So first we use automated script to install home-brew:

/usr/bin/ruby -e "$(curl -fsSL"

Then download MySQL…

brew install mysql

and start service

brew services start mysql

You’ll often need to use above command to open a port at local for incoming connection. It creates a sql service at localhost( on port 3306 by default.

2: Connect to MySQL

Before using MySQL, I recommend you to change your password, but it is not necessary as long as you can ensure your machine’s cyber security.

mysqladmin -u[user] -p[old password] password

mysql command basic format: mysql -u[user] -p[password] -h[host address] [optional database]. Notice that there is no space between options and values, otherwise the program my recognize your password as database name.

By default, mysql’s admin user is root, and it has no password. So you can basically connect to the database by:

mysql -uroot

Or if you are connecting to remote sql server, for example, use:

mysql -uroot -p123123 -h192.168.0.12 my_database

3: Create a new database

mysql>CREATE DATABASE [dbname];
mysql>use [dbname];

Then you can do whatever you want with it :/…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s