Sponsored Content
Top Forums Web Development met problem with do() in MySQL Post 302582278 by yifangt on Thursday 15th of December 2011 10:01:42 AM
Old 12-15-2011
met problem with do() in MySQL

Hi, I had a chance to create a database refreshing the previous post. An error was tossed out with the following message:
Code:
DBI  connect('nr20111117_db','yifangt',...) failed: Unknown database  'nr20111117_db' at create-nrDB-20111214.pl line 17
Cannot connect: Unknown database 'nr20111117_db' at  create-nrDB-20111214.pl line 17.

Obviously the problem is line 17 to CREATE DATABASE and TABLE. Appreciate any help. Thanks a lot!
Code:
#!/usr/bin/perl -w
use strict;
use DBI;

my $DataBaseName="nr20111117_db";
my $DataBaseHost="localhost";
my $MySQLUser="yifangt";
my $MySQLUserPass="PassWord";
my $dsn="DBI:mysql";
my $Table="table01";

my $dbh = DBI->connect("$dsn:$DataBaseName", $MySQLUser, $MySQLUserPass) or die "Cannot connect: " . $DBI::errstr;

   $dbh->do("CREATE DATABASE $DataBaseName");
   $dbh->do("CREATE TABLE $Table (
            number    INT NOT NULL AUTO_INCREMENT  PRIMARY KEY,
              gi_id     VARCHAR(20),
            description     TEXT)"
        );

my $sql = qq{INSERT INTO $Table (number, gi_id, description) VALUES (?, ?, ?)};
my $sth = $dbh->prepare($sql);
my $file_name="/home/yifang/20111114-Yangdou/BLAST-vs-nr/nr-headers+row.tab";

open (FILE, "<", $file_name) or die "Cannot open the file named $file_name to read: $!";

#################### Example rows of the data
#Run_Number gi_ID    Description
# 1 >gi|15674171|ref|NP_268346.1|   30S ribosomal protein S18 
# 2 >gi|66816243|ref|XP_642131.1|    hypothetical protein DDB_G0277827 [Dictyostelium discoideum AX4]
# 3 >gi|66818355|ref|XP_642837.1|    hypothetical protein DDB_G0276911 [Dictyostelium discoideum AX4]
############## ### End of Example rows of the file #
     
foreach my $line (<FILE>) {
    chomp $line;
  my @fields = split(/\t/, $line);
    $sth->execute(@fields);
}

while (my $row = $sql->fetchrow_arrayref) {
        print join("\t", @$row), "\n";
    }
$dbh->disconnect;

I had thought it to be simple to add the lines by durden_tyler, but not that easy! Thanks again!
 

10 More Discussions You Might Find Interesting

1. Cybersecurity

Need someone to help, MySQL problem, no root access

Hi! I have a website, and it's been down for a long time now, because MySQL died (www.3dkingdom.org). I need someone who can get me the root password of the server (I will find someone to take care of the MySQL database, because there is about 20 sites there and none of them have MySQL databases... (6 Replies)
Discussion started by: _hp_
6 Replies

2. UNIX for Advanced & Expert Users

MySQL problem >> missing mysql.sock

