I have a strange issue. On my PC with Linux Mint 17 I can access mysql just by typing mysql in the terminal, but on my laptop (with Ubuntu 15.04) I have to type each time /opt/lampp/bin/mysql (both have the latest XAMPP version installed).
So my question is: how to make mysql "global" and accessible by just typing "mysql"?
You need to add /opt/lampp/bin/ to your $PATH so that the system can find the binary file.
From the command line enter:
PATH=$PATH:/opt/lampp/bin
+1 for doublesharp's answer. Otherwise, you could do:
alias mysql=/opt/lampp/bin/mysql
This avoids making everything in /opt/lampp/bin/ immediately accessible on the path, which may or may not be desired.
As said by #doublesharp, enter this line into the file .bashrc in your home directory
export PATH=$PATH:/opt/lampp/bin
Related
This question already has an answer here:
VS code terminal can't find AWS SAM even though windows terminal can
(1 answer)
Closed yesterday.
So I downloaded the MySQL installer from https://dev.mysql.com/downloads/installer/. I then went through the process of setting it up via the installer etc. After this was complete, I went to test the command in both Windows PowerShell and CMD, but neither worked.
I looked everywhere I could online to find out what the issue was, but nothing really worked. I found a post that said to add the MySQL path to the main system PATH and so I did. The command I used was:
SET PATH=%PATH%;C:\Program Files\MySQL\MySQL Server 8.0\bin
I also manually edited my environment variables and checked everything there. HOWEVER, a really weird thing is that when I run that command in cmd the mysql --version command WORKS! When I run the same command in Powershell it doesn't, and when I close Windows Terminal and re-open it, the command no longer works in cmd! I really have no idea whats going on. The error message I receive in PowerShell is:
PS C:\Users\User> mysql --version
mysql: The term 'mysql' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
And the error message I receive in CMD is:
C:\Users\User>mysql --version
'mysql' is not recognized as an internal or external command,
operable program or batch file.
If anyone could give me a hand, that'd be amazing, thanks.
Adding to the PATH the way you did is only temporary. It lasts as long as the terminal is open, and when the terminal is gone, so is the change to the path. Use setx instead of set to make it permanent, or make the change using the UI in Windows settings. To do the latter, open the Settings dialog and type Environment into the search box, and then choose the option to change the system environmental variables. When the System Properties dialog appears, click the Environmental variables button at the lower right.
i am new to laravel i just figured out how to install composer laravel etc etc on my local machine MAMP on windows , Now i am confuse with the command on terminal which is
C:\project>mysql -uroot -proot
'mysql' is not recognized as an internal or external command,
operable program or batch file.
How can i fix this ?
setting Environment will solve the issue
Go to Control Panel -> System -> Advanced
Click - Environment Variables
Go to- System Variables find PATH and click on it.
add the path to your mysql\bin folder to the end paths. (ex: E:\xampp\mysql\bin) and add ; end of the line
Close all the command prompts you opens.
Re open and try it.
Setting the PATH to point to the MYSQL bin folder is normally the first thought, but I find that dangerous as things get left lying around when you change software.
I normally create a little batch file in the projects folder or in a folder that it already on your PATH, like this
mysqlpath.cmd
echo off
PATH=C:\mamp\path\to\the\mysql\bin;%PATH%
mysql -v
The mysql -v will output the mysql version number but it is a handy way of knowing that the correct folder has been added to the PATH. This adds the folder to the PATH but only for the life of the command window.
Then just run this from any command window when you want to use MYSQL from the command line
> phppath
You may also like to create one for PHP as well
phppath.cmd
echo off
PATH=C:\mamp\path\to\the\php\;%PATH%
php -v
when I try to use mysql or mysqldump command in terminal I receive an error saying mysql: command not found. Ok the next step is to add the path of mysql: something like this export PATH=$PATH:/usr/local/mysql-5.7.15-osx10.11-x86_64/bin. After that I can use both commands without problem, but if I close the Terminal or restart the computer the mysql/mysqldump command is not recognised by the terminal again. Do you know what could be happening?
I'm using OS X Sierra
Add the below line to .bash_profile for the changes to take effect on every new shell on your OS X system. Not doing so, leaves the changes only on your current working shell and the changes are lost at the end of the shell exit.
export PATH=$PATH:/usr/local/mysql-5.7.15-osx10.11-x86_64/bin
.bash_profile is read at start-up of every new session, so that now the shell knows which path it should pick up the mysql executable.
On macOS you can always add it to /etc/paths.d by creating a file there called something like 90-mysql with the content:
/usr/local/mysql-5.7.15-osx10.11-x86_64/bin
That will apply to new shells, so you will need to create a new terminal window for that to take effect.
The other option is to create a link in /usr/bin to whatever binaries in that directory you want to use. That's more of a hack and probably less elegant than the paths.d option.
Right now, if I want to run mysql, I have to do /Applications/MAMP/Library/bin/mysql -u user -ppass... I'd be a happy camper if I could just do mysql -u user -ppass.... Been googling around, but haven't been able to find anything... Have a feeling I'm using dumb search terms, so if anyone here knows how to do this, that'd be awesome...
you can either add /Applications/MAMP/Library/bin/ to your bash PATH variable (edit your .bash_profile, find the line with export PATH=... and add here the path to MAMP bin folder) , or maybe create an alias with alias mysql='/Applications/.../bin/mysql' (also in your .bash_profile).
Add:
export PATH=$PATH:/Applications/MAMP/Library/bin/
to your ~/.profile
It will take effect next time your profile is initialized (I'm not sure when that is under OS X, it might be when you start your terminal application, it might be when you log in)
It depends what shell you're using. You should be able to add /Applications/MAMP/Library/bin/ to your path:
export PATH=${PATH}:/Applications/MAMP/Library/bin
Mac OS uses bash by default. Just add this line to your .bashrc.
Execute . ./.profile to restart your profile.
I followed this tutorial to the very end, then found out it didn't work right. I think I have everything installed but when I type
mysql -uroot
I only get
-bash: mysql: command not found
Note: I did not skip the "Setting the Path" step. Upon running this command for the first time:
mate ~/.bash_login
This brought up an empty file. So I added this line:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
I saved the file, closed TextMate, executed the following command:
. ~/.bash_login
...and continued with the tutorial. Based on your suggestions, I thought maybe the file didn't actually get saved. So I ran the following command to bring up the file again:
mate ~/.bash_login
...yet the contents of the file were as they should be.
Any suggestions?
You probably don't have the mysql binaries in your path.
The link you posted has a section on setting the path, titled "Setting the Path Do not skip this step! Most everything else will fail if you do."
EDIT: As debugging steps, try:
First launching a new terminal window. Does it run now?
Typing "echo $PATH" at the prompt. Does the path show up correctly as you've typed it in bash_profile?
Running it the long way: /usr/local/mysql/bin/mysql -u root
Does the application run?
Did you follow the step that says
Setting the Path
Do not skip this step! Most everything
else will fail if you do.
Did you close your terminal window and re-open it afterwards?
Update:
What does "which mysql" say? Does "ls /usr/local/mysql/bin" say?
Two things:
Try editing ~/.profile (rather than ~/.bash_profile or ~/.bash_login).
You may find it easier to use the native Mac style .dmg installer directly from Sun.
One nice thing about the dmg installer is that it automagically sets up symlinks to /usr/local/mysql (which means less - or no - fiddling with your $PATH).
Another option would be to use MAMP.
It has Apache, PHP and MySQL packaged with no further setup necessary.
MySQL is usually put in /usr/local/mysql/bin/
You need to add this to your PATH, you can do this by adding the follwoing lines to your .bash_profile
PATH=$PATH:/usr/local/mysql/bin/
export PATH
The .bash_profile file is located in the root of your username directory.
Make sure you restart your Terminal for the setting to take affect.
And if you're not a command-line person, I highly recommend you also install the MySQL Preference Pane to start/stop the server and install Sequel Pro to create databases and run queries.
ftp://ftp.mysql.com/pub/mysql/download/gui-tools/MySQL.prefPane-leopardfix.zip
http://www.sequelpro.com/