mysql-query

How to run benchmarking on MySQL?

My server has installed MySQL Server 5.1. I would like to run benchmarking on the MySQL, but I couldn't found sql-bench, which is Benchmark Suite provided by MySQL. The MySQL Benchmark Suite seem like complicated to be install or setup into my server. I need one can be direct setup to test the benchmark without using Perl script liked ...

Saving commands for later re-use in MySQL?

What would be the equivalant in MySQL for: Saving a command for later reuse. eg: alias command1='select count(*) from sometable;' Where then I simply type command 1 to get the count for SomeTable. Saving just a string, or rather part of a command. eg: select * from sometable where $complex_where_logic$ order by attr1 desc; WHere $co...

How to order results based on number of search term matches?

I am using the following InnoDB tables in mysql to describe records that can have multiple searchtags associated with them: TABLE records ID title desc TABLE searchTags ID name TABLE recordSearchTags recordID searchTagID To SELECT records based on arbitrary search input, I have a statement that looks sort...

mysqldump from a query

How do we take a mysql dump for table from a query I need something like this.. `mysqldump -uroot -pxxxx mydb "select * from table where name='1';" > /tmp/a Thanks ...

sort mysql query by filtered query

I have two mysql queries: $sql = "SELECT * FROM content WHERE threadName LIKE '%$filter%' ORDER BY lastUpdated desc"; and $sql = "SELECT * FROM content ORDER BY lastUpdated desc"; The end result is to have all rows returned from a particular table 'content' but have those that match the variable $filter at the top. Is there either ...

mysql UNION query not working

What am I doing wrong with this: $sql = "SELECT * FROM content WHERE threadName LIKE '%$filter%' ORDER BY lastUpdated desc UNION SELECT * FROM content WHERE threadName NOT LIKE '%$filter%' ORDER BY lastUpdated desc"; The first statement before the UNION works well on its own, but this one above returns: mysql_fetch_array() w...

How to count all rows when using SELECT with LIMIT in MySQL query?

I've got a mysql query like this: SELECT A.ID, A.NAME, B.ID, B.NAME FROM table1 A JOIN table2 B ON ( A.ID = B.TABLE1_ID ) WHERE cond1, cond2, ..., condN LIMIT 10 I've got many where clauses in query. How to improve this query to get also full row count? I don't want to use one more request without LIMIT. ...

Stop 2 identical queries from executing almost simultaneously?

I have developed an AJAX based game where there is a bug caused (very remote, but in volume it happens at least once per hour) where for some reason two requests get sent to the processing page almost simultaneously (the last one I tracked, the requests were a difference of .0001 ms). There is a check right before the query is executed ...

mysql select two prior to and one after NOW()

Hi I have a table with a column event_time. How can I select two rows right before NOW() and the next one after NOW(), ordered by event_time? Is is possible with a single query? ...

MySQL Query to Count Unique Domains from Email Address field

I'd like to get a better idea of what domains my customers are using. I could easily do this in PHP by explodeing each address and counting the domain that way. But I'm wondering if there's a way to get this information with just a plain MySQL query? This is what sample output would look like: gmail.com | 3942 yahoo.com | 3852 hotmai...

I'm trying to populate a MySQL table with some data, but, mysqli won't let me insert every 10th statement

I want to initialise a 'ticket' table with some ticket IDs. To do this, I want to insert 120 ticket IDs into the table. However, at every 10th statement, MySQL tells me that the ID already exists and thus won't let me insert it. Here's my code: //make a query $insert_ticket_query = "INSERT INTO ticket (id) VALUES (?)"; $inse...

Sorting MySQL table by next due date

Hi folks, I have a MySQL table that stores (amongst other things) a persons date of birth. Is there any way to sort the table so the next due birthday is at the top? I have the date stored in standard yyyy-mm-dd DATE format and seperate year, month and day fields so I can sort it by the first birthday of the year (ORDER BY month, d...

wordpress generating slow mysql queries - is it index problem?

Hello Stack Overflow I've got very slow Mysql queries coming up from my wordpress site. It's making everything slow and I think this is eating up CPU usage. I've pasted the Explain results for the two most frequently problematic queries below. This is a typical result - although very occasionally teh queries do seem to be performed at a...

Monitoring used connections on mysql to debug 'too many connections'

On LAMP production server I get the 'too many connections' error from MYSQL occasionally, I want to add monitoring to find if the reason is that I exceed the max-connections limit. My question: How can I query from mysql or from mysqladmin the current number of used connections? (I noticed that show status gives total connections and n...

need explanation for this MySQL query .

I just came across this database query and wonder what exactly this query does..Please clarify .. select * from tablename order by priority='High' DESC, priority='Medium' DESC, priority='Low" DESC; ...

MySQL Math - Is it possible to calculate a correlation in a query?

In a MySQL (5.1) database table there is data that represents: how long a user takes to perform a task and how many items the user handled during the task. Would MySQL support correlating the data or do I need to use PHP/C# to calcuate? Where would I find a good formula to calculate correlation (it's been a long time since I last d...

How to get top 3 frequencies in MySQL?

Hello, In MySQL I have a table called "meanings" with three columns: "person" (int), "word" (byte, 16 possible values) "meaning" (byte, 26 possible values). A person assigns one or more meanings to each word: person word meaning ------------------- 1 1 4 1 2 19 1 2 7 <-- Note: second meaning for word 2 1 ...

MySQL, Implementing a ViewCount that automatically add +1 every time

I'm MySQL, I have a table full of docs. Each row represents a doc. I'd like to have a data column for "VIEWS" that automatically adds +1 every time the row is accessed and avoid needing to write a SQL UPDATE that hits the DB after the SELECT to get the doc in the web app. Any smart clever ways to solve for this? Thanks ...

Mysql compare using left(X,2)="AB" or X like "AB%" for speed?

Which will perform better when searching for a key with a specific prefix in MySQL? ;- i) where left(X,2)="AB" or ii) where X like "AB%" ...

free sql script to get a list of countries, provinces/states and their cities.

I am working on a registration page for a php website as mysql as the backend database. I need a sql script to insert the list of countries with their associated provinces and the provinces with their associated cities. I need all the countries, provinces and cities all over the world which are related to each other. I can get the indi...