从终端运行MySql命令不起作用

时间:2021-09-23 03:06:40

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

所以我想把我的netstat输出管道输入到mysql数据库中

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

计划是使它成为一个连续的crontab事件。这样我就可以存储这些数据并轻松地在其他地方使用它。

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

虽然我需要弄清楚如何从终端运行SQL命令,但我还是想知道那部分。

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

当我运行它时,它打印MYSQL帮助

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

现在我不知道它是否有所作为,但我的数据库密码确实有感叹号。它也超过15个字符

Could either of these be an issue?

这些都可能成为一个问题吗?

2 个解决方案

#1


1  

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:

所以选项-p是PROMPT,密码不需要链接,但要与它分开:

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.

编辑:如果您的真实密码包含特殊字符,您需要转义它们。

#2


0  

Maybe try : sudo mysql -u username -p'MYPassword' -e "SQL COMMAND"

也许试试:sudo mysql -u username -p'MYPassword'-e“SQL COMMAND”

Or : sudo mysql -u username --password=MyPassword -e "SQL COMMAND"

或者:sudo mysql -u username --password = MyPassword -e“SQL COMMAND”

#1


1  

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:

所以选项-p是PROMPT,密码不需要链接,但要与它分开:

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.

编辑:如果您的真实密码包含特殊字符,您需要转义它们。

#2


0  

Maybe try : sudo mysql -u username -p'MYPassword' -e "SQL COMMAND"

也许试试:sudo mysql -u username -p'MYPassword'-e“SQL COMMAND”

Or : sudo mysql -u username --password=MyPassword -e "SQL COMMAND"

或者:sudo mysql -u username --password = MyPassword -e“SQL COMMAND”