In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
If you are responsible for managing the database server, you may need to run the query from time to time and check it carefully. Although you can do this from MySQL/MariaDB Shell, this technique will allow you to execute an MySQL/MariaDB query directly using the Linux command line and save the output to a file for later inspection (this is especially useful when the query returns. A lot of records.
Let's look at some simple examples of running a query directly from the command line, and then move on to a more advanced query. To view all databases on the server, issue the following command:
[linuxidc@localhost ~ / www.linuxidc.com] $mysql-u root-p-e "show databases "+-+ | Database | +-+ | idc_db | | information_schema | | linuxidc_db | | mysql | | performance_schema | | xxx_db | +-+ |
Next, to create a database table named linuxceshi in the database linuxidc_db, run the following command:
[linuxidc@localhost ~ / www.linuxidc.com] $mysql-u root-p-e "USE linuxidc_db; CREATE TABLE linuxceshi (idc_id INT NOT NULL AUTO_INCREMENT, idc_title VARCHAR (100) NOT NULL, idc_author VARCHAR (40) NOT NULL, submissoin_date DATE, PRIMARY KEY (idc_id));"
Check whether the following table has been built or not
[linuxidc@localhost ~ / www.linuxidc.com] $mysql-u root-p-e "use linuxidc_db; desc linuxceshi "+-+-+ | Field | Type | Null | Key | Default | Extra | +-- -+ | idc_id | int (11) | NO | PRI | NULL | auto_increment | | idc_title | varchar | NO | | NULL | | idc_author | varchar (40) | | NO | | NULL | submissoin_date | date | YES | | NULL | | +-+ + |
We will use the following command and pipe the output to the tee command, followed by the file name in which we want to store the output.
For illustration purposes, we will use a linuxceshi table called the linuxidc database. Note that you will be prompted for the password of the database user:
[linuxidc@localhost ~ / www.linuxidc.com] $mysql-u root-p-e "use linuxidc_db; desc linuxceshi;" | tee linuxidc_chaxun.txt
Use the cat command to view the query results.
[linuxidc@localhost ~ / www.linuxidc.com] $mysql-u root-p-e "use linuxidc_db; desc linuxceshi "| tee linuxidc_chaxun.txtEnter password:Field Type Null Key Default Extraidc_id int (11) NO PRI NULL auto_incrementidc_title varchar (100) NO NULLidc_author varchar (40) NO NULLsubmissoin_date date YES NULL [linuxidc@localhost ~ / www.linuxidc.com] $cat linuxidc_chaxun.txtField Type Null Key Default Extraidc_id int (11) NO PRI NULL Auto_incrementidc_title varchar (100) NO NULLidc_author varchar (40) NO NULLsubmissoin_date date YES NULL
Using the query results of a plain text file, you can use other command-line utilities to process records more easily.
Summary
This article has shared a bit of Linux tips, and as a system administrator, you can find useful information about automating daily Linux tasks or performing them more easily.
The original text is from: https://www.linuxprobe.com/linux-mysql-mariadb.html
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.