2

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?

  • 1
    What's the error? Secondly, mysql takes several arguments like user, password (where applicable), database, etc. You seem to be missing a number of those. – Allan Jul 4 '18 at 13:42
  • Please add the error message you get so the question can be reopened. – nohillside Jul 4 '18 at 13:52
  • I added the error message, it was in the question title already before. No need to add mysql arguments, as when mysql is recognized, it will report another error. – Paul Vincent Beigang Jul 4 '18 at 14:24
  • 2
    Details are important. If there really are two spaces between found: and mysql in the error message you still had shift/opt/whatever pressed from typing the pipe character when you pressed space. – nohillside Jul 4 '18 at 14:36
5

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

  • 2
    While typing |mysql solves the problem it might be better to get used to relasing shift/opt/whatever after typing the pipe and before typing the space character. – nohillside Jul 4 '18 at 15:39
  • Does that make a character that looks like a space? – pixelomer Jul 4 '18 at 15:41
  • 2
    A real extra space doesn't explain the error message, running cmd1 | cmd2 is perfectly valid shell syntax. And yes, depending on keyboard settings and locale it does. – nohillside Jul 4 '18 at 15:46
  • 2
    I'll edit the answer to give more information. – pixelomer Jul 4 '18 at 15:55
1

Notice the extra space given after the ":" in the first error message. This is because of using the "option space" character instead of a normal space. Your output is similar t the first of these two

[Option Space before first missing command in pipe[1]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .