简体   繁体   English

mysql错误选择输出

[英]mysql wrong select output

I created table using command: 我使用命令创建表:

CREATE TABLE genre(
    genre_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(20) NOT NULL
);

Then I filled table with data using command: 然后我使用命令用数据填充表:

load data infile 'D:/MySQL/.../genres.txt' into table genre(name);

There is one record on every line. 每行有一个记录。

Problem occured when I tried to print content of table into terminal using command: 当我尝试使用命令将表的内容打印到终端时发生问题:

select * from genre;

Output: 输出:

 +----------+--------------+
 | genre_id | name         |
 +----------+--------------+
 |       1 | alternative
   | 2 | blues
 |   3 | classic
 |   4 | country
   | 5 | dance
 |   6 | electro
    |7 | folk
     | | pop
     | | rap
    |0 | jazz
  | 11 | latino
   |12 | opera
     | | r&b
  | 14 | reagge
    |5 | rock
 |       16 | metal        |
   |
 +----------+--------------+

(vertical bars are printed wrong too) (竖线也打印错误)

Does anyone know why is output of first column printed wrong? 有谁知道为什么第一列的输出打印错误? I am mysql beginner so sorry if it is a dumb question. 我是mysql初学者,所以很抱歉,如果这是一个愚蠢的问题。

File content: 档案内容:

alternative
blues
classic
country
dance
electro
folk
pop
rap
jazz
latino
opera
r&b
reagge
rock
metal

This is too long for a comment. 这个评论太长了。

The column genre_id is auto-incremented. genre_id是自动递增的。 So, when a row is inserted into the table, the column gets a value. 因此,当在表中插入一行时,该列将获得一个值。 It is as simple as that. 它是如此简单。

You appear to have rows with no genre_id. 您似乎有没有genre_id的行。 That is not possible. 这是不可能的。 The column is declared as an integer and it cannot take on a NULL value. 该列声明为整数,并且不能采用NULL值。 So, you would see some value for every inserted row. 因此,您将为每个插入的行看到一些值。

The conclusion is that the rows that look like they are missing genre_id really are not separate rows at all. 结论是看起来像缺少genre_id行实际上根本不是单独的行。 Instead, they are single rows that have embedded newline or carriage return characters that are messing up the output. 相反,它们是嵌入了换行符或回车符的单行,这些字符使输出混乱。 If you are using a Unix-based system, you can use od (octal dump) to see the contents of the file. 如果使用的是基于Unix的系统,则可以使用od (八进制转储)查看文件的内容。 There is probably some correct line terminator that will fix the problem. 可能有一些正确的行终止符可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM