Mac : Installing Mysql on mac using brew

Look, if you just want to try out mysql only for learning then there is not need for local installation, you can try it out free at this site :

If you want to install Mysql on you mac machine then follow below steps :

  1. Install mysql with brew install mysql
  2. Start mysql with mysql.server start
  3. Connect mysql with mysql -uroot 
  4. Stop mysql with mysql.server stop


Note :

To have launchd start mysql at login:

  ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents

Then to load mysql now:

  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Or, if you don’t want/need launchctl, you can just run:

$   mysql.server start

$ mysql -uroot

mysql.server stop

Once Mysql is installed you can check port number using below command



| Variable_name | Value |


| port          | 3306  |


1 row in set (0.00 sec)

How to execute/import JS file in Mongo Shell

You can write your code, json or logic in the javascript file and load it simply using load() method which takes absolute and relative path.

There are 2 ways :

#1 When you are in mongo shell use load and keep file in script folder

#2 When you are in terminal and want to load and connect to mongo shell
➜ mongo --shell myDatabaseName /Users/asee2278/myFile.js

MongoDB shell version: 3.0.6 connecting to:myDatabaseName
type “help” for help
> obj { “name” : “aseem” } >

Note : Please make sure to put only Js and not mongo commands other wise import might fail with message : E QUERY Error: error loading js file Another way is to file it from bash

bash$ mongo localhost:27017/test myjsfile.js

What does "MUL" mean in MySQL for the key?

In any case, there are three possible values for the “Key” attribute:

  1. PRI
  2. UNI
  3. MUL

The meaning of PRI and UNI are quite clear:

  • PRI=> primary key
  • UNI=> unique key

The third possibility, MUL, (which you asked about) is basically an index that is neither a primary key nor a unique key. The name comes from “multiple” because multiple occurences of the same value are allowed. Straight from the MySQL documentation:

“If Key is MUL, the column is the first column of a nonunique index in which multiple occurrences of a given value are permitted within the column.”

There is also a final caveat:

“If more than one of the Key values applies to a given column of a table, Key displays the one with the highest priority, in the order PRI, UNI, MUL.”

As a general note, the MySQL documentation is quite good. When in doubt, check it out!