sql语句无法在mysql执行语句_如何不登录到MySQL执行SQL语句

mysql 后面直接接命令

一般来讲,我们在MySQL中执行查询都是进入到mysql中执行的,比如通过命令登录:

$ mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.7.17-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

然后再敲命令做查询,那么能不能直接就在终端或者命令行执行查询呢,答案是肯定的,只需要多加一个e参数即可:

$ mysql -u root -p-e "SHOW DATABASES"

Enter password:

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

再做一个SELECT语句看看:

$ mysql -u root -p -e "SELECT * FROM user \G" mysql

Enter password:

*************************** 1. row ***************************

Host: localhost

User: root

Select_priv: Y

Insert_priv: Y

Update_priv: Y

Delete_priv: Y

Create_priv: Y

Drop_priv: Y

Reload_priv: Y

Shutdown_priv: Y

Process_priv: Y

File_priv: Y

Grant_priv: Y

References_priv: Y

Index_priv: Y

Alter_priv: Y

Show_db_priv: Y

Super_priv: Y

Create_tmp_table_priv: Y

Lock_tables_priv: Y

Execute_priv: Y

Repl_slave_priv: Y

Repl_client_priv: Y

Create_view_priv: Y

Show_view_priv: Y

Create_routine_priv: Y

Alter_routine_priv: Y

Create_user_priv: Y

Event_priv: Y

Trigger_priv: Y

Create_tablespace_priv: Y

ssl_type:

ssl_cipher:

x509_issuer:

x509_subject:

max_questions: 0

max_updates: 0

max_connections: 0

max_user_connections: 0

plugin: mysql_native_password

authentication_string: *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9

password_expired: N

password_last_changed: 2017-03-07 19:17:21

password_lifetime: NULL

account_locked: N

*************************** 2. row ***************************

Host: localhost

User: mysql.sys

Select_priv: N

Insert_priv: N

Update_priv: N

Delete_priv: N

....................

这样只不过是每次都得键入密码,有点繁琐,所以还是进入到MySQL再执行查询吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值