Mysqldump isn't working: "command not found" - mysql

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.

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.

If you not installed MySql.
Ubuntu
sudo apt update
sudo apt-get install mysql-client

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 ;

Related

mysql command is not found in macOS

I have installed MySQL with .dmg installation file according to the official page. But it returns command not found: mysql when I execute mysql command.
How to fix this issue?
The documentation for MySQL says:
When installing using the package installer, the files are installed into a directory within /usr/local matching the name of the installation version and platform. For example, the installer file mysql-5.7.29-osx10.13-x86_64.dmg installs MySQL into /usr/local/mysql-5.7.29-osx10.13-x86_64/.
Once you verify that there is a bin folder in this directory, you have to make sure that the terminal looks for the MySQL command there. This can be done by executing the following command:
export PATH=$PATH:/usr/local/<my-path>/bin
Adding the following line to .bash_profile worked for me:
export PATH=${PATH}:/usr/local/mysql/bin/
Then either restart the terminal or to apply the changes to an existing session, run:
source ~/.bash_profile
If you had installed mysql#5.7 using brew:
paste/type below command in terminal:
echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> ~/.zshrc
then paste/type:
mysql -u root
boom!!!!
reason: brew files are installed in usr/local/opt
Try this if you have not upgraded your OS and wants to access mysql
instead of -> mysql -u root -p
use -> /usr/local/mysql/bin/mysql -u root -p

Terminal doesnt not recognise mysqld and mysql commands

I am runnin OSX 10.9.5 and while trying to reset my MySQL root pasword I typed this:
sudo mysqld_safe --skip-grant-tables
After being asked for the admin password, I got this error :
sudo: mysqld_safe: command not found
I wrote this in
cd /usr/local/mysql
Also, I have a problem with the sudo command, event though I am logged on the admin account my account, It gives me often permission denied, like using this command for basically the same problem ( reseting my root password )
sudo kill cat /usr/local/mysql/data/rodongi.pid
I then got
cat: /usr/local/mysql/data/rodongi.pid: Permission denied
Password:
After entering the password …
usage: kill [-s signal_name] pid ...
kill -l [exit_status]
kill -signal_name pid ...
kill -signal_number pid ...
I have no idea why
1) I dont have the permission even though I used the sudo command( and another time sudo!! )
2) Why msql-bash doesn't not recognise the mysql and mysqld command ( I also tried in terminal-bash;does not work either)
First problem
You're trying to execute the command mysqld_safe, so that command should be on the PATH where the terminal looks for commands. (You can view these locations by running echo $PATH. The different locations are separated with a colon).
Since you're trying to run a file that is in the local directory you should type ./mysqld_safe to tell the shell that you're giving a path to file, otherwise it'll search for it in the PATH. (You can run the file from anywhere by specifying the full path).
Another solution is to make a symbolic link in /usr/local/bin/ that points to /usr/local/mysql/mysqld_safe` (which is the path to the command if I understood you correctly). That way you can run the command from anywhere because it's in the path the shell is looking for.
Second Problem
The cat command surrounded by backticks is executed by the shell before running the sudo command (If the file was readable for everyone the shell will execute something like: sudo kill 12345).
To run the cat as root you should run this command:
sudo bash -c 'kill `cat /usr/local/mysql/data/rodongi.pid`'
That way, you run bash as root, which in turn runs the kill command, and thus reads the rodongi.pid file as root.

Using MySQL in the command line in OS X - command not found?

I'm trying to get MySQL up and running on my Mac OS X 10.9.5.
I've installed the latest version 5.6.21 of MySQL Community Server. I've gone to system preferences and started the mysql server, then launched terminal and typed this:
/usr/local/mysql/bin/mysql --version
which should return the version. But when I type any of the mysql commands I get command not found.
I've also tried:
sudo mysql_secure_installation
mysql -u root --password=password`
I do have web hosting with MySQL etc installed, but I want to be able to get to grips with it in the command line first.
So there are few places where terminal looks for commands. This places are stored in your $PATH variable. Think of it as a global variable where terminal iterates over to look up for any command. This are usually binaries look how /bin folder is usually referenced.
/bin folder has lots of executable files inside it. Turns out this are command. This different folder locations are stored inside one Global variable i.e. $PATH separated by :
Now usually programs upon installation takes care of updating PATH & telling your terminal that hey i can be all commands inside my bin folder.
Turns out MySql doesn't do it upon install so we manually have to do it.
We do it by following command,
export PATH=$PATH:/usr/local/mysql/bin
If you break it down, export is self explanatory. Think of it as an assignment. So export a variable PATH with value old $PATH concat with new bin i.e. /usr/local/mysql/bin
This way after executing it all the commands inside /usr/local/mysql/bin are available to us.
There is a small catch here. Think of one terminal window as one instance of program and maybe something like $PATH is class variable ( maybe ). Note this is pure assumption. So upon close we lose the new assignment. And if we reopen terminal we won't have access to our command again because last when we exported, it was stored in primary memory which is volatile.
Now we need to have our mysql binaries exported every-time we use terminal. So we have to persist concat in our path.
You might be aware that our terminal using something called dotfiles to load configuration on terminal initialisation. I like to think of it's as sets of thing passed to constructer every-time a new instance of terminal is created ( Again an assumption but close to what it might be doing ). So yes by now you get the point what we are going todo.
.bash_profile is one of the primary known dotfile.
So in following command,
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> ~/.bash_profile
What we are doing is saving result of echo i.e. output string to ~/.bash_profile
So now as we noted above every-time we open terminal or instance of terminal our dotfiles are loaded. So .bash_profile is loaded respectively and export that we appended above is run & thus a our global $PATH gets updated and we get all the commands inside /usr/local/mysql/bin.
P.s.
if you are not running first command export directly but just running second in order to persist it? Than for current running instance of terminal you have to,
source ~/.bash_profile
This tells our terminal to reload that particular file.
That means /usr/local/mysql/bin/mysql is not in the PATH variable..
Either execute /usr/local/mysql/bin/mysql to get your mysql shell,
or type this in your terminal:
PATH=$PATH:/usr/local/mysql/bin
to add that to your PATH variable so you can just run mysql without specifying the path
for me the following commands worked:
$ brew install mysql
$ brew services start mysql
You can just modified the .bash_profile by adding the MySQL $PATH as the following:
export PATH=$PATH:/usr/local/mysql/bin.
I did the following:
1- Open Terminal then $ nano .bash_profile or $ vim .bash_profile
2- Add the following PATH code to the .bash_profile
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/mysql/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
3- Save the file.
4- Refresh Terminal using $ source ~/.bash_profile
5- To verify, type in Terminal $ mysql --version
6- It should print the output something like this:
$ mysql Ver 14.14 Distrib 5.7.17, for macos10.12 (x86_64)
The Terminal is now configured to read the MySQL commands from $PATH which is placed in the .bash_profile .
modify your bash profile as follows
<>$vim ~/.bash_profile
export PATH=/usr/local/mysql/bin:$PATH
Once its saved you can type in mysql to bring mysql prompt in your terminal.
You have to create a symlink to your mysql installation if it is not the most recent version of mysql.
$ brew link --force mysql#5.6
see this post by Alex Todd

How do I create a symbolic link to mysql? (Mac, XAMPP)

I have just installed XAMPP and I went to the command line and typed 'mysql' and I got the following error:
"command not found"
When I specify where mysql is located
"/Applications/XAMPP/xamppfiles/bin/mysql -u root"
it works fine so I'm just wondering how I could create a link so that I don't have to type the full path name each time?
Thanks
You'll want to put it in /usr/bin if you want to be able to type just mysql
ln -s /Applications/XAMPP/xamppfiles/bin/mysql /usr/bin/mysql
ln -s [actual mysql directory] [symlink directory]
i.e.: ln -s /Applications/XAMPP/xamppfiles/bin/mysql /home/user/me/mysql

MYSQL: version libmysqlclient_16 not defined in file libmysqlclient.so.16 with link time reference

When I try to use :
mysqldump -u st -p st mydb > /tmp/st.sql
...to dump the database, the following error happens:
mysqldump: relocation error: mysqldump: symbol _hash_init, version libmysqlclient_16 not defined in file libmysqlclient.so.16 with link time reference
Why? and how to fix that?
Ran into the same problem on debian squeeze when installing gdal1.8.0 from the experimental repository. I am really needing the correct answer on this!
Fixed it in Debian squeeze in the following way:
upgrade apt sources.list:
apt-get install -t unstable libmysqlclient16
When this is done, it works!