Installing and Running MySQL on Mac

Writing by on Friday, 27 of May , 2016 at 7:35 am

Painful process, but you will need to see what works for you.

Say you’ve done the following:

  • Downloaded the DMG and installed MySQL on your Mac (and it provided you a password)
  • Started it from System Preferences -> MySQL
  • Now you tried different ways to connect to MySQL but are not able to login to localhost
  • So, then you tried brew and it didn’t work. Go ahead and remove mysql from brew
    • sudo brew remove mysql
    • brew cleanup

Now, here’s what worked for me, thanks to the following:


# Start MySQL in Safe Mode
$ sudo /usr/local/mysql/bin/mysqld_safe –skip-grant-tables

# Connect to MySQL as root (without password)
$ sudo /usr/local/mysql/bin/mysql -u root

# Update the password
mysql>use mysql;
mysql>show tables;
mysql> update user set authentication_string=password(‘new_password’) where user=’root’;

# Kill the mysql safe process and start it from System Preferences -> MySQL
alias mysql=’/usr/local/mysql/bin/mysql -uroot -ppassword’

That worked for me and I was able to kill the mysql safe-mode process and connect to MySQL through CLI as well as a GUI like Sequel Pro.

Optionally, to add python drivers that will fail further if the following is not done.

# add this to your $PATH
export PATH=$PATH:/usr/local/mysql/bin

# pip install in the right venv
pip install MySQL-python

Leave a comment

Category: Mac,SQL DB

Connection refused while trying to ssh localhost on Mac

Writing by on Sunday, 15 of May , 2016 at 4:04 am

Although SSH is available on the Mac, you need to enable Remote Login. Otherwise you will see

$ ssh localhost
ssh: connect to host localhost port 22: Connection refused

Good article from StackOverflow describes this

System Preferences -> (under) Internet & Networking -> Sharing -> check Remote Login and select the users

Leave a comment

Category: Mac

Create a new user on EC2 and give sudo privileges

Writing by on Monday, 2 of May , 2016 at 10:00 pm

newhost.compute.internal is the new host you launched
ec2-user is the user created by EC2
newuser is the user you want created and need password-less ssh & sudo privileges
– is newuser’s public key

# Copy newuser’s to the new instance
scp -i ~/.ssh/my.pem ~/.ssh/ ec2-user@newhost.compute.internal:~

# Login to the newhost (and sudo as root)
ssh -i ~/.ssh/my.pem ec2-user@newhost.compute.internal
sudo su –

# add newuser and copy the keys
useradd -c “firstname lastname” newuser
cd /home/newuser
mkdir .ssh
cat /home/ec2-user/ >> .ssh/authorized_keys

# provide right ownership and permissions
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
chown -R newuser:newuser /home/newuser

# give sudo access
vim /etc/sudoers

Leave a comment

Category: AWS

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.