MAMP: how to use MYSQL from console

I could not access the mysql database from console, getting this error

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ 

So I googled and found this:

http://fischerlaender.de/apple-mac/mac-os-x-trouble-with-mamp-mysql

and I sorted it out using:

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

This will allow you to access through the console and do things such as

mysql -u root …

But now, there is an additional challenge. When I try to use the database through php (launching the console php -a), using sentences to connect such as mysql_connect(DB_HOST, DB_USUARIO, DB_PASSWORD) it will return the error

Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in php shell code on line 1

So, again searching in google, this is the solution: http://stackoverflow.com/questions/4219970/warning-mysql-connect-2002-no-such-file-or-directory-trying-to-connect-vi

sudo mkdir mysql

cd mysql/

sudo ln -s /tmp/mysql.sock mysql.sock

 

 

Advertisements

javascript: how to access the functions from the console

when you are programming and want to test a function of your code inside the console, can you call it directly?

the answer here: http://stackoverflow.com/questions/9354191/calling-custom-functions-from-firebug-console

If the function global scope then it should be fine. If it is inside a function, then it will not work. In my case, I am using $(document).ready ( { function ( …) }); to hold all the code so I cannot. Now I understand why.

Two possible solutions: 

– copy paste the function in the console – may not work..

– or enclose it in this code:

(function() {
    window.myFunction = myFunction;
    function myFunction() {
    }
})();

How to work with the console and github ruby projects

How to work on the console when you have a ruby project you want to try? If you are tweaking the code I believe that gem install … is not the solution.

So, I found a solution here: http://stackoverflow.com/questions/5424905/automatically-load-projects-environment-to-irb

What you can do is 

irb -Iname_of_libfolder -rname_of_rb_file

for example for me that was irb -Ilib -rwp_rpc