当前位置:Gxlcms > 数据库问题 > MySQL 实用技巧

MySQL 实用技巧

时间:2021-07-01 10:21:17 帮助过:2人阅读

OptionDescription
\C The current connection identifier (MySQL 5.7.6 and up)
\c A counter that increments for each statement you issue
\D The full current date
\d The default database
\h The server host
\l The current delimiter
\m Minutes of the current time
\n A newline character
\O The current month in three-letter format (Jan, Feb, …)
\o The current month in numeric format
\P am/pm
\p The current TCP/IP port or socket file
\R The current time, in 24-hour military time (0–23)
\r The current time, standard 12-hour time (1–12)
\S Semicolon
\s Seconds of the current time
\t A tab character
\U

Your full user_name@host_name account name

\u Your user name
\v The server version
\w The current day of the week in three-letter format (Mon, Tue, …)
\Y The current year, four digits
\y The current year, two digits
\_ A space
A space (a space follows the backslash)
\‘ Single quote
\" Double quote
\\ A literal \ backslash character
\x

x, for any x not listed above


以下为配置示例:
1、在my.cnf配置文件[client]部分中增加以下配置 prompt="[\\r:\\m:\\s](\\U)[\\d] > " -- 在配置文件中配置都需要用\对配置的参数进行转义

[root@manager ~]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.10-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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.

[03:11:57](root@localhost)[(none)] >  -- 显示时间 + 登录用户 + 当前使用的数据库(未使用则为none)
[03:15:40](root@localhost)[test] >
2、在mysql客户端内直接配置
mysql>prompt [\r:\m:\s](\U)[\d] >    
PROMPT set to [\r:\m:\s](\U)[\d] >
[03:22:31](root@localhost)[(none)] > -- 显示时间 + 登录用户 + 当前使用的数据库
[03:22:31](root@localhost)[(none)] >prompt (\U)[\d] >
PROMPT set to (\U)[\d] >
(root@localhost)[(none)] > -- 只显示 登录用户 + 当前使用的数据库
 

 

二、tee/notee

功能:tee实现将命令行中的输入输出结果保存到文本文件中,使用该命令能方便的将命令进行日志记录。 
用法:tee /tmp/command.log
以下为使用示例:
[03:43:49](root@localhost)[(none)] > tee /tmp/command.log    -- 设置将输出的结果保存到文件中
Logging to file ‘/tmp/command.log‘
[03:44:02](root@localhost)[(none)] > show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| paralleldb         |
| performance_schema |
| web                |
+--------------------+
10 rows in set (0.00 sec)

[03:44:18](root@localhost)[(none)] > system cat /tmp/command.log    -- 通过system 命令查看系统文件内容与数据库中内容一致
[03:44:02](root@localhost)[(none)] > show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| paralleldb         |
| performance_schema |
| web                |
+--------------------+
10 rows in set (0.00 sec)

[03:46:55](root@localhost)[(none)] > notee         -- 使用notee可结束文件的输出
Outfile disabled.

 

MySQL 实用技巧

标签:

人气教程排行