FranzGoogle
FranzGoogle

Reputation: 481

Mysqldump isn't working: "command not found"

I have to export a database from the command line. I tried using this command:

mysqldump -u root -p db_name > backup.sql

But it returns this error:

-bash: mysqldump: command not found

After this, I also tried with

sudo mysqldump

but the error is the same.

I'm at the beginning and I'm not very good at it at the moment. If I have to work on directory, please be clear because I'm not confident with the terminal.

Upvotes: 14

Views: 40748

Answers (3)

Kairat Koibagarov
Kairat Koibagarov

Reputation: 1485

If you not installed MySql.
Ubuntu

sudo apt update
sudo apt-get install mysql-client

Upvotes: 7

Reece Daniels
Reece Daniels

Reputation: 1207

Add a semi-colon to the end of your command, it could make all the difference. I was getting the same error and that fixed it for me.

I'd also suggest declaring everything explicitly in the command you're running. The following worked for me:

1) Find the direct path to your mysqldump file. Check usr/local/mysql/bin/mysqldump if installed using MySQL Server DMG, or if you're using homebrew check in usr/local/Cellar/mysql... (even just do a spotlight search for it).

2) Create a folder to dump the backup to. I made mine ~/dumps.

3) Tie it all together, ensuring you have a semi-colon at the end!

/usr/local/mysql/bin/mysqldump -u root -p db_name > ~/dumps/db_name.sql ;

Upvotes: 1

Daniel
Daniel

Reputation: 103

If you have the latest mysql installation in El Capitan, the mysqldump executable should be in the /usr/local/mysql/bin directory. In order to use it, you can either run /usr/local/mysql/bin/mysqldump directly, create a symlink, or add the whole bin directory to your path, so you can use any of the executable files without typing the full path.

As suggested below, you can easily make a symlink in your /usr/bin directory, which should already be in your path, by running this command: ln -s /usr/bin/mysqldump /usr/local/mysql/bin/mysqldump

That command should create a link called mysqldump in your /usr/bin directory, which will redirect to the full path of the mysqldump program.

If you would rather add the entire mysql library of tools, all at once, you can follow this guide: https://coolestguidesontheplanet.com/add-shell-path-osx/ and learn how to add new directories to your path.

Upvotes: 9

Related Questions