MySQL on my server is down.... I figured out that the mysqld process isn't running. When I try to run it, it says it can't find mysql.sock Any suggestions? Here's what I can't do: can't be root don't have physical access (do stuff via SSH) reinstall MySQL (need to keep the current MySQL... (8 Replies)
Discussion started by: _hp_
8 Replies

3. Shell Programming and Scripting

Problem with PHP and MySQL

Okay, I'm new to this PHP and MySQL stuff, so help would be VERY much appreciated. :) On my iMac runnning Panther, it has MySQL and PHP installed. Yet when I view a PHP file from the iMac or another computer at my house, I get the source code. What's wrong? (11 Replies)
Discussion started by: Danny_10
11 Replies

4. Shell Programming and Scripting

Mysql problem

No help guys??? :( Hi guys, i've got a question here... my intention is to write a script that would access a mysql db and extract some info and paste it into a file... so the first move would be, to access the mysql interface right? hence... #! /usr/bin/ksh echo "Job Begin: " `date` ... (1 Reply)
Discussion started by: 12yearold
1 Replies

5. Linux

MySQL server connetction problem

Hello,thanks for your help. I can't connect my MYSQLserver , the note from my Linux System is 'Error 1130 (00000): Host 'my ip address' is not allowed to connect to this MySQL server. What could I do on this? Thanks again! (4 Replies)
Discussion started by: lancepanda
4 Replies

6. Web Development

Deleting databases in MYSQL problem asking...

Hi, I'm the new user of mysql. I facing one problem to delete one of the database in mysql. Hope can get all of your suggestion and advice. Input: mysql> show databases; +-------------------------+ | Database | +-------------------------+ | information_schema | |... (3 Replies)
Discussion started by: patrick87
3 Replies

7. Shell Programming and Scripting

Mysql import problem

Dear folks, i am importing a database since yesterday that is innodb tablespace, the space of dump file is 4GB, almost 24 pass out it is not yet complete. What should i do to import it fastly. I have disable foreign key check because it have some issues so thats why i am importing it with source... (2 Replies)
Discussion started by: learnbash
2 Replies

8. UNIX and Linux Applications

mysql conflicts problem

:confused: hi all, RHEL 4 has installed on the server, when i use rpm -i command to install mysql5.1 enterprise version, error failed dependencies occurs as below: mysql conflicts with mysql-4.1.22-2.el4.i386 mysql conflicts with mysql-4.1.22-2.el4.x86_64 have tried rpm -e which was... (2 Replies)
Discussion started by: maxlee24
2 Replies

9. AIX

Configuring MySQL problem

Hi, Trying to setup mediawiki on a system but having problems configuring mysql: CC=/usr/bin ./configure checking build system type... powerpc-ibm-aix6.1.0.0 checking host system type... powerpc-ibm-aix6.1.0.0 checking target system type... powerpc-ibm-aix6.1.0.0 checking for a... (9 Replies)
Discussion started by: vpundit
9 Replies

10. Red Hat

Problem in installing mysql

Hi i am trying to install mysql rpm package on my linux machine but getting below error : warning: MySQL-embedded-5.5.28-1.rhel5.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5 error: Failed dependencies: MySQL-devel is needed by MySQL-embedded-5.5.28-1.rhel5.i386 ... (9 Replies)
Discussion started by: mukulverma2408
9 Replies
GAMMU-SMSD-DBI(7)						       Gammu							 GAMMU-SMSD-DBI(7)

NAME
gammu-smsd-dbi - gammu-smsd(1) backend using DBI abstraction layer to use any supported database as a message storage DESCRIPTION
DBI backend stores all data in any database supported by libdbi, which parameters are defined by configuration (see gammu-smsdrc for description of configuration options). For tables description see gammu-smsd-tables. This backend is based on gammu-smsd-sql. Note The DBI driver is currently not supported on Windows because libdbi library does not support this platform. CONFIGURATION
Before running gammu-smsd you need to create necessary tables in the database. You can use examples given in database specific backends parts of this manual to do that. The configuration file then can look like: [smsd] service = sql driver = DBI_DRIVER host = localhost See also gammu-smsdrc SUPPORTED DRIVERS
For complete list of drivers for libdbi see libdbi-drivers project. The drivers for example include: o sqlite3 - for SQLite 3 o mysql - for MySQL o pgsql - for PostgeSQL o freetds - for MS SQL Server or Sybase CREATING TABLES
SQL script for creating tables in SQLite database: CREATE TABLE daemons ( Start TEXT NOT NULL, Info TEXT NOT NULL ); CREATE TABLE gammu ( Version INTEGER NOT NULL DEFAULT '0' ); INSERT INTO gammu (Version) VALUES (13); CREATE TABLE inbox ( UpdatedInDB NUMERIC NOT NULL DEFAULT (datetime('now')), ReceivingDateTime NUMERIC NOT NULL DEFAULT (datetime('now')), Text TEXT NOT NULL, SenderNumber TEXT NOT NULL DEFAULT '', Coding TEXT NOT NULL DEFAULT 'Default_No_Compression', UDH TEXT NOT NULL, SMSCNumber TEXT NOT NULL DEFAULT '', Class INTEGER NOT NULL DEFAULT '-1', TextDecoded TEXT NOT NULL DEFAULT '', ID INTEGER PRIMARY KEY AUTOINCREMENT, RecipientID TEXT NOT NULL, Processed TEXT NOT NULL DEFAULT 'false', CHECK (Coding IN ('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression')) ); CREATE TRIGGER update_inbox_time UPDATE ON inbox BEGIN UPDATE inbox SET UpdatedInDB = datetime('now') WHERE ID = old.ID; END; CREATE TABLE outbox ( UpdatedInDB NUMERIC NOT NULL DEFAULT (datetime('now')), InsertIntoDB NUMERIC NOT NULL DEFAULT (datetime('now')), SendingDateTime NUMERIC NOT NULL DEFAULT (datetime('now')), SendBefore time NOT NULL DEFAULT '23:59:59', SendAfter time NOT NULL DEFAULT '00:00:00', Text TEXT, DestinationNumber TEXT NOT NULL DEFAULT '', Coding TEXT NOT NULL DEFAULT 'Default_No_Compression', UDH TEXT, Class INTEGER DEFAULT '-1', TextDecoded TEXT NOT NULL DEFAULT '', ID INTEGER PRIMARY KEY AUTOINCREMENT, MultiPart TEXT NOT NULL DEFAULT 'false', RelativeValidity INTEGER DEFAULT '-1', SenderID TEXT, SendingTimeOut NUMERIC NOT NULL DEFAULT (datetime('now')), DeliveryReport TEXT DEFAULT 'default', CreatorID TEXT NOT NULL, CHECK (Coding IN ('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression')), CHECK (DeliveryReport IN ('default','yes','no')) ); CREATE INDEX outbox_date ON outbox(SendingDateTime, SendingTimeOut); CREATE INDEX outbox_sender ON outbox(SenderID); CREATE TRIGGER update_outbox_time UPDATE ON outbox BEGIN UPDATE outbox SET UpdatedInDB = datetime('now') WHERE ID = old.ID; END; CREATE TABLE outbox_multipart ( Text TEXT, Coding TEXT NOT NULL DEFAULT 'Default_No_Compression', UDH TEXT, Class INTEGER DEFAULT '-1', TextDecoded TEXT DEFAULT NULL, ID INTEGER, SequencePosition INTEGER NOT NULL DEFAULT '1', CHECK (Coding IN ('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression')), PRIMARY KEY (ID, SequencePosition) ); CREATE TABLE pbk ( ID INTEGER PRIMARY KEY AUTOINCREMENT, GroupID INTEGER NOT NULL DEFAULT '-1', Name TEXT NOT NULL, Number TEXT NOT NULL ); CREATE TABLE pbk_groups ( Name TEXT NOT NULL, ID INTEGER PRIMARY KEY AUTOINCREMENT ); CREATE TABLE phones ( ID TEXT NOT NULL, UpdatedInDB NUMERIC NOT NULL DEFAULT (datetime('now')), InsertIntoDB NUMERIC NOT NULL DEFAULT (datetime('now')), TimeOut NUMERIC NOT NULL DEFAULT (datetime('now')), Send TEXT NOT NULL DEFAULT 'no', Receive TEXT NOT NULL DEFAULT 'no', IMEI TEXT PRIMARY KEY NOT NULL, Client TEXT NOT NULL, Battery INTEGER NOT NULL DEFAULT -1, Signal INTEGER NOT NULL DEFAULT -1, Sent INTEGER NOT NULL DEFAULT 0, Received INTEGER NOT NULL DEFAULT 0 ); CREATE TRIGGER update_phones_time UPDATE ON phones BEGIN UPDATE phones SET UpdatedInDB = datetime('now') WHERE IMEI = old.IMEI; END; CREATE TABLE sentitems ( UpdatedInDB NUMERIC NOT NULL DEFAULT (datetime('now')), InsertIntoDB NUMERIC NOT NULL DEFAULT (datetime('now')), SendingDateTime NUMERIC NOT NULL DEFAULT (datetime('now')), DeliveryDateTime NUMERIC NULL, Text TEXT NOT NULL, DestinationNumber TEXT NOT NULL DEFAULT '', Coding TEXT NOT NULL DEFAULT 'Default_No_Compression', UDH TEXT NOT NULL, SMSCNumber TEXT NOT NULL DEFAULT '', Class INTEGER NOT NULL DEFAULT '-1', TextDecoded TEXT NOT NULL DEFAULT '', ID INTEGER, SenderID TEXT NOT NULL, SequencePosition INTEGER NOT NULL DEFAULT '1', Status TEXT NOT NULL DEFAULT 'SendingOK', StatusError INTEGER NOT NULL DEFAULT '-1', TPMR INTEGER NOT NULL DEFAULT '-1', RelativeValidity INTEGER NOT NULL DEFAULT '-1', CreatorID TEXT NOT NULL, CHECK (Status IN ('SendingOK','SendingOKNoReport','SendingError','DeliveryOK','DeliveryFailed','DeliveryPending', 'DeliveryUnknown','Error')), CHECK (Coding IN ('Default_No_Compression','Unicode_No_Compression','8bit','Default_Compression','Unicode_Compression')) , PRIMARY KEY (ID, SequencePosition) ); CREATE INDEX sentitems_date ON sentitems(DeliveryDateTime); CREATE INDEX sentitems_tpmr ON sentitems(TPMR); CREATE INDEX sentitems_dest ON sentitems(DestinationNumber); CREATE INDEX sentitems_sender ON sentitems(SenderID); CREATE TRIGGER update_sentitems_time UPDATE ON sentitems BEGIN UPDATE sentitems SET UpdatedInDB = datetime('now') WHERE ID = old.ID; END; Note You can find the script in docs/sql/sqlite.sql as well. There are also scripts for other databases in same folder. UPGRADING TABLES
The easiest way to upgrade database structure is to backup old one and start with creating new one based on example above. For upgrading existing database, you can use changes described in smsd-tables-history and then manually update Version field in gammu ta- ble. AUTHOR
Michal iha <michal@cihar.com> COPYRIGHT
2009-2012, Michal iha <michal@cihar.com> 1.31.90 February 24, 2012 GAMMU-SMSD-DBI(7)
All times are GMT -4. The time now is 03:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy