1

我有一个与 MySQL 有关的问题。从这两张图片中可以看出问题:

http://imgur.com/NrOwSxS,yPo9Cra http://imgur.com/NrOwSxS,yPo9Cra#1

有谁知道 MySQL 为什么要这样做?它应该显示为一张漂亮整洁的桌子,而不是一堆乱七八糟的东西。提前致谢!:D

4

3 回答 3

1

首先,为了证明没有什么问题,试试这个查询:

SELECT firstname FROM contact_info

那应该看起来不错。现在试试这个:

SELECT firstname, lastname FROM contact_info

这就是您选择单个列的方式。

如果您真的想将输出捕获到文件中,此页面将向您展示如何:MySQL 命令行工具

然后你可以学习使用其他程序很好地格式化它。

于 2013-03-18T04:58:42.030 回答
0

我假设您创建的表格有点像这样:

create table automobile (make char(10),model char(10),year int, color char(10), style char(50), MSRP int);
insert into automobile values ('Ford','Mustang',2006,'Blue','Convertible',27000);
insert into automobile values ('Toyota','Prius',2005,'Silver','Hybrid',22000);
insert into automobile values ('Toyota','Camry',2006,'Blue','Sedan',26000);
insert into automobile values ('Dodge','1500',2005,'Green','Pickup',26000);

所以一个

 describe automobile

将向您显示您的列:

+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| make  | char(10) | YES  |     | NULL    |       |
| model | char(10) | YES  |     | NULL    |       |
| year  | int(11)  | YES  |     | NULL    |       |
| color | char(10) | YES  |     | NULL    |       |
| style | char(50) | YES  |     | NULL    |       |
| MSRP  | int(11)  | YES  |     | NULL    |       |
+-------+----------+------+-----+---------+-------+

只要您的列总数小于终端的宽度,您应该会看到预期的结果:

mysql> select * from automobile;
+--------+---------+------+--------+-------------+-------+
| make   | model   | year | color  | style       | MSRP  |
+--------+---------+------+--------+-------------+-------+
| Ford   | Mustang | 2006 | Blue   | Convertible | 27000 |
| Toyota | Prius   | 2005 | Silver | Hybrid      | 22000 |
| Toyota | Camry   | 2006 | Blue   | Sedan       | 26000 |
| Dodge  | 1500    | 2005 | Green  | Pickup      | 28000 |
+--------+---------+------+--------+-------------+-------+

如果您希望结果更小,请选择您想查看的列,例如

 select make,model from automobile

mysql> select make,model from automobile;
+--------+---------+
| make   | model   |
+--------+---------+
| Ford   | Mustang |
| Toyota | Prius   |
| Toyota | Camry   |
| Dodge  | 1500    |
+--------+---------+

要使列的内容更小,您可以使用左字符串函数

select left(make,4) as make, left(model,5) as model,left(style,5) as style from automobile;
+------+-------+-------+
| make | model | style |
+------+-------+-------+
| Ford | Musta | Conve |
| Toyo | Prius | Hybri |
| Toyo | Camry | Sedan |
| Dodg | 1500  | Picku |
+------+-------+-------+
于 2014-05-07T11:51:03.710 回答
0

您可以尝试在最后提供行分隔符。

mysql> LOAD DATA LOCAL INFILE *file_path* INTO *table_name* LINES TERMINATED BY '\r\n';

分隔符可能因编辑而异。在 Windows 中,大多数编辑器使用'\r\n'.

于 2018-09-25T08:16:29.673 回答