mysql

Large amounts of text - mysql or flatfile?

I am writing a web application in PHP that will store large numbers of blocks of arbitrary length text. Is MySQL well suited for this task with a longtext field or similar, or should I store each block of text in its own file and use a MySQL table for indexes and filenames? Think online bulletin board type stuff, like how you would store...

How can I create a threshold for similar strings using Levenshtein distance and account for typos?

We recently encountered an interesting problem at work where we discovered duplicate user submitted data in our database. We realized that the Levenshtein distance between most of this data was simply the difference between the 2 strings in question. That indicates that if we simply add characters from one string into the other then we e...

Set up large database in MySQL for analysis in R

I have reached the limit of RAM in analyzing large datasets in R. I think my next step is to import these data into a MySQL database and use the RMySQL package. Largely because I don't know database lingo, I haven't been able to figure out how to get beyond installing MySQL with hours of Googling and RSeeking (I am running MySQL and MySQ...

A simple MySQL query taking forever (more than 20 minutes!)

Hello, Maybe you can help me. I need to query 3 tables in order to get data for a financial stock. The idea is to go to the instruments table, find the index for each instrument and then bring all the prices for that particular instrument together with the indicators that are on a separate table. Tables stockdata and indicators are bot...

Tough Mysql Query ....

Hi guys, I am trying to do a complex query from two tables...It's a question from a skill quiz.... table **Orders Customer**s id id date first_name shipping_amount last_name order_stat...

Proper way to save a 1970 type date

I have a date that looks like 1003029303, which I guess is what's known as a linux UNIX time stamp. What format should I save it as in a mysql database? I don't suppose that an int(10) is the right way. `gottime` int(10) ...

which one is faster/smarter and why: COUNT(*) or storing the numbers each the do something

PHP $total_points = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM account WHERE id='$id'"),0) Mysql account table |user_id| mysql points table |id | user_id | points | or PHP $total_points = mysql_query("SELECT points FROM account WHERE id='$id'"); Mysql account table |user_id| points | Mysql points table |id | u...

How do I check for duplicate column values in the table before I insert them with Perl?

I am reading a file which contains a record in each line. I am extracting the contents of the file and inserting it as column values into a table. The problem I face is, suppose if i insert a record into a table after reading from the file, I want to remove the duplicate fields. For example: NAME age time Tom 21 10:30 Tom 21 12:21...

Count(*) with 0 for boolean field

Let's say I have a boolean field in a database table and I want to get a tally of how many are 1 and how many are 0. Currently I am doing: SELECT 'yes' AS result, COUNT( * ) AS num FROM `table` WHERE field = 1 UNION SELECT 'no' AS result, COUNT( * ) AS num FROM `table` WHERE field = 0; Is there an easier way to get the resu...

Why is my database backup script not working in php?

I am using the Database Backup script by David Walsh(http://davidwalsh.name/backup-mysql-database-php) to backup my MYSQL database as a .sql file to my server. I created a user named backup and gave it all privileges(just to make sure). Then I put the code into a php file and setup a cron job to run the php file. This is the code: /* ...

MySQL filter query with relation

Hi, I'm having the following problem with 2 MySQL tables that have a relation: I can easily query table 1 (address) when I want a full list or filter the result by name or email or such. But now I need to query table 1 and filter it based on the relational content of table 2 (interests). So, I need to find a row (usually many rows) in ta...

Batch Update fails - Rollback operation

I've created a PreparedStatement and have added a couple of data in a bactch PreparedStatement ps = conn.PreparedStatement("INSERT into table (a, b) values (?, ?)"; ps.setInt(1, 1); ps.setInt(2, 2); ps.addBatch ps.setInt(1, 4); ps.setInt(2, 5); ps.addBatch Now when I execute ps. I get the result, now lets say ps fails, then I want...

How to create an MySQL query alias?

For example I use this select * from tab1; every 5 minutes. Is there a way to set up an alias p so that I can just do p instead and that query is executed? ...

Storing associative array in MySQL DB

Hello, I'd like to store associative array containg mostly strings and integers as values in db. I was thinking: implode/explode - need to find delimiter, which won't be in values - since it's almost user generated, not safe XML - feels to heavy for the job (creating/reading values) json - if i need only to work with json_decode/json...

Most convenient way to save data and make backups in MySQL

Hi, one of my colleagues suggested that I should make different databases (MySQL) for each client, so that if one account is compromised, we only need to restore a backup of a single database. I'm concerned about a fast access to the data: which is faster? selecting a database among thousands of them, or finding an entry among thousands ...

MySQL Select, column with same name from multiple tables, order by another column with same name

I'm trying to select rows with a certain column name and order them by another column name. Here's my problem, into N simplified tables: table 1: id, username, datetime, comment table 2: id, username, datetime, vote . . . table N: id, username, datetime, bought I want to be able to select all rows where username='Some Name', ord...

MySQL Cerification

I am PHP / MySQL programmer. I want to know what do you think about MySQL Certification (for developers)? In my opinion it looks like simple but expensive exam (~2 x 200$). Is it worth to pass it? ...

Why am I getting 'access denied for user' error in php?

I am running this code: include '../includes/connection.php'; $conn = dbConnect('backup'); $tableName = 'orders'; $backupFile = '../backup/db-backup(' . $date . ').sql'; $query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName"; $result = $conn->query($query) or die(mysqli_error($conn)); I am getting this error: Access...

Not able to get the amazon RDS instances using AWS .NET SDK.

I'm not able to connect to my database in RDS from local machine.... Here is my code: Amazon.RDS.AmazonRDSClient client = new Amazon.RDS.AmazonRDSClient(myPublicKey, myPrivateKey); Amazon.RDS.Model.DescribeDBInstancesRequest instanceRequest = new Amazon.RDS.Model.DescribeDBInstancesRequest(); Amazon.RDS.Model.DescribeDBInstancesRespo...

improve a mysql query.

I have a query. DELETE FROM A WHERE i NOT IN ( SELECT i FROM B WHERE j = 1 UNION select i from C UNION select i from D ); basically delete all rows in A where field i does not occur in tables B, C or D. If it was just DELETE FROM A WHERE i NOT IN ( SELECT i FROM B ); then that could be done easility with a left join ...