Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How should the terminal use mysql to execute sql statements

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how the terminal should use mysql to execute sql statements, the contents of the articles are carefully selected and edited by the author, with a certain pertinence, the reference significance for everyone is still relatively great, the following with the author to understand how the terminal should use mysql to execute sql statements.

Mysql-urootmysql > use mydb;mysql > select * from user;...

If we need to monitor some tables and save the query results after execution, we need to copy them to a file manually, which affects productivity.

Terminal executes sql

Therefore, the following method is provided, which can directly use shell to call mysql to execute sql statement on the terminal without entering mysql.

Mysql provides the-e parameter to execute the statement directly on the terminal and output it.

For example:

Mysql-uroot-e'select * from mydb.user'

When you use mysql-e to execute a statement, you can add-v,-vv,-vvv parameters

-v displays the statement itself

-vv increases the number of rows displaying query results

-vvv increases display execution time

The execution result is written to the file

Using output redirection, you can save the results of the execution to a file.

For example:

Mysql-uroot-e'select * from mydb.user' > / tmp/mydb_user.txt

After the terminal executes, the query results are saved to / tmp/mydb_user.txt.

After reading the above about how the terminal should use mysql to execute sql statements, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report