LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2007, 07:09 AM   #1
stephencassidy
LQ Newbie
 
Registered: Jan 2006
Posts: 4

Rep: Reputation: 0
MySql stuck


Hi all, hope someone can help.

I am trying to write some kind of script that will delete rows from a MySQL table using a parameter that I pass to it

My table has 3 colums and I want to delete the rows where the value in one of the colums matches a value passed programatically by a script.

I have create a file called remove_records.sql

delete from filenames where path="qp-ms"

then I do mysql -u username -p password < remove_records.sql

this works but I need to change the value of path frequently.

Hope all this makes some kind of sense?

Thanks

Stephen
 
Old 03-29-2007, 11:52 AM   #2
mjones490
Member
 
Registered: Sep 2005
Distribution: LFS
Posts: 60

Rep: Reputation: 22
Perhaps a shell script like:

Code:
#!/bin/bash
echo delete from filenames where path=\"$1\" | mysql -u username -p password
would work.
 
Old 03-29-2007, 12:54 PM   #3
derzok
Member
 
Registered: Aug 2004
Location: Ohio
Distribution: Debian, Slackware
Posts: 58

Rep: Reputation: 15
In perl:

Code:
use DBI;
sub dbconnect {
        my $platform = "mysql";
        my $database = "dbname";
        my $host = "localhost";
        my $port = "3306";
        my $tablename = "tablename";
        my $user = "dbuser";
        my $password = "dbpass";
        my $dsn = "DBI:mysql:database=$database;host=$host;port=$port";
        $dbh = DBI->connect($dsn,$user,$password,);
}

&dbconnect;
$sth = $dbh->prepare("DELETE FROM `tablename` WHERE `field`=`'value'");
$sth->execute();
 
Old 03-30-2007, 04:58 AM   #4
stephencassidy
LQ Newbie
 
Registered: Jan 2006
Posts: 4

Original Poster
Rep: Reputation: 0
Talking Excellent

Thanks for that, Mark I opted for your version and it worked a treat.

Thanks both for taking the time to help me out.

Stephen
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. NoviceW Linux - Networking 17 09-17-2014 02:13 PM
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. suziecorbett Linux - Software 8 10-09-2008 01:52 AM
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) sunlinux Linux - Software 1 11-07-2006 12:08 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
Installing LAMP with MySQL 4.1 - close but stuck with Apache problem David Mann Linux - Software 2 11-10-2004 08:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration