Tag: command line

Command not found when using MYSQL from the command line on osx

I want to run some mysql command from my terminal, but each time I run mysql -u root to log in, I get an error:

-bash: mysql: command not found

This is because mysql isn’t in my PATH.  Your path is an environment variable that holds directories that your computer will search through to find executable files. You can review what’s in your path by running:

# echo $PATH

This will show you the list of directories that are in your path.  This variable is stored in your .bash_profile. On most macs, the .bash_profile file is located in the root of your home directory. To view the current .bash_profile file, go to your home directory

# ~ 

From there, run the ls command to view all files.

# ls -alh

 Near the top of the listing is the .bash_profile file. Cat out the contents to see what’s in your path.

# cat .bash_profile

To update the file, backup your current .bash_profile

# cp .bash_profile .bash_profile_backup

To locate your mysql executable, use the locate command.

# locate mysql | less

Since I’m running MAMP, my mysql executable is located in  /Applications/MAMP/Library/bin/mysql  To add this to the end my path, run the following command.

# echo 'export
PATH=$PATH:/Applications/MAMP/Library/bin' >> ~/.bash_profile

This takes the output of the echo command and puts it into your .bash_profile. Now, you make it persist by sourcing it. This alerts the current terminal to reload the file.

# source ~/.bash_profile

Now you can echo path again to confirm or cat out your file

# echo $PATH

Now, we can use the mysql command from our current location. Enter the password, if prompted.

# mysql -u root -p

Now, you can run your commands with ease.

To quit the mysql cli, run:

# \q
Be soical and share.

Today’s 10 Commands: Command-Line Navigation

Introducing 2 new blog series: Today’s 10 & Fab 5

This is the first of many blog posts about commands, utilities and tips I’m either learning for the first time or re-familiarizing myself with. This series is called Today’s 10, 10 commands, tips, tricks, etc. I will have another series called Fab 5 for the quick hitters that I come across.

Command-Line navigation:

We all have done it, backspaced and back and forth, arrow up and down the command line. Trying to correct errors, change things after an erroneous tab completions and make changes to command after we’ve pulled them up in our history.

Here are 10 commands that will have you zipping around the shell prompt in no time.

  1. Alt+b – will move your cursor back one word at a time to start of the word.
  2. Alt+f – will move your cursor forward one word at a time to the end of the word.
  3. Alt+d – will delete to the end of that misspelled word starting at the cursor.
  4. Ctrl+e – move your cursor at the end of the line.
  5. Ctrl+ a – move your cursor to the beginning of the line.
  6. Ctrl+l – clear your screen (clear also will do the trick).
  7. Ctrl +w – deletes from the cursor to the beginning of the word or path.
  8. Ctrl+c – clears the entire line. (yes, THAT ctrl+c) and takes to to a blank command prompt.
  9. Ctrl+f – move cursor forward one character at a time, like the right arrow key.
  10. Ctrl+b – move cursor backward one character at a time, like the left arrow key.

Watch your command-line navigation improve as you use these keystrokes more and more. There are many, many more, but these are the 10 that I use the most.

What are some of your favorite command-line shortcuts?





Be soical and share.

Edit files from Windows Command Line

I was adding entries to my hosts file on Windows 10 and I got an Access is Denied message when I saved the file in Notepad. Here are 2 quick ways to edit system files.

1) Right+Click Command Prompt or Notepad and Run as Administrator (old faithful)
2) From the Command Line, as Administrator,  start notepad.exe “hosts” (from the etc folder of course) or for more bang for your buck, open notepad++ with start notepad++.exe “hosts” if you have it installed.

Command to edit files from the command line

Be soical and share.
Social media & sharing icons powered by UltimatelySocial