mysql command line not working

16,469

Solution 1

Like Khaled said, the "command not found" issue is likely a problem with the path setup. If you try locate mysql and it comes up with something like /opt/lampp/mysql/bin/mysql, then you need to export PATH=$PATH:/opt/lampp/mysql/bin' to get a simple mysql to work. Additionally, you would probably want to add that to your ~/.bash_profile so that it will get reset the next time you login.

As for the socket issue, your my.cnf file will specify where the socket is located. The mysql client binary is going to look in whatever default location it is compiled with. In the case of Fedora, this is /var/lib/mysql/mysql.sock. If that is in an alternate location, you need to specify that alternate location on the commandline with mysql --socket=/path/to/mysql.sock. This file will also not be present if MySQL is not running, so you may want to check ps output ps -efa|grep -i mysql to verify it is running. As a side note, you will also see the "socket=" on the ps output, which is setting where the server is going to write the socket.

Solution 2

You need to locate the Mysql binaries folder and add that path to your $PATH variable. You can use find or locate to search for mysql binaries.

Share:
16,469

Related videos on Youtube

Sandeepan Nath
Author by

Sandeepan Nath

Please answer these questions of mine - Stackoverflow - mysql date time indexes not applying for some specific date ranges How to find the absolute path of a node (file or directory) in this file system model (Interesting question!) Need help? Have some questions that I may answer? Is nobody answering your question? If you feel I may be able to answer any of your questions, mail me the link of your question. My mail ID is sandeepan (dot) nits (at) google's mail. I like trying to answer those questions which are generally skipped by many highly reputated guys here lol. Sometimes they skip them because they don't have time to read long questions. I like attempting such questions and I think that could be my trick to earn reputation. I am also active in many SE sites like programmers.SE, gaming.SE, onstartups.SE, etc. Send me questions!! About me I am a Software Developer/Designer from India. Here is my Brief Résumé on Stackoverflow Careers. Contact me at sandeepan (dot) nits (at) google's mail. Other than programming I have deep interests in Human Psychology, Entrepreneurship, Social work and Scientific Research. While younger I had deep interests in Genetics, Astronomy etc. I love computer games, especially FPS games on multi-player, cricket, music, racing and adventure. I am a 24 years old guy and as time is passing by, I am gradually coming to realize that there are so many things to see and do in this beautiful world. I am afraid that a few years down the line I will repent over so many things I wished to do but could not do. However, I have started serious planning for all this.

Updated on September 17, 2022

Comments

  • Sandeepan Nath
    Sandeepan Nath over 1 year

    I have mysql running in my fedora system. I have xampp setup on the system and php projects present in the webspace are working fine. PhpMyAdmin is working fine. echoing phpinfo() in a PHP script also shows mysql enabled. But running mysql connect command

    mysql -u[username] -p[password]

    Gives this -

    bash: mysql: command not found
    

    How do I fix that? Any pointers?

    I guess I need to do some pointing (define some path in some file) so that my system knows that mysql is installed. What exactly do I have to do?

    Additional Details
    This system was someone else's and he is not available here. May be PHP/Mysql was setup already in the system. I just freshly extracted xampp for linux into /opt/lampp/ and have put all the above mentioned things (PHP projects and PhpMyAdmin) there. After doing that I had a socket problem (PhpMyAdmin was not working and showing this)-

    #2002 - The server is not responding (or the local MySQL server's socket is not correctly configured) 
    

    I restarted lampp using ./lampp restart but problem remained. Then after turning on system today, I started lampp and everything worked just fine. No project issues anymore only command line Mysql not working

    • Philip
      Philip over 13 years
      Is the mysql client installed?? It's possible to install the server without the client.
    • Sandeepan Nath
      Sandeepan Nath over 13 years
      @Chris - how do I check that?
  • Sandeepan Nath
    Sandeepan Nath over 13 years
    Just making it more clear for others - "then you need to export PATH=$PATH:/opt/lampp/mysql/bin" means run this in console.