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:

  • https://www.variphy.com/support/knowledge-base/mac-os-x-reset-mysql-root-password
  • http://stackoverflow.com/questions/30692812/mysql-user-db-does-not-have-password-columns-installing-mysql-on-osx

# 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

Assumptions:
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
– id_rsa.pub is newuser’s public key

# Copy newuser’s id_rsa.pub to the new instance
scp -i ~/.ssh/my.pem ~/.ssh/id_rsa.pub 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/newuser.pub >> .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
newuser ALL=(ALL:ALL) NOPASSWD:ALL

Leave a comment

Category: AWS

Determine size of an S3 bucket or folder

Writing by on Wednesday, 16 of March , 2016 at 6:01 pm

Ensure that you have awscli installed as well as your keys setup in ~/.aws/credentials

To determine the size of an S3 Bucket or a folder, you can summarize the output as follows.

aws s3 ls –summarize –human-readable –recursive s3://mybucket/directory/

2015-03-05 19:57:33 71 Bytes directory/sub1/sub2/file.gz

Total Objects: 71
Total Size: 81.9 MiB

To determine the size of an S3 Bucket, you can also use s3api list-objects as shown below.

aws s3api list-objects –bucket mybucket –output json –query “[sum(Contents[].Size), length(Contents[])]”
[
351885203186,
4668
]

For more info refer to ServerFault

Leave a comment

Category: AWS

Recover a corrupted gz

Writing by on Wednesday, 14 of October , 2015 at 7:13 am

Sometimes you might be able to salvage a corrupted gzip. Typically this trick always works on most log files.

$ gunzip corrupted.gz
gunzip: corrupted.gz: unexpected end of file
gunzip: corrupted.gz: uncompress failed

Use the -c option that outputs to console, but redirect to a new salvaged file. Then gzip the salvaged file to recover it.

$ gunzip -c corrupted.gz > salvaged
$ gzip salvaged

You can now delete the corrupted gz file and use the salvaged version.

Leave a comment

Category: Linux,Tips and Tricks

Backpacking Grand Canyon Rim to Rim

Writing by on Monday, 12 of October , 2015 at 8:47 pm

On Thu Oct 8, 2015 my wife and I set out on the grandest hike from the South Rim to North Rim of the Grand Canyon. It was a 3 day hike with 2 stops at Bright Angel and Cottonwood campgrounds. It was an amazing experience and a remarkable hike with spectacular views throughout. We had our camping permits and reservations at Yavapai Lodge on Wed Oct 7 and Sat Oct 10. So couple of friends, my wife and I flew from San Jose to Flagstaff on Wed Oct 7 and rented a car and reached the Grand Canyon National Park around 14:00. We checked into Yavapai Lodge stretched out a bit and went straight to the visitors center and spent some time at Mather Point for our first view of the Grand Canyon in all its glory. After an hour we took a shuttle and went to Hopi Point to see the Sunset. We stopped by Bright Angel Lodge for a beer and our last real meal before our hike. Headed back to the lodge and went to bed. It was chilly night and we were anxious.

Thu Oct 8, 2015. GOAL: Reach the bottom (7 miles) by 14:00, set camp and Phantom Ranch for beer.
Backpacks packed. Check out of Yavapai Lodge. Extra stuff in the car. Quick breakfast at Yavapai Lodge Canyon Cafe and we were on the shuttle to South Kaibab Trailhead. Took some photos with friends and bid them farewell until Saturday night! At 09:45 the descent had started and marked the start of a fabulous journey through the Canyon. Instantly we were welcomed with spectacular views of the Canyon. First stop Ooh Aah Point for photos. We continued and waited for a mule train to pass when I asked the Rangers if they had stocked enough supply of Beer – Affirmative. Awesome! Next stop Cedar Ridge. Stretched out a little and we were off. We went passed Skeleton Point and stopped for lunch (PBJ sandwich) when we saw two mule trains. Tip Off Point was next and what seemed to be 1.4 miles felt a lot longer and we were starting to get weary. Finally we saw the Colorado River and gave us glimmer of reaching our goal. We crossed the bridge and made it to Bright Angel Campground around 14:00. It was hot – 90F. Picked a campsite by the creek, set camp and went to Phantom Ranch which felt like a long walk in the sun. Phantom Ranch closes at 16:00 and reopens at 20:00. The mules stock the supplies there. We were lucky there was one Steak Dinner and one Veg Dinner slot available. Reserved! After beer and lemonade, we went back to camp and freshened up at the creek and went back for Dinner and then the Ranger program at 19:30 and called it a night!

