从命令行Mysql创建表时出现问题 [英] Problems creating Tables from command line Mysql

查看:107
本文介绍了从命令行Mysql创建表时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在终端中输入代码时,它会创建数据库,但不会创建表. 当我使用"locations"然后输入"Show TABLES"时,它告诉我没有创建表. 这段代码应该创建一个数据库,然后在表中将csv文件导入数据库的位置"

When I type in the code into the Terminal it creates the Database but doesn't create the Table. When I type in use "locations" then "Show TABLES" it tells me that no Tables were created. This code should create a Database and the Table then import the the csv file into the database "locations"

推荐答案

这是一个完整的答案,基于@Honeyboy的评论.

Here is a full answer, based off of @Honeyboy's comment.

除了需要USE locations;以外,还有其他一些要解决的问题:

In addition to needing to USE locations; there are some other things to fix:

  • shell引用并不是很正确.一方面,您现有的代码无法解决换行问题-它需要换行符才能按编写的方式运行.
  • 表名在CREATE TABLE语句和LOAD DATA语句之间更改
  • LOAD DATA语句没有忽略制表符分隔文件的标题行.
  • Shell quoting wasn't really quite right. For one thing, your existing code doesn't account for the line breaks -- it needs line continuation escapes to run as written.
  • The name of the table changed between the CREATE TABLE statement and the LOAD DATA statement
  • The LOAD DATA statement didn't ignore the header row of your tab delimited file.
mysql -u root --password=password -e \
'CREATE DATABASE locations; \
USE locations; \
CREATE TABLE location_T (number1 INT NOT NULL, \
number2 INT NOT NULL, \
number3 INT NOT NULL, \
names VARCHAR(100) NOT NULL,PRIMARY KEY (number1)); \
LOAD DATA LOCAL INFILE "locations.csv" \
INTO TABLE location_T FIELDS TERMINATED by "\t" \
ENCLOSED BY "\"" LINES TERMINATED BY "\n" IGNORE 1 LINES \
(number1,number2,number3,names)'

这篇关于从命令行Mysql创建表时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