How to make MySQL command line works with MAMP? - mysql

I love the conveniences of MAMP e.g. phpMyAdmin so I installed it.
I also installed MySQL via Home Brew because I need MySQL command line (mainly for import and export).
Now entering mysql results in:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
What should I do?

The MAMP mysql socket is located elsewhere. If you installed MAMP and own mysql parallel, you have two instances.
One with MAMP context, which has its binary in
/Applications/MAMP/Library/bin/
Other one depending on your settings during install.
Make sure to start mysql (the one you would like to work with).
You might want to use command line as follows:
/Applications/MAMP/Library/bin/mysql [command goes here]
To access the MAMP mysql server.

Related

Mysql Not Working After El Capitan Upgrade

I recently upgraded my Mac Pro to a Mac Mini and used the migration assistant to transfer all my files and applications across to the Mac Mini.
I also re-installed macports and configured apache etc. So I've managed to get my localhost and php working on the new machine.
However I am now unable to start mysql from terminal?
When I try my usual:
mysql5 -u root -p;
and got the following error:
Error: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)
I've also tried restarting mysql:
sudo opt/local/share/mysql5/mysql/mysql.server restart
and got the following error:
ERROR! Manager of pid-file quit without updating file.
When I navigate to my mysql5 directory /opt/local/var/db/mysql5/ I see a list of my databases, and see the following PID files:
myName.local.pid
and
localhost pid
So the structure is similar to what was on my old Mac but I confused as to what is causing mysql to not start?
Interestingly, mysql must be still working because when I run an .php scripts in my browser the mysql queries work and the data is being retrieved.
Any help much appreciated.
SOLVED
I would like to share the solution that I came across to resolve this issue.
When you update to El Capitan from a previous version of OSX your mysql settings get lost. When you try to connect via:
mysql5 -u root -p;
I was getting the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)
The problem was with my.cnf!
The default configuration of macports mysql does not come with a my.cnf (it does however have others my-medium.cnf, my-small.cnf) so the Macports mysql client is going to look where the Macports server is set to look.
I also learned that if you've changed the socket path away from the default then you need to tell everything where it is. Most programs have a hard coded default that can be overridden, I had overridden the macports default to the one php is compiled to, so you need to tell the client what you've changed it to otherwise how is it supposed to know.
Because I did not have a copy of my.cnf in opt/local/share/mysql5/mysql, the client did not know where to look for the socket. So I had to define the path to the socket in the my.cnf for both the [client] and [mysqld] configurations.
The in my case the path to the socket should have been:
socket = /opt/local/var/run/mysql5/mysqld.sock
I then restarted mysql:
sudo /opt/local/share/mysql5/mysql/mysql.server restart
And SUCCESS at last.
Hope this helps.

Unable to start MySQL Server - 'mysql.sock' missing

I am unable to start MySQL Server on Mac OSx Mountain Lion. This may be because there's no file named as 'mysql.sock' anymore. On running mysql command on terminal i get
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
MySql server was running fine on my machine for a long time before this issue. What could be causing this error ?
Update :
i have tried running mysqld_safe but no use and then running '/usr/local/mysql-5.6.12-osx10.7-x86_64/scripts/mysql_install_db' but this is what i get
FATAL ERROR: Could not find ./bin/my_print_defaults
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

MySQL Error on Mac Lion 10.7

I am trying to make mysql run on mac so I can make it work with rails 3. I installed the mysql*.dmg file from the official website, and I have also added this in my ".bashrc" file:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
PATH=$PATH:/usr/local/mysql/bin
Now I have created a /tmp/mysql.lock file, changed its permission and I still get this error when I am trying to run mysql:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)
Any help installing mysql on Lion?
That's because MySQL is probably creating the socket file somewhere else. Use
mysqladmin variables
in the terminal to find out the exact location and use it in your database.yaml.

Setting up MySQL server on OSX 10.7 (Lion) using Homebrew

I have successfully installed MySQL using Homebrew. However, whenever I type the command mysql I receive this error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I suspect this is a permission problem, as I have confirmed my system is looking for MySQL in the right location. However, I a novice with Unix(OSX) and don't know how to rectify the problem.
I am using OSX 10.7 (Lion)
which mysql produces /usr/local/bin/mysql
When you type 'mysql' you are running the MySQL client. The client needs to communicate with the server. If you simply run 'mysql' without any argument it assumes you are trying to connect to a mysql server that is located on 'localhost' using the user name as the user you are running the command as and without a password.
From the error it seems your server is not running yet. Start it by typing:
mysql.server start

missing mysql.sock after new install

I recently upgraded to a new macbook pro and haven't been able to get mysql to install. I have been trying to install using the:
mysql-5.5.8-osx10.6-x86_64.dmg
which 'should' work for my machine, but is not. After installing the three pieces (mysql.pkg,
startup.pkg, prefpane) I get nothing. Trying to start mySQL through the prefpane freezes sysprefs. Trying to start via the terminal gets this error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
So I deleted all of the mysql install files and reinstalled following these instructions:
https://discussions.apple.com/message/12820394
when I get to the step where I would set up the root password i get the following error:
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
This is perhaps due to the fact that there are no mysql related files in /tmp ? I can't find anything *.sock anywhere on my machine at all. I really don't know much about server admin, so I could be totally confused and off here.
It can have moved to /var/mysql/mysql.sock. I think it is the new position. You may need to point your php.ini to that or create a symbolic link to ln -s /var/mysql/mysql.sock /tmp/mysql.sock...