bash: mysql: 找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44531375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:21:37  来源:igfitidea点击:

bash: mysql: command not found

mysqlwindowsgit-bash

提问by Archie1008

I just installed MySQLserver and a MySQL Workbenchon my new desktop and trying to use MySQL commands in Git Bash

我刚刚在我的新桌面上安装了MySQL服务器和MySQL Workbench,并尝试在Git Bash 中使用 MySQL 命令

to create some databases locally in folder

在文件夹中本地创建一些数据库

C:\Users\OmNom\Desktop\code\burger\db

C:\Users\OmNom\Desktop\code\burger\db

(database file located in this folder)

位于此文件夹中的数据库文件

with

mysql -u root -p

but getting this message in return

但收到这条消息作为回报

bash: mysql: command not found

What am I doing wrong ? Do I have to install something else to make it work?

我究竟做错了什么 ?我是否必须安装其他东西才能使其工作?

P.S.OS Windows 10, Node.jsinstalled , server runs fine (I'm able to create databases in workbench).

PS OS Windows 10,安装了Node.js,服务器运行良好(我能够在工作台中创建数据库)。

Please help!

请帮忙!

P.P.S.If you need additional information let me know!

PPS如果您需要更多信息,请告诉我!

回答by Rubel

Copy the path to mysql.exe, and add it to your computer's PATHvariable, then open git bash and type

复制mysql.exe的路径,并添加到你电脑的PATH变量中,然后打开git bash并输入

winpty mysql -u root -p

回答by vivek agarwal

Following steps installed drush in my windows 7 PC's & laptop seamlessly. Please ignore 1st two steps if you already have a web-server-stack running in your machine.

按照以下步骤在我的 Windows 7 PC 和笔记本电脑中无缝安装了 drush。如果你的机器上已经有一个 web-server-stack 运行,请忽略第一两步。

  1. Install VC11

  2. Install XAMPP-5.6-VC11

  3. Install GIT

  4. Install composer

  5. Install drush using compser in git-bash type: composer global require drush/drush

  6. in bash - navigate to sites folder

  7. check environment by typing following commands in bash one by one

    php --version
    mysql --version
    composer --version
    drush --version
    
  1. 安装 VC11

  2. 安装XAMPP-5.6-VC11

  3. 安装GIT

  4. 安装作曲家

  5. 在 git-bash 类型中使用 compser 安装 drush:composer global require drush/drush

  6. 在 bash 中 - 导航到站点文件夹

  7. 通过在bash中一一键入以下命令来检查环境

    php --version
    mysql --version
    composer --version
    drush --version
    

Incase any of the above commands returns error, make sure to update environment variables accordingly.

如果上述任何命令返回错误,请确保相应地更新环境变量。

Make sure that your environment variables have these entries (depending upon your install location & user name)

确保您的环境变量具有这些条目(取决于您的安装位置和用户名)

C:\Users\Admin\AppData\Roaming\Composer\vendor\bin;
C:\Users\Admin\AppData\Roaming\Composer\vendor\drush\drush\;
C:\Program Files\Git\cmd;C:\ProgramData\ComposerSetup\bin;
C:\xampp\mysql\bin;
C:\xampp\php;
  1. Finally in sites\defalut\settings.phpchange the host from localhostto 127.0.0.1
  1. 最后sites\defalut\settings.php将主机从 更改localhost127.0.0.1

Hope this helps

希望这可以帮助

回答by Syed Ekram Uddin

That's because your MySQL bin program (mysql command tool) not added to your windows PATH system variable.

那是因为您的 MySQL bin 程序(mysql 命令工具)没有添加到您的 Windows PATH 系统变量中。

Now this can happen for several reasons, one particular reason could be your installation executable not run as administrator. So to use it with your git bash you can do two things.

现在发生这种情况的原因有多种,一个特殊原因可能是您的安装可执行文件未以管理员身份运行。因此,要将它与您的 git bash 一起使用,您可以做两件事。

Approach 1

方法一

Go to the bin directory of your MySQL installation using git bash. For example

使用 git bash 转到 MySQL 安装的 bin 目录。例如

$ cd 'C:\Program Files\MySQL\MySQL Server 5.7\bin'

Then run

然后运行

./mysql -u root -p

Approach 2

方法二

To make it easier to invoke MySQL programs, you can add the path name of the MySQL bin directory to your Windows system PATH environment variable. To do so follow the MySQL official documentation guideline from here

为了更容易调用 MySQL 程序,您可以将 MySQL bin 目录的路径名添加到您的 Windows 系统 PATH 环境变量中。为此,请遵循此处的 MySQL 官方文档指南

https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/mysql-installation-windows-path.html

https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/mysql-installation-windows-path.html

After adding the PATH variable you need to restart your git bash.

添加 PATH 变量后,您需要重新启动 git bash。

Now you'll able to run mysql command from anywhere using git bash.

现在您可以使用 git bash 从任何地方运行 mysql 命令。

回答by Tomer Shay

This error means that from some reason your shell doesn't recognize the mysql client. It might be one of the following:

此错误意味着由于某种原因,您的 shell 无法识别 mysql 客户端。它可能是以下情况之一:

  1. You opened the shell before installing MySQL, so therefore the PATHvariable isn't updated on that shell instance. To make sure this is not the case, close the shell and re-open it, try to use the command again.
  2. From some reason the mysql client is not added to the PATHenvironment variable. Add the directory where mysql exists to the PATHvariable using this command, and then try to run the client:

    set PATH=%PATH%;C:\xampp\php
    
  3. Maybe you didn't install MySQL client and only installed the server? Can you find the executable somewhere on your computer?

  1. 您在安装 MySQL 之前打开了 shell,因此该PATH变量不会在该 shell 实例上更新。要确保不是这种情况,请关闭 shell 并重新打开它,再次尝试使用该命令。
  2. 由于某种原因,mysql 客户端没有添加到PATH环境变量中。PATH使用这个命令将mysql所在目录添加到变量中,然后尝试运行客户端:

    set PATH=%PATH%;C:\xampp\php
    
  3. 也许你没有安装 MySQL 客户端,只安装了服务器?你能在你的计算机上的某个地方找到可执行文件吗?

回答by Bjorn Liza

If everything has been followed by the book mysqlwont work (as I have tried) but mysqlshinstead will do the work.

如果一切都遵循了这本书就mysql行不通(正如我所尝试的那样),mysqlsh而是会完成工作。