Terminal – Fix ‘mysql Command Not Found’ After Pipe

MySQLterminal

I installed mysql with homebrew.

mysql --version
mysql  Ver 8.0.11 for osx10.13 on x86_64 (Homebrew)

and

which mysql
/usr/local/bin/mysql

but when I try to use it after a pipe, I get the following error

unzip -p dump.sql.zip | mysql
zsh: command not found:  mysql

Why is that and how can I fix it?

Best Answer

You have an extra character before mysql that looks like a space, but is not a space. You have to fix that before running the command. This problem occurs when you press the space bar while you are holding the Option key.

$ # Option + Space
$ unzip -p dump.sql.zip | mysql
zsh: command not found:  mysql
$ # Regular Space
$ unzip -p dump.sql.zip | mysql
...
expected output
...

Another example:

$ # Option + Space
$ echo "hi" | less
-bash:  less: command not found
$ # Regular Space
$ echo "hi" | less

hi
(END)

Another option is to eliminate the space after the pipe entirely:

$ echo "hi" |less

hi
(END)

Option+Space = \xc2\xa0 (UTF-8)

Space = Regular Space

Related Question