Problems creating Tables from command line Mysql

前端 未结 1 1814
无人及你
无人及你 2021-01-28 17:41

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 m

相关标签:
1条回答
  • 2021-01-28 18:05

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

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

    • 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)'
    
    0 讨论(0)
提交回复
热议问题