Fri Oct 9, 2015. GOAL: Reach Cottonwood by 14:00 and set camp.
Granola Blueberries for breakfast. Broke Camp at 08:00 and we were on our way at 08:15.
A beautiful easy 3 hour hike on the North Kaibab Trail through the valley along the creek with picturesque views takes you towards Ribbon Falls. The sun shines bright and it gets hotter and we’re at the Fork – Ribbon Falls or Cottonwood Campground. After some arguing with the wife (who typically always wins), she made us walk towards Ribbon Falls with our backpacks. We crossed the bridge and somehow found it although the trail seemed sequestered. There she went up the falls while I stayed at the bottom grouchy as I washed my face with the cold water from the falls. Around 13:00 we left for Cottonwood as the trail started getting steeper and the sun getting hotter. After what seemed terribly long with temps hitting the upper 90s, we arrived at 14:20. We picked a campsite (the few shady sites were taken) and made lunch (Backpackers Pantry) Pad-Thai! Then cooled off near the river. I had to just jump in. Washed my t-shirt and left it to dry. We hung out at the picnic tables to cool off and get some shade from the sun. Made dinner (Chana Masala) and desert (Raspberry Crumble) at 17:30 set our alarms and went to bed by 19:00. We had an early start the next morning.

Sat Oct 10, 2015. GOAL: Start at Dawn. Reach Trailhead by 12:30 and look for Trans Canyon Shuttle.
We were awake by 04:00 even before the alarms went off. Mentally preparing ourselves for the 7 mile climb up the North Kaibab Trail we stumbled out by 04:45. Made breakfast and broke camp at 05:45, used the toilets freshened up and we were on our way at 06:15. We had to get up before 14:00 when the Trans Canyon Shuttle left North Rim for South Rim and my wife knew she wouldn’t win with any pit stops at Roaring Springs today. We hurried past Pumphouse Ranger Station which arrived at 06:50 sooner than anticipated and then came to the Roaring Springs fork. We were making good progress but trail wasn’t all that steep yet. We skipped Roaring Springs (we had water) and continued on the trail as the sun was rising past the walls of the Canyon. The trail was getting steep and fatigue began to settle in. We were going to take a break at Supai Tunnel but it seemed like an eternity. Nowhere in site, we passed the bridge and carried on each step getting us closer. We rested for a bit and continued and finally saw a tunnel. Voila! We were at Supai Tunnel at 09:30 and took off our heavy packs and just sat resting, eating and drinking water. At 10:05 we were going for the final push 1.7 miles to the finish. The match was in the fifth set! We were making our way through the unforgiving steps of North Kaibab where the backpack seems to get heavier with every step and the mind starts playing games. Then we were greeted by Coconino Overlook a magnificient view of the South Rim and the beautiful canyon where we rested for photos. At 10:50 we left for the trail head and finally after weathering through, our legs weary, our feet blistery, we reached the trail-head at 11:25. We had done it! The Grandest Hike! We spent some time there recuperating and then with no sign of any Park Shuttles we walked to the Campground and then got a beer and took a shuttle to Grand Canyon Lodge at the North Rim. We ate at the deli and took the Trans Canyon Shuttle back to South Rim and checked in at Yavapai Lodge at 19:00. After a well deserved good shower we met our friends at the Grand Canyon Cafe at Yavapai Lodge for Dinner to share stories of our grand experience.

Final Comments
Pack that backpack carefully. Take only what you will need. Ask for the weather report at Phantom Ranch & Cottonwood at your lodge. We took 2 jackets and thermals that we didn’t need. We didn’t need the water filter and carried more food/snacks than necessary. In the end, to witness the magnificent natural wonder up close and personal and a tremendous sense of accomplishment this makes it one of the grandest hikes of all time!

Leave a comment

Category: Travel

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.