mysql

Comparing date ranges

In mysql, If I have a list of date ranges (range-start and range-end). e.g. 10/06/1983 to 14/06/1983 15/07/1983 to 16/07/1983 18/07/1983 to 18/07/1983 And I want to check if another date range contains ANY of the ranges already in the list, how would I do that? e.g. 06/06/1983 to 18/06/1983 = IN LIST 10/06/1983 to 11/06/1983 = IN ...

MySQL and data file encryption

Hi, Is there a way to encrypt the data file that mysql uses? I have a mysql server on an open machine, and I would like to encrypt the data file so even if someone copies the data files, they cannot read the data. Thanks ...

varchar(255) v tinyblob v tinytext

My side question is there really any difference between tinyblob & tinytext? Buy my real question is what reason, if any, would I choose varchar(255) over tinyblob or tinytext? ...

How would you handle a very large vector in Ruby?

I'm planning to write a program in Ruby to analyse some data which has come back from an online questionnaire. There are hundreds of thousands of responses, and each respondent answers about 200 questions. Each question is multiple-choice, so there are a fixed number of possible responses to each. The intention is to use a piece of demo...

How can I be sure the whole MySQL DB is loaded in memory?

I am running a mysql server. I would like to somehow make sure that the whole DB is loaded into the ram as I heard it would be alot faster. Is this true? and how do I vertify it? ...

Can I make Hibernate transparently avoid string duplication in the database?

I have a Java program that uses Hibernate and MySQL to store a lot of tracing data about the use of the Eclipse IDE. This data contains a lot of strings such as method names, directories, perspective name, etc. For example, an event object (which is then reflected in a record) can specify the source file and the current method, the use...

Best way to validate user input JDBC?

Is there a built-in way to escape user input in java using the JDBC? Something similar to the php version mysql_real_escape() function. What's the best way to validate input? ...

Best way to search in a table and get results and number of results (MySQL)

I have a table of "items", and a table of "itemkeywords". When a user searches for a keyword, I want to give him one page of results plus the total number of results. What I'm doing currently is (for a user that searches "a b c": SELECT DISTINCT {fields I want} FROM itemkeywords JOIN items WHERE (keyword = 'a' or keyword='b' o...

MySQL5: Delete all but the 50 newest rows

I have a SQL table with news stories and Unix timestamps. I'd like to only keep the 50 newest stories. How would I write an SQL statement to delete any amount of older stories? Edit: See my answer ...

What is mysql mostly doing?

Is there any way to see an overview of what kind of queries are spent the most time on every day on mysql? ...

MySQL Row Format: Difference between fixed and dynamic?

MySQL specifies the row format of a table as either fixed or dynamic, depending on the column data types. If a table has a variable-length column data type, such as TEXT or VARCHAR, the row format is dynamic; otherwise, it's fixed. My question is, what's the difference between the two row formats? Is one more efficient than the other? ...

Loading .sql files from within PHP

I'm creating an installation script for an application that I'm developing and need to create databases dynamically from within PHP. I've got it to create the database but now I need to load in several .sql files. I had planned to open the file and mysql_query it a line at a time - until I looked at the schema files and realised they are...

Is having different users for different types of queries a good practice?

I am using MySQL and PHP for a project I am working. I have created separate users for carrying out different functions (one for running select queries, one for running update queries, etc.) to provide an extra layer of security. This way, I figure if someone does manage to carry out an injection attack (which is unlikely since I am us...

Does mysqldump --password really do what it says?

I'm trying to use mysqldump to dump a schema, and it mostly works but I ran into one curiosity: the -p or --password option seems like it is doing something other than setting the password (as the man page and --help output say it should). Specifically, it looks like it's doing what is indicated here: http://snippets.dzone.com/posts/sho...

What are your favorite Ruby on Rails books and why?

I'm looking to pick up a few books on RoR to help teach myself how to build a scalable RoR app. I have read the RailsSpace book, and am starting the Rails Way book tonight. Some topics of interest are: REST - considering using Amazon's SimpleDB Using RSpec effectively memcached - server architecture and code implementation mongrel -...

SQL clone record with a unique index

Is there a clean way of cloning a record in SQL that has an index(auto increment). I want to clone all the fields except the index. I currently have to enumerate every field, and use that in an insert select, and I would rather not explicitly list all of the fields, as they may change over time. ...

Search for text between delimiters in MySQL

I am trying to extract a certain part of a column that is between delimiters. e.g. find foo in the following test 'esf :foo: bar So in the above I'd want to return foo, but all the regexp functions only return true|false, is there a way to do this in MySQL ...

How to use GROUP BY to concatenate strings in MySQL?

Basically the question is how to get from this: id string 1 A 1 B 2 C to this: id string 1 A B 2 C ...

Is there a disadvantage to blindly using INSERT in MySQL?

Often I want to add a value to a table or update the value if its key already exists. This can be accomplished in several ways, assuming a primary or unique key is set on the 'user_id' and 'pref_key' columns in the example: 1. Blind insert, update if receiving a duplicate key error: // Try to insert as a new value INSERT INTO my_prefs ...

mysql "drop database" takes time -- why?

mysql5.0 with a pair of databases "A" and "B", both with large innodb tables. "drop database A;" freezes database "B" for a couple minutes. Nothing is using "A" at that point, so why is this such an intensive operation? Bonus points: Given that we use "A", upload data into "B", and then switch to using "B", how can we do this faster? Dr...