24

I want to export my database and i am using this code:

mysqldump -p -u markazo_b markazo_b > /tmp/file.sql

But SSH show this error:

-bash: mysqldump: command not found

How i fix this problem?

8 Answers 8

17

After reading your conversation, I found the solution (for me, at least). It was a permissions issue.

Issuing which mysqldump in the terminal shows /usr/bin/mysqldump.

When I then issue cd /usr/bin/ and afterward mysqldump I receive the same indications you were seeing: mysqldump: command not found.

Inside /usr/bin I then issued sudo mysqldump and received:

Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

Try that and see if it helps.

Edit: too long, didn't read: sudo mysqldump may work. (May be a permissions issue.)

3
  • in short, you may need to use /usr/bin/mysqldump
    – fedmich
    Commented Jan 7, 2015 at 9:19
  • Yes, but I answered in such a manner so that the @okancelik might understand how to find his own particular directory.
    – Tass
    Commented Jan 7, 2015 at 14:19
  • Looking back on this question, I was hasty to agree with you, @fedmich. In short, a person may need to issue sudo mysqldump. My answer was verbose in order to verify the command is available for execution.
    – Tass
    Commented Jan 4, 2016 at 21:56
15

The solution I found is adding MySql's installation directory to PATH

Steps:

  1. Find where MySql is installed
  2. Add the bin directory of MySql installation to PATH

(In the terminal),

locate mysqldump

export PATH=$PATH:MY_SQL_INSTALLATION_DIRECTORY/bin

MY_SQL_INSTALLATION_DIRECTORY is the directory you found by locate mysqldump: Example

export PATH=$PATH:/usr/local/mysql-5.6.23-osx10.8-x86_64/bin
10

You probably don't have the MySQL /bin folder on your PATH. Change to your mysql /bin folder and try the command again.

6
  • Sorry, I dont understand your suggest. Please explain detail, thank you.
    – okancelik
    Commented Jun 21, 2014 at 15:00
  • 1
    Try cd /usr/bin/ then run mysqldump again Commented Jun 21, 2014 at 15:05
  • 1
    The same error. My ssh screen in this picture ; i.hizliresim.com/A2W3jL.jpg
    – okancelik
    Commented Jun 21, 2014 at 15:07
  • 2
    What does which mysqldump tell you? That's the directory you want to be in. Commented Jun 21, 2014 at 15:09
  • 1
    Of course this was my problem. I added export PATH=$PATH:\usr\local\mysql\bin to ~/.profile file, or run PATH=$PATH:\usr\local\mysql\bin in terminal.
    – ako
    Commented Jul 5, 2017 at 11:57
8

For OS X and MAMP (localhost) open Terminal and run

sudo nano ~/.bash_profile

Add the following code (make sure to change the -uroot -proot by the username and password you have for mysql):

alias mysqldump='/Applications/MAMP/Library/bin/mysqldump --host=localhost -uroot -proot'

Once added, Press Ctrl + O to save then Ctrl X to leave the editor, now run on the terminal

mysqldump dbname > dump_name.sql

That worked perfectly for me.

4

My solution: (On windows)
1, Right click to your computer ==> Properties ==> Advanced system settings ==> on tabs "Advanced" click Environments Variables ==> on System variables find "Path" and click "Edit".
2, Finally, you copy your bin folder of your mysql to that.
Ex: D:\LEARN\wamp64\bin\mysql\mysql5.7.14\bin
3, Restart cmd and try your command again.
Nice..

1
  • 1, From the desktop, right click the Computer icon. 2, Choose Properties from the context menu. 3, Click the Advanced system settings link. 4, Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New. 5, In the Edit System Variable (or New System Variable) window, add location of folder mysql/bin to the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK. Ex: my location is D:\LEARN\wamp64\bin\mysql\mysql5.7.14\bin
    – IMc
    Commented May 12, 2017 at 6:55
2

For mac users, look into /usr/local/, this is most likely where mysql is installed. There may be two installations. I chose the one without the version number in the name.

You need to add the path of your mysql installation to your bash profile by adding export PATH=$PATH:/usr/local/mysql/bin to ~/.bash_profile. Can try running PATH=$PATH:/usr/local/mysql/bin if adding export to ~/.bash_profile doesn't work.

0

You are actually trying using git bash, please try CMD xampp/mysql/bin then run

mysqldump -u root -p DbName> name_to_downlaod.sql

0

I just did the following steps and that fixed the issue for me!

1- sudo nano ~/.zshrc 2- Added the following to the file: {export PATH=$PATH:/usr/local/mysql/bin} 3- restart your terminal (not sure this is needed, but I did it to make sure!)

Hope this will fix someone's issue!

Not the answer you're looking for? Browse other questions tagged or ask your own question.