Access MySQL from Host being on Vagrant

For this all you would need is tunneling/port forwarding from vagrant to mysql.

Being on vagrant machine, figure out what the host ip is, usually netstat would tell you that.
The default being 10.0.2.2 and assuming you have 3306 port on host machine do the following

ssh username@10.0.2.2 -L 3306:127.0.0.1:3306 -N

The above would forward the 3306 [ the one on the left ] to the hosts port. Mind you, you have to use 127.0.0.1 to access your vagrant machine in place of localhost which might not work.

database

Connecting to Vagrant [PuPHPet] MySql from host

Probably here with – I can’t connect to mysql on vagrant machine Yup I have been there

If you are php developer and are using vagrant you would want to use mysql tool to access the vagrant mysql server.

Here is the step by step procedure.

I will assume the PuPHPet configuration
First, get the user which can connect from any host

Log into your vagrant

vagrant ssh

Then open the mysql configuration file

vi /etc/mysql/my.cnf

And update the bind-address part to be 0.0.0.0. This will allow address to be used from any host.
If you want to specifically access from some host only, then put IP over there.

Then being in your vagrant machine run

mysql -uroot -p123

This will be depending on if you have provided a password for root the default on puPHPet would ask password so you would have a password

After this allow root user to access everything from everywhere.. or you can create another user and grant that

mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123';
mysql > FLUSH PRIVILEGES;

Then to make the sql pickup the changes made so far

sudo service mysql restart

Then being on your host machine open your sequel pro – if you are on mac.. or other clients you would use for mysql.

Mysql Host: 127.0.0.1
Mysql user: root
Mysql Password: 123

SSH Host: 127.0.0.1
SSH Username: vagrant – this is the default one
SSH key -> point the key in puphpet/files/dot/ssh/id_rsa
SSH Port: 2222 – this is also the default ssh port forwarding, if you change this change it here too..

See how to Setting up vegrant machine from scratch here

Vagrant running slow sites

Using vagrant and running a website from it looks so slow when you access it form host?
Then you are not alone.
Just enable NFS and you would see an increase on performance.

If you are using puphpet, on your config.yaml file under the synced_folder, set nfs to ‘true’. Otherwise on your Vagrantfile, look for nfs and set that to true.

Guest machine entered an invalid state Vagrant error

I used to use vagrant only at work place. But yesterday I upgraded my mountain lion to maverics and my php | ruby setting was jacked up.
I decided to use vagrant at my home as well and got this error.
It appears that I had an older version of Virtualbox and upgrading that helped the problem in no time.

Happy Vagranting

Points on Oracle MySQL Associate Certification Exam

Certification is one way to keep on top of your expertise. It would help you to communicate easily, meet expectations. When you take certification, it is entirely for your own. No one, specially these days, will take certifications for granted. Still you will go thru a number of interviews and code challenges to show who you are. But, when there are times that all of us are the same colored potato, certification will rescue us by making us a bit bolder than the others.
Also, take the challenge. If you are working on some technology and you think you are expert on it, proof it thru certification.

I took the exam yesterday and it was cool. It was not that difficult to tell the truth. Here are some of my points that would help you if you are thinking to take that exam.

1. Are you a developer who is working on mysql as a backend and have done a number of selects, joins, where statements, group by and havings? How about querty statements like create table, alter table, add index and show databases/table..? If the answer for this questions is ‘Yes’ – congrats my friend, almost you have answered a bit more than half the questions on the exam already.
The exam’s most portion is on DML and DDL. If you have a good hands on those query types all you have to do is to get the grip on the principles behind those. Actually this will help you in general not for the exam only
Like, what are basic blocks of select statements, when do you use indexes, group bys and havings, how are the results of the query be affected? When to use Order by and limit. Practice with a number of queries with real tables..

2. Get this book – MySQL-5-0-Certification-Study-Guide. You will need only this book indeed. Read the part for the developer PartI and read on views, import and export and you will be pretty much set.
Guess what, this book is the same book you will need when you take the MySQL Developer exam I and II, which I am planning to take in the coming couple of weeks.

3. Do the exercises from the book’s CD. it has a concise exercises for each chapter and they are the best. Make sure you cover those before jumping to the exam.

4. Give it at least two weeks. It might depend on how you are prepared, but the more prepared the more walk in the park it would be.

5. Apply the general test rules :) – take a good rest before you sit for the exam, eat appropriately [dont be hungry and don’t be too loaded as well], make sure you visit the bathroom first 😉

*For me applying all those points appropriately, I was able to finish the exam way ahead of the allotted time, and score 94% – which shows those guidelines are good to follow.

Updating Git on Mac showing previous version

Was trying to pull something to github and noticed I was using a bit old Git version.
Then I went to and downloaded for mac.
After installing, I checked if I have the latest version by doing

git --version

and it showed

git version 1.7.4.4

Then I suspected the previous one is not updated and checked which git binary is being used

which git

And it replied as

/usr/bin/git

BINGO!
The new one is being save on another directory – /usr/local/git

Then I checked how my path is setup

echo $PATH

it was something like

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin..

As you can see the poor mac would see the /usr/bin first to check if command binary is inside it and it would continue.. so it was not checking the /usr/local/git..

Just putting the proper path infront of the path would solve the problem

export PATH=/usr/local/git/bin/:/usr/local/sbin/:$PATH

That would fix the problem. In the mean time, doing some cleanup on the existing git files would help also..

flush memcache contents from command line

We all love caching right? We have a bunch of ’em these days: query cache, file cache, page cache..
Ok, memcache.. what if you quickly wanted to flush all the contents of it on the server, just use this:

echo "flush_all" | nc  

An example for local memcache could be:

echo "flush_all" | nc localhost 11211

you would see “OK” on the command prompt after successful clearing of the cache.
happy memcaching! :)

Changes made in new revision of SVN. How to see changes in revision in SVN

Working on SVN? I am sure these days we are on the era of DVCS ( Decentralized Version Control System ) like that of git and mercurial but still, we will be using svn..

To see the changes you made on the current revision vs the previous one, use:

svn diff -r PREV:COMITTED file_name_goes_here

or if you have specific revision numbers then plug them in place of the prev and committed above and it will list the changes you made on that file.

Remove clean outgoing change from mercurial hg

How to clear outgoing change from repository that are listed when you do hg o or hg outgoing

In this case using the hg strip will be the solution.

To use hg strip you need to install the extension mq, to install that:

Assuming you are on ubuntu/linux desto

1. go to /home/USER/

2. open .hgrc

3. under the [extensions] add mq =

Say you have two outgoing changes with revison rev1 and rev2.

If you want to get rid of rev2 then being on the repository do:


hg strip rev2

That would remove the outgoing revision from the repository and you can push only the desired revision change