21

The following link at the end of the post was helpful, but can someone clarify this? There are two answers that are in complete conflict, so I am asking about it.

One person responds that you should get to the MySQL command line like this.

Navigate to the directory

/usr/local/mysql/bin

And at a Unix prompt, type:

./mysql

Then type the following to reset the password.

mysql -u root -p

But then another person says:

No, you should run mysql -u root -p in bash, not at the MySQL command-line. If you are in mysql, you can exit by typing exit.

Neither of these work for me.

First method. From the Bash prompt:

mysql -u root -p

Enter password:  xxxx
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Second method from the mysql> prompt:

mysql> -u root -p
    ->

I also often get this error:

-bash command not found

I am unable to log in to phpMyAdmin.

My problem is that I am getting this error message when trying to log in to phpMyAdmin:

Login without a password is forbidden by configuration

The link that I have is referenced above. Responses from 2013:

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'db'

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
iHaveAQuestion
  • 301
  • 2
  • 5
  • 14
  • These are the first sentences of instructions "On Unix, use the following procedure to reset the password for all MySQL root accounts. The instructions assume that you will start the server so that it runs using the Unix login account that you normally use for running the server". Start the server. Which server ? The apache server ? I just open terminal and apache is running anyway that is unless I one apachectl stop. – iHaveAQuestion Mar 14 '14 at 17:36
  • possible duplicate of [can't access mysql from command line mac](http://stackoverflow.com/questions/8195418/cant-access-mysql-from-command-line-mac) – kishanio Aug 15 '15 at 13:23

4 Answers4

51

To use the command, i.e., mysql on a MacBook terminal, you need to export the path using:

export PATH=$PATH:/usr/local/mysql/bin/

Considering the default installation, use the following command to get the mysql prompt as the root user:

mysql -u root

Otherwise you are using the wrong root password.

Reference: Setting the MySQL root user password on OS X

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
panther_
  • 514
  • 3
  • 3
  • Thankyou Panther. I had gotten past that problem but today logged on about something else. I am keeping your above posted suggestions. They seem very logical of course :) – iHaveAQuestion Apr 29 '14 at 15:37
  • The above can solve the -13 error from child_process.spawn in node as well. (I had added what I thought was needed in the path... it worked for my login but did not work for node). – MER Oct 28 '20 at 22:56
7

For a permanent solution -

  1. echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile

  2. . ~/.bash_profile

Refer to details at this link.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dan
  • 93
  • 1
  • 5
1

You can permanently add PATH to your ~/.bash_profile file by the following. This will save you to run the export command every time you reopen the console or terminal.

  1. Open the ~/.bash_profile file using

    sudo nano ~/.bash_profile
    
  2. Add the following line there

    export PATH=$PATH:/usr/local/mysql/bin/
    
  3. Save and exit the file and refresh the ~/.bash_profile file

    source ~/.bash_profile
    
  4. Enjoy

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Ahmad
  • 413
  • 5
  • 12
0

I am not sure whether it is connected, but you might give it a try. It could be that you simply need MySQL on your local computer.

On your computer, run:

sudo apt-get update && sudo apt-get install mysql-server

Then you will get rid of such an error. I am not sure whether it is one of the errors you mean in the title "MySQL command line '-bash command not found'":

/home/.../some_bash_script.sh: line 123: mysql: command not found

With some luck, other errors that you get are connected to this. At least in my case, I got rid of a few other errors with this step, like ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
questionto42
  • 7,175
  • 4
  • 57
  • 90