MySQL client command line application tips

Source: Internet
Author: User
Tags mysql client mysql commands requires

Image-oriented MySQL management tools abound, but there may not be more efficient than a MySQL client-driven command line for management tools that can really speed up and are not "graphs with tables." However, performing a generic query requires a lot of keyboard input, and it can be tedious to determine the database you are currently logged on to and the performance of a fast-monitoring database server.

Changing the client prompt

If you can get a dollar every time you run show tables to remind yourself of which database you are currently choosing, I guess I'm a millionaire now. In fact, when we constantly switch between the IDE, the shell prompt, and the MySQL client prompt, it's easy to get lost and not know where we are. To fundamentally eliminate this problem, you can use the following prompt command to change the MySQL prompt:

Mysql>prompt MySQL (\d) >

When you finish executing the command, the database you select is displayed in the prompt, as follows:

MySQL (Corporate) >

In addition, we can easily lose the database server we are logged on to, let alone the account being used. To resolve this issue, change the prompt settings by using the \u and \h options:

Mysql>prompt MySQL (\u@\h) >

The results of the execution of the command are as follows:

MySQL (root@www.ctocio.com.cn) >

To permanently save this change setting, you can add the following command to the. my.cnf file:

[MySQL] prompt=mysql \\d>

database, user, and host options are just a small part of many optional options, and you can refer to MySQL's documentation for more information.

Use Shell alias (alias) to perform frequently used MySQL commands

Suppose your new Web application is stepping into the application phase, with new users registering every hour. Just like the IPO, you and your co-workers need to keep an eye on the number of registered users. However, in order to perform a simple count query requires constant login to exit MySQL, obviously not very cost-effective. If you log on to the server, you can create a shell alias to implement the entire process of logging on to the MySQL server, selecting the appropriate database, and executing the Count command:

%>alias usrcount= "mysql-u appadmin-p myapplication-e \" SELECT COUNT (ID) from users\ ""

In this case, you want to log on to the local MySQL server using the Appadmin user account, select the MyApplication database, and then use the Select query to perform the Count query. After you execute the above command, when you want to determine how many users are in the system, simply execute the following command and enter the Appadmin user password:

%>usrcount
Enter password:
+-------------+
| count(id) |
+--------- ----+
| 348 |
+-------------+

To permanently save this alias, you can add it to a. bashrc file or a similar shell configuration file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.