简体   繁体   中英

bash: mysql: command not found

I just installed MySQL server and a MySQL Workbench on my new desktop and trying to use MySQL commands in Git Bash

to create some databases locally in folder

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?

PS OS Windows 10 , Node.js installed , server runs fine (I'm able to create databases in workbench).

Please help!

PPS If you need additional information let me know!

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

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.

Approach 1

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

$ 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

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.

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

复制mysql.exe的路径,并将其添加到您计算机的PATH变量中,然后打开git bash并键入

winpty mysql -u root -p

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.

  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

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.php change the host from localhost to 127.0.0.1

Hope this helps

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

  1. You opened the shell before installing MySQL, so therefore the PATH variable 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 PATH environment variable. Add the directory where mysql exists to the PATH variable 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?

如果一切都跟随着这本书mysql无法工作(正如我所尝试的那样),但mysqlsh将完成这项工作。

First make sure that you have installed all the required components.

If not then uninstall the installer only and run installer again. Then install all components if you haven't already.

Now open Windows Terminal or Command Prompt and travel into MySQL server 8.0 's bin directory (ie, C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin ). Run

$ mysql -u root -p
Enter password:

and enter the root password

If it works then the problem was in only PATH Variable/Environment Variable

Add a new variable named MYSQL_HOME in user variables and give path of bin directory of MySQL Server as value in it and also in path variable

Just restart your machine and it should work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM