Running MySql command from terminal not working

Anthony Russell

So I want to pipe my netstat output into a mysql database

The plan is to make it a continuous crontab event. That way I can store that data and use it elsewhere easily.

I figured before I could figure that part out though I needed to figure out how to run a SQL Command from terminal.

It seems pretty straight forward

sudo mysql -u username -pMYPassword -e "SQL COMMAND"

This however doesn't work...

When I run this it prints the MYSQL Help

When I run this though

sudo mysql -u username -p -e "SQL COMMAND"

everything works perfect, it just prompts me for a password

Now I don't know if it makes a difference or not but my DB password does have exclamation points in it. It is also over 15 chars long

Could either of these be an issue?

Bud Damyanov
mysql -u user -p -e 'SQL Query' database

Where,

-u : Specify mysql database user name
-p : Prompt for password
-e : Execute sql query
database : Specify database name

So the option -p is a PROMPT, the password need not to be linked, but to be separated from it:

sudo mysql -u username -p'PassWord' -e 'SELECT COUNT(*) FROM my_table'

EDIT: If your real password contains special characters, you need to escape them.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

(Windows Terminal) How to stop double printing of current working directory when running a command from a doskey macro file?

From Java

grunt: command not found when running from terminal

From Dev

Running a program from terminal, "command not found"

From Dev

Running a program from terminal, "command not found"

From Dev

Running command from cron not working with no error

From Dev

Running python script from matlab not working, but runs fine from terminal

From Dev

Running python script from matlab not working, but runs fine from terminal

From Dev

Can I run a terminal command from the terminal, and close the terminal (leaving the program running)?

From Dev

Running a Common Lisp function from a Terminal command prompt

From Dev

Running a custom command from the Terminal icon in the dock on Ubuntu 18.04

From Dev

Express command not working in terminal

From Dev

subl . command not working on terminal

From Dev

Running mysql command from bat file with redirection

From Dev

Terminal INSERT into MySQL Not Working

From Dev

Execute mysql command from the host to container running mysql server

From Dev

How to execute MySQL command from the host to container running MySQL server?

From Dev

Opening a new terminal from the command line and running a command on Mac OS X?

From Dev

'rails server' command not working in terminal

From Dev

OSX: Terminal Zip command not working

From Dev

append line command not working in terminal

From Dev

Command `open` not working on Ubuntu Terminal

From Dev

Command not working in crontab, but work in terminal

From Dev

MySQL command from file running from bash / results columns not alligned

From Dev

Working directory when running command

From Dev

Working directory when running command

From Dev

Command showing different behaviour when running from terminal and when Using as Shortcut

From Dev

Getting output from executing a terminal command in a java code running inside Cubieboard Platform

From Dev

Command showing different behaviour when running from terminal and when Using as Shortcut

From Dev

Running JUnit tests from Terminal

Related Related

  1. 1

    (Windows Terminal) How to stop double printing of current working directory when running a command from a doskey macro file?

  2. 2

    grunt: command not found when running from terminal

  3. 3

    Running a program from terminal, "command not found"

  4. 4

    Running a program from terminal, "command not found"

  5. 5

    Running command from cron not working with no error

  6. 6

    Running python script from matlab not working, but runs fine from terminal

  7. 7

    Running python script from matlab not working, but runs fine from terminal

  8. 8

    Can I run a terminal command from the terminal, and close the terminal (leaving the program running)?

  9. 9

    Running a Common Lisp function from a Terminal command prompt

  10. 10

    Running a custom command from the Terminal icon in the dock on Ubuntu 18.04

  11. 11

    Express command not working in terminal

  12. 12

    subl . command not working on terminal

  13. 13

    Running mysql command from bat file with redirection

  14. 14

    Terminal INSERT into MySQL Not Working

  15. 15

    Execute mysql command from the host to container running mysql server

  16. 16

    How to execute MySQL command from the host to container running MySQL server?

  17. 17

    Opening a new terminal from the command line and running a command on Mac OS X?

  18. 18

    'rails server' command not working in terminal

  19. 19

    OSX: Terminal Zip command not working

  20. 20

    append line command not working in terminal

  21. 21

    Command `open` not working on Ubuntu Terminal

  22. 22

    Command not working in crontab, but work in terminal

  23. 23

    MySQL command from file running from bash / results columns not alligned

  24. 24

    Working directory when running command

  25. 25

    Working directory when running command

  26. 26

    Command showing different behaviour when running from terminal and when Using as Shortcut

  27. 27

    Getting output from executing a terminal command in a java code running inside Cubieboard Platform

  28. 28

    Command showing different behaviour when running from terminal and when Using as Shortcut

  29. 29

    Running JUnit tests from Terminal

HotTag

Archive