Sponsored Content
Top Forums Programming MySQL auto_increment, primary key Post 302590478 by yifangt on Monday 16th of January 2012 11:05:03 AM
Old 01-16-2012
MySQL auto_increment, primary key

Hello,

I want to create a table in mysql database by loading the local file. I am confused with the auto_increment column (say Run_ID) that I want to set it as primary key. My questions are:
1) Do I need add this Run_ID in my file ready? then this does not make any sense to the auto_increment;
2) Should I ignore this column first and then alter the table later? I actually do not have this column in the file. When I tried to create the table:
Code:
DROP TABLE IF EXISTS tair10_agi;
CREATE TABLE if NOT EXISTS tair10_agi (
     Run_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
     AGI_Number text(50),
     Symbols text(100),
     Computational_description text(1000),
     Chromosome VARCHAR(10),
     Orientation VARCHAR(20),     
     Start INT,
     End INT,
     AA_Length INT NOT NULL
      );

LOAD DATA 
     LOCAL INFILE "/home/path/to/my_file/file-cleaned.csv" 
 INTO TABLE tair10_agi 
     FIELDS TERMINATED BY '\t' 
     LINES TERMINATED BY '\n';

I added this column, but there is always problem with loading the local file. Somehow the columns are shifted. I was thinking the problem is with this auto_increment. I must have missed something.
Any explanation is appreciated!
yifangt
 

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Pressing backspace key simulates enter key

Hi, Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused: Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies

2. Web Development

MySQL Replication Issues: Duplicate Key Error

Lately my attention has been focused on distributed MySQL database replication to other web servers. All was going well, but then I noticed the replication would stop and there were there "Duplicate Primary Key" errors in SHOW SLAVE STATUS; I started to trace these down and noticed that this... (2 Replies)
Discussion started by: Neo
2 Replies

3. Solaris

Solaris 8 ssh public key authentication issue - Server refused our key

Hi, I've used the following way to set ssh public key authentication and it is working fine on Solaris 10, RedHat Linux and SuSE Linux servers without any problem. But I got error 'Server refused our key' on Solaris 8 system. Solaris 8 uses SSH2 too. Why? Please help. Thanks. ... (1 Reply)
Discussion started by: aixlover
1 Replies

4. UNIX and Linux Applications

MySQL Daemon failed to start - no mysql.sock file

After doing a yum install mysql mysql-server on Fedora 14 I wasn't able to fully install the packages correctly. It installed MySQL 5.1. I was getting the following error when running the: mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)... (3 Replies)
Discussion started by: jastanle84
3 Replies

5. Programming

Identifying a missing primary key

I have the following method to identify missing primary keys in a MySQL database schema: USE information_schema; SELECT xx.table_name FROM (SELECT table_name, COUNT(*) FROM columns WHERE table_schema = @myDB GROUP BY table_name, column_key) xx GROUP BY xx.table_name HAVING COUNT(*) = 1; I... (0 Replies)
Discussion started by: figaro
0 Replies

6. Solaris

Primary key issue when running Oracle sql file

I got a issue with running the following script below if I remove the inserts and alter table the tables will install just fine but if I try and do the full thing in one go i get the below error dose any one have any ideas on this problem? its got me spinning, thanks. REM REM List of... (1 Reply)
Discussion started by: Wpgn
1 Replies
Class::DBI::mysql(3pm)					User Contributed Perl Documentation				    Class::DBI::mysql(3pm)

NAME
Class::DBI::mysql - Extensions to Class::DBI for MySQL SYNOPSIS
package Film; use base 'Class::DBI::mysql'; __PACKAGE__->set_db('Main', 'dbi:mysql:dbname', 'user', 'password'); __PACKAGE__->set_up_table("film"); __PACKAGE__->autoinflate(dates => 'Time::Piece'); # Somewhere else ... my $type = $class->column_type('column_name'); my @allowed = $class->enum_vals('column_name'); my $tonights_viewing = Film->retrieve_random; DESCRIPTION
This is an extension to Class::DBI, containing several functions and optimisations for the MySQL database. Instead of setting Class::DBI as your base class, use this instead. METHODS
set_up_table __PACKAGE__->set_up_table("table_name"); Traditionally, to use Class::DBI, you have to set up the columns: __PACKAGE__->columns(All => qw/list of columns/); __PACKAGE__->columns(Primary => 'column_name'); Whilst this allows for more flexibility if you're going to arrange your columns into a variety of groupings, sometimes you just want to create the 'all columns' list. Well, this information is really simple to extract from MySQL itself, so why not just use that? This call will extract the list of all the columns, and the primary key and set them up for you. It will die horribly if the table contains no primary key, or has a composite primary key. autoinflate __PACKAGE__->autoinflate(column_type => 'Inflation::Class'); __PACKAGE__->autoinflate(timestamp => 'Time::Piece'); __PACKAGE__->autoinflate(dates => 'Time::Piece'); This will automatically set up has_a() relationships for all columns of the specified type to the given class. We currently assume that all classess passed will be able to inflate and deflate without needing extra has_a arguments, with the example of Time::Piece objects, which we deal with using Time::Piece::mysql (which you'll have to have installed!). The special type 'dates' will autoinflate all columns of type date, datetime or timestamp. create_table $class->create_table(q{ name VARCHAR(40) NOT NULL PRIMARY KEY, rank VARCHAR(20) NOT NULL DEFAULT 'Private', serial INTEGER NOT NULL }); This creates the table for the class, with the given schema. If the table already exists we do nothing. A typical use would be: Music::CD->table('cd'); Music::CD->create_table(q{ cdid MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, artist MEDIUMINT UNSIGNED NOT NULL, title VARCHAR(255), year YEAR, INDEX (artist), INDEX (title) }); Music::CD->set_up_table; drop_table $class->drop_table; Drops the table for this class, if it exists. column_type my $type = $class->column_type('column_name'); This returns the 'type' of this table (VARCHAR(20), BIGINT, etc.) enum_vals my @allowed = $class->enum_vals('column_name'); This returns a list of the allowable values for an ENUM column. retrieve_random my $film = Film->retrieve_random; This will select a random row from the database, and return you the relevant object. (MySQL 3.23 and higher only, at this point) SEE ALSO
Class::DBI. MySQL (http://www.mysql.com/) AUTHOR
Tony Bowden BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Class-DBI-mysql@rt.cpan.org COPYRIGHT AND LICENSE
Copyright (C) 2001-2005 Tony Bowden. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. perl v5.10.0 2005-09-03 Class::DBI::mysql(3pm)
All times are GMT -4. The time now is 02:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy