MySQL tee(\ T)命令不输出我的查询或我的评论

时间:2016-09-25 21:43:10

标签: mysql tee

目标:将所有SQL查询及其输出输出到文本文件

SQL CODE

\W /*enable warnings*/

USE bookdb; /*doesn't exist because I WILL DROP DATABASE booksdb BEFORE RUNNING THIS SCRIPT (to avoid duplicate entry errors from testing out the queries during the assignment)*/

/* Query 0 */

SELECT user(), current_date(), version(), @@sql_mode\G

/*Query 1*/

CREATE DATABASE IF NOT EXISTS bookdb;
Use bookdb;

/*QUERY 2*/

CREATE TABLE books (
 isbn CHAR(10),
 author VARCHAR(100) NOT NULL,
 title VARCHAR(128) NOT NULL,
 price DECIMAL(7 , 2 ) NOT NULL,
 subject VARCHAR(30) NOT NULL,
 PRIMARY KEY (isbn)
)ENGINE = INNODB;

/*QUERY 3*/

INSERT INTO books
VALUES ('0345377648', 'Anne Rice', 'Lasher', 14.00, 'FICTION');
INSERT INTO books
VALUES ('1557044287','Ridley Scott','Gladiator',26.36,'FICTION');
INSERT INTO books
VALUES ('0684856093', 'Sean Covey', 'The 7 Habits', 12, 'CHILDREN');

/*QUERY 4*/

SHOW TABLES;

/*QUERY 5*/

DESC books;

/*QUERY 6*/

SELECT * FROM books;

/*QUERY 7*/

SELECT ISBN, title, price FROM books;

SQL PROMPT命令

mysql> tee /my_scripts/yourname_assignment1.txt

mysql> source /my_scripts/yourname_assignment1.sql

mysql> notee

导致assignment1.txt文件

        user(): root@localhost
current_date(): 2016-09-25
     version(): 5.7.15-0ubuntu0.16.04.1
    @@sql_mode:         ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_    FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
1 row in set (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Database changed
Query OK, 0 rows affected (0.32 sec)

Query OK, 1 row affected (0.06 sec)

Query OK, 1 row affected (0.04 sec)

Query OK, 1 row affected (0.08 sec)

+------------------+
| Tables_in_bookdb |
+------------------+
| books            |
+------------------+
1 row in set (0.00 sec)

+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| isbn    | char(10)     | NO   | PRI | NULL    |       |
| author  | varchar(100) | NO   |     | NULL    |       |
| title   | varchar(128) | NO   |     | NULL    |       |
| price   | decimal(7,2) | NO   |     | NULL    |       |
| subject | varchar(30)  | NO   |     | NULL    |       |
+---------+--------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

+------------+--------------+--------------+-------+----------+
| isbn       | author       | title        | price | subject  |
+------------+--------------+--------------+-------+----------+
| 0345377648 | Anne Rice    | Lasher       | 14.00 | FICTION  |
| 0684856093 | Sean Covey   | The 7 Habits | 12.00 | CHILDREN |
| 1557044287 | Ridley Scott | Gladiator    | 26.36 | FICTION  |
+------------+--------------+--------------+-------+----------+
3 rows in set (0.00 sec)

+------------+--------------+-------+
| ISBN       | title        | price |
+------------+--------------+-------+
| 0345377648 | Lasher       | 14.00 |
| 0684856093 | The 7 Habits | 12.00 |
| 1557044287 | Gladiator    | 26.36 |
+------------+--------------+-------+
3 rows in set (0.00 sec)

mysql> notee

正如您所看到的,我的查询执行时没有错误(即它们正确显示),但输出列出查询本身。

我的教授" example.txt" file包含assignment1.sql文件中列出的查询。换句话说,他的输出显然包括他在SQL文件中的查询,其中我的输出没有。你如何改变" tee"命令包含查询?我的教授是否只是手动编辑了该文件的副本,还是我错过了什么?

我意识到,如果我手动输入命令,我的输出看起来会更像他的(即带有查询),但这不是他解释这个任务的方式。

如果可能对SQL产生影响,我正在运行最新的x64 Ubuntu操作系统。我是新手。我已经在网上彻底搜索了这个具体问题,但没有人列出这个问题。

谢谢。

分配方向如果澄清任何事情

  1. 运行以下命令: mysql -u root -p --force --comments -vvv
  2. 使用tee命令将输出放在要提交的文本文件中。 MySQL的> tee c:/my_scripts/yourname_assignment1.txt
  3. 运行SQL脚本hibrahim_assignment1.sql MySQL的> source c:\ my_scripts \ yourname_assignment1.sql
  4. 键入notee以停止tee命令。 MySQL的> notee

1 个答案:

答案 0 :(得分:0)

我修好了。这是因为我的Linux机器没有正确授予权限。命令

mysql -u root -p --force --comments -vvv 

要求提升(并且不需要root)。我想我错过了--force --comments -vvv因此没有包含查询和评论。因此,为了将来参考,您需要提升。此外,我不需要指定root。结果命令是

sudo mysql --force --comments -vvv