Log in

LiveJournal for MySQL Community.

View:User Info.
View:Website (www.mysql.org).
You're looking at the latest 20 entries. Missed some entries? Then simply jump back 20 entries.

Friday, October 15th, 2010

Subject:Efficient full-text searchs on large sets of data
Posted by:shadesogrey.
Time:11:48 am.
A database application I've written uses a table with around 600,000 rows. Each row has a text field 500-5000 characters long. I periodically need to find all the rows containing a particular phone number, name, or address, ie.'123-4567', 'john smith', '1950 Main St N'

I'm doing this using
SELECT * FROM `tb_archive` WHERE `text` LIKE '%john smith%' ORDER BY `date` DESC

The problem is that it is too slow. Most searches take 30-60 seconds. If multiple searches are done the server response begins to slow to a crawl for other users.

I've looked at mysql built in full-text indexing - but I'm not sure if it can work since I only need exact matches, don't care about relavence, and often search for numbers and short words.

Any suggestions as to how I can do this more efficiently?
Comments: Read 3 orAdd Your Own.

Tuesday, March 2nd, 2010

Subject:A question of logic
Posted by:pkbarbiedoll.
Time:11:45 am.
I've struggled with this for a few days now and thought some of you may have insight.

I need to display four columns of data from this table:


(Review_id is a set of questions given to a member. Each colum represents questions for a given member, from a specific review_id. The idea is to compare review answers between 4 members)

Displaying a single member's results is easy enough to query. But where I am stuck is showing multiple member question/answers on the same screen, side by side. I'm tempted to nest queries with PHP. But maybe there is a better way?

I cannot change the layout of the page -- must have four columns, with answers listed on each row.

Comments: Read 6 orAdd Your Own.

Friday, October 9th, 2009

Subject:Database in SVN
Posted by:miquel_fire.
Time:2:06 pm.
Anyone know how to store a MySQL database schema (and maybe data from some tables hopefully based on table structure) into SVN?
Comments: Read 5 orAdd Your Own.

Tuesday, September 22nd, 2009

Subject:Effective coding
Posted by:siliconstitches.
Time:7:23 pm.
I found an instruction set that said to list the first, and last name of all employees that had neither 'SON' nor 'DAUGHTER' listed in their dependency files. I came up with a query that gave me the results I wanted by assuming the database only takes SPOUSE, SON, and DAUGHTER, but assuming has always caused me trouble, so I would like to know: Is there any better way I could have gone about approaching this so it's not going by a general assumption of dep_relation = 1, and so forth?

The Gory Details BelowCollapse )

So really, I covered the "Son nor Daughter" case, but it's the count = 1 that I feel could be "bettered" so to speak.

I appreciate the feedback. ;]
Comments: Read 11 orAdd Your Own.

Tuesday, September 1st, 2009

Posted by:xscene_laura.
Time:10:09 am.
i have this thing on another page it works but its like the same and doesnt work on the page im working on. this is what it is:
SELECT column, column2 FROM table
doesnt work. only shows column one. ive done all the variations i can think of SELECT `column1`, `column2` ectttt fucking ect does anyone know why this is o pathetic and will NOT WORK?
Comments: Read 6 orAdd Your Own.

Saturday, August 8th, 2009

Posted by:mermaid.
Time:12:04 am.
I am not entirely sure if this is the right place to ask but I thought to give it a shot anyway.
I want to create a new MySQL Database so I downloaded MySQL 4.1.22 for Windows and installed it. After installing it I have the program MySQL Command Line Client and MySQL Server Instance Config Wizard. For both of them I need a root user name and a root password but how do I know those, where can I find them?
i hope you can help me.
Comments: Read 2 orAdd Your Own.

Monday, July 20th, 2009

Subject:oracle blob to mysql blob *update*
Posted by:eskander.
Time:3:03 pm.
hey again
i'm trying to convert an oracle db to mysql. so far everything is going ok except for the files in the db. the old admin was storing jpg, pdf, doc, xml files and whatever else you can think of into a blob field in the table on oracle.

is this the best way to do things? i mean sure all you need to do is back up the database and presto you have all the files. but i'm having a hell of a time getting a backup. 440 entries in the table comes up to a 180 megabyte text file. phpmyadmin won't process the file because it times out, sqlyog and navicat are having trouble with the file size saying they're running out of memory.

the closest i've come to completing this transfer is using toad for oracle and outputting the table to an mdb file. then in navicat i use the wizard and import the mdb, it sees the fields of the table perfectly, but the blobs come out having 0k. aside from that small issue i keep getting error 2006 when importing. and lose between 3 and 219 entries depending on the time i'm importing.

so, at a loss, am i doing things right? is it possible to convert oracle blobs to mysql blobs? personally if i had written the original site i would just save a link to the actual file in the db and not store the actual file in the db. does that make sense?

so i tried using the migration tool, no luck. i'm missing libraries and my tech guy wasn't here yesterday. the site for the oracle libraries didn't want to work either.
so this is what i ended up doing:
in toad i saved a csv/txt file of the table without the blobs in the csv. cut the size down to 88k.
i uploaded that via sqlyog into the db. no problems.
then in toad i saved the blobs themselves as individual .dat files. so at least i have the files this way.
the db actually has the filename in it, so it was just a simple extracting the filename, copying the .dat files from one folder to another on the server with a simple php script and changing the names to reflect their actual names. all the files can be opened no problem once the name have been changed.

now i just need to link to said files from db to directory on the server.

thanks again for the input :)
Comments: Read 2 orAdd Your Own.

Tuesday, July 14th, 2009

Subject:Searching and counting
Posted by:lsergei.
Time:5:49 pm.
I have some difficulties in building a right query for a situation. A MySQL Table 'patients' looks like this

Name Doctor Date
John Deere Dr.Watson 2009-02-11
Bill Fairy Dr.Dylan 2009-03-03
John Deere Dr.Dylan 2009-05-19

I'm trying to count records with same Name field AND all other fields in reply must contain appropriate field in LAST record (based in Date field). I'm doing following query:

SELECT *, COUNT(*) AS num FROM patients GROUP BY name, HAVING COUNT(*)>1 ORDER BY date DESC;

I think that ORDER BY DESC helps me to get in reply fields of last record. But in reply I always receive data contained in my oldest record :( I stumbled :) Anyone can help?

Thanks in advance.
Comments: Read 3 orAdd Your Own.

Sunday, July 12th, 2009

Subject:selecting part of the data in a field
Posted by:switchstatement.
Time:2:37 pm.
i have a field with a full street address, something like "1234 main st." is it possible to select just the numerical part of the data?

i ask because i need to compare that to another field. so it'd be real easy to just do something like

select * from `table` where (MAGIC, `address`) = `other_field`
Comments: Read 2 orAdd Your Own.

Monday, July 6th, 2009

Subject:How to Merge Databases?
Posted by:kinnerc.
Time:9:43 am.
I have two tables (same DB format) that I'd like to merge.

One table has the format of several colums:

ID, AlphaCol, BetaCol, GammaCol

The other has different columns:

ID, Foo, Bar, Baz

The ID colum in both are what ties the separate tables together.

I started out the process with the following command:

create table combinedtable select * from firsttable;

This created combinedtable with the columns ID, AlphaCol, BetaCol, GammaCol. Everything's cool so far.

Then, I thought I could do a command like:

insert into combinedtable select secondtable.Foo, secondtable.Bar, secondtable.Baz from secondtable, combinedtable where combinedtable.ID = secondtable.ID;

When I try this, however, I consistently get the error:

Error 1136 (21S01): Column doesn't match value count at row 1.

So, I'm missing something basic, but I didn't think this would be that difficult. What am I doing wrong?
Comments: Read 2 orAdd Your Own.

Tuesday, June 23rd, 2009

Subject:Is ref: NULL bad?
Posted by:pkbarbiedoll.
Time:12:25 pm.
In the EXPLAIN below, is ref: NULL a bad thing?

mysql> explain SELECT * FROM mytable WHERE item_id='09N1320347' AND value_id IN (2,3,4,5,6,7,8,9);
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
| 1 | SIMPLE | mytable | range | PRIMARY,item_id | item_id | 18 | NULL | 6 | Using where |
1 row in set (0.00 sec)

Keyname Type Cardinality Action Field
PRIMARY PRIMARY 2240917 item_id, color_id
item_id INDEX 93371 item_id, value_id
Comments: Read 2 orAdd Your Own.

Friday, June 19th, 2009

Subject:Best schema for these requirements?
Posted by:pkbarbiedoll.
Time:8:22 am.
I've been handed a legacy app with a mysql database to extend/upgrade. The system is a mess. Lab tests are stored in a single table, with over 200 columns containing marker values. The labtest table includes the DateTestCollected. A separate table holds patient demographics, including DateOfBirth and Sex.

In the past, we scanned lab results and identified possible abnormalities based on one or more markers. The same cutoff values were used regardless of age or sex. So -- SELECT COUNT(*) FROM labtest WHERE marker_1>$m_1_cutoff_high OR marker_1<$m_1_cutoff_low; Even with the less than ideal schema, indexes on the marker columns made this kind of query work relatively well.

New algorithms are being put into place. Instead of just looking at one or two markers, we now must look at the age & sex to determine which cutoff values to use, then apply our algorithm. I now have 12 possible variations of the same algorithm.


date_of_test>'2008-01-01' AND
date_of_test<'2008-04-01' AND

( age_rage='0-9' AND sex='m' AND ( marker_1 < 876 AND marker_1 > 345) ) OR
( age_rage='10-19' AND sex='m' AND ( marker_1 < 824 AND marker_1 > 312) ) OR
( age_rage='20-29' AND sex='m' AND ( marker_1 < 798 AND marker_1 > 311) )

) OR (

( age_rage='0-9' AND sex='f' AND ( marker_1 < 987 AND marker_1 > 465) ) OR
( age_rage='10-19' AND sex='f' AND ( marker_1 < 813 AND marker_1 > 404) ) OR
( age_rage='20-29' AND sex='f' AND ( marker_1 < 701 AND marker_1 > 209) )

) OR (
/* ect */

There are actually 12 variations to check against. This query is very slow, especially when iterating through 200+ markers (200 x 12 variations). EXPLAIN showed that MySQL is scanning all rows (50,000) - as soon as I applied a multi-column index (date_of_test, marker_1) MySQL stopped scanning the entire table.

Under the current schema, each marker, age, sex, and date_of_test column is indexed separately (no multi-column indexes). There are limits to the number of indexes per table.

So that's where I am. I have a legacy system in need of work, but I'm not sure of the best, most efficient way of approaching the problem.

I thought of converting the labtest table to something like (labtest_id, marker_id, marker_value), but that alone doesn't solve the issue of having to find the age & sex of each patient to determine the correct marker cutoff value.

What would be the least painful way of working through this?
Comments: Read 2 orAdd Your Own.

Friday, June 5th, 2009

Subject:Pivs Not Showing Up?
Posted by:kinnerc.
Time:10:45 am.
Hi Folks. I'm hoping this is a simple question, but its baffling me.

I have a mySQL 5.0.27 DB. I am trying to give people "show view" and "create view" privs for a specific database. When I execute the commands to do this, they seem to be accepted with no problem - no syntax error, no warning. However when I then do a show grants on the person the "view privs" do not show up, and they confirm that they do not have those privs.

I have flushed privileges as well, which was my first thought, but that is not the case.

I do seem to be able to grant or revoke other privs.

Views are new to us, but they were included in 5.0.1 so I should have them.

Anyone have any thoughts?
Comments: Read 4 orAdd Your Own.

Wednesday, April 22nd, 2009

Subject:select + asterisk
Posted by:spacefem.
Time:6:07 pm.
is it bad to do "SELECT *"? What if you're really pulling every column?
Comments: Read 4 orAdd Your Own.

Saturday, April 4th, 2009

Subject:Message Board
Posted by:246_slc.
Time:4:21 pm.

I want to write my own little message board.
Post something…and allow others to respond, keeping message trees intact.

I’ve no idea how to manage the database for something like this.
Can anyone give me a recommendation (book or website) that might give me a clue?


Comments: Read 3 orAdd Your Own.

Wednesday, April 1st, 2009

Subject:updating a database from a received email
Posted by:eskander.
Time:12:35 pm.
hey everyone,
i've got a problem and having a hard time wrapping my head around a solution.

i'm writing an app in php that will send an email notification to about 100 people, my boss wants to know how many people actually open the emails, so what i've done is created a field in the db for views.

what i want to do is when someone opens the email it increments the views by 1. simple enough right?
i thought maybe i'd hide an iframe in the email that goes to a php script on the server that would update the views in the db. hit a road block since 99% of email clients now block or disable iframes in emails.

so are there any other ways to go about doing this?
Comments: Read 12 orAdd Your Own.

Monday, March 30th, 2009

Subject:Indexes and DB Writes...
Posted by:kinnerc.
Time:12:34 pm.
We are all familiar with how valuable indexes are to mySQL (and in general) database reads. However - and specifically with respect to mySQL - what effect to indexes have to database writes?

A colleague of mine, as we are changing our DB indexing structure, has argued that indexes harm database writes since the data must be written to the database and to the index. This is a compelling argument. However, in my last job in working with Sybase SQL databases we had instances where indexes would greatly increase write efficiency apparently. I had specific experience that this was the case, but no one was able to explain to me how that was the case given what I could see where the data would have to be written in two separate places.

So, how do indexes effect the efficiency of database writes in mySQL?
Comments: Read 6 orAdd Your Own.

Tuesday, February 3rd, 2009

Subject:Selective Replication in mySQL 5.X
Posted by:kinnerc.
Time:10:46 am.
Folks may remember last week when I was asking questions about mysqldumps. I was doing that in order to get a DB backup for a specific database we wanted to replicate on another server, and I've been working on that.

After some hit and miss I think I nearly got it working, at least to a point where the replication started between the Master and the slave. It seemed to work for a few seconds, then bombed when the slave tried to execute a statement that was for a DB that it didn't have in it.

The point is that of all the several databases on the Master machine, at this point we only want to replicate one on the slave machine. I thought I had had that set up in the slave's my.cnf with the line

replicate-do-db - aid #aid is the database we want to replicate

however High Performance MySQL says that this is not the way to do this since filtering will be done on the current default database. "This is not usually what you want." :-)

The book does indicate that "On the slave, the relicate_* options filter events as the slave SQL thread reads them from the relay log." This make sense to me, and at this point it also makes sense that the log coming from the master has every statement coming into the DB. It goes on to say that "You can replicate or ignore one or more databases (emphasis mine)...based on LIKE pattern matching syntax." There is where I lose it. I understand how to use the LIKE syntax in mySQL statements, but not in this environment.

Is it possible to set up a small battery of statements in the slave my.cnf along the lines of:

replicate_ignore_table = .%

Would that do it?

Is anyone basically doing replication in a simple Master-Slave relationship where you are only replicating one DB? If so, how are you doing it?

THANKS, folks!
Comments: Read 2 orAdd Your Own.

Wednesday, January 28th, 2009

Subject:Restoring from a mySQLDump...
Posted by:kinnerc.
Time:1:29 pm.
Folks, I'm having what I think is a weird problem restoring a DB from a mysqldump. What I'm trying to do is basically copy a DB from one mysql database server to another.

The mysqldump command I used originally was:

mysqldump --quick --add-locks --extended-insert -u root -p dbname > dbname.sql

When this didn't work upon restoration I also tried:

mysqldump --opt -u root -p dbname > dbname.sql

Both these commands created the dbname.sql file with no problems or complaints.

I copied the SQL file over to the target computer. I went into mySQL as root and did:

create database dbname;
use dbname;
source dbname.sql;

The import would start, but it wouldn't get very far. In the end, after not many seconds it would just...stop. Here is an example:

Query OK, 8708 rows affected (0.11 sec)
Records: 8708 Duplicates: 0 Warnings: 0

Query OK, 8750 rows affected (0.12 sec)
Records: 8750 Duplicates: 0 Warnings: 0

Query OK, 8740 rows affected (0.11 sec)
Records: 8740 Duplicates: 0 Warnings: 0

Query OK, 8758 rows affected (0.11 sec)
Records: 8758 Duplicates: 0 Warnings: 0

Query OK, 8745 rows affected (0.12 sec)
Records: 8745 Duplicates: 0 Warnings: 0

And it would just stop here. I waited several minutes, and the load average of the machine went down to normal levels. The mySQLd stopped showing up on top.

I'd then CNTRL-C the process and get:

^CQuery aborted by Ctrl+C
mysql: 0 files and 1 streams is left open


I've done this a few times and the results have been consistent(ly bad). As I mentioned I also did two separate mysqldumps and both files failed to import the same way.

While the import was happening I watched "top." There didn't seem to be a memory issue since the mysqld never used more than 0.3% of the memory, although it did use 96% of the CPU (which was fine).

The mysqlds are running on the same operating system - Fedora 10 x_64. The only difference between them is the dump was done on mysql 5.0.27, and I am trying to source to a mysqld v5.0.67.

Any thoughts?
Comments: Read 7 orAdd Your Own.

Wednesday, December 17th, 2008

Subject:calling remote stored procedure
Posted by:danwinter.
Time:12:48 pm.
I need to "synchronize" the output of a stored procedure in one database (I don't have access to any tables there, just stored procedures) and a table in another database. So I need to call a remote stored procedure once in a while and populate a local table with its output. For the remote database, I know hostname, port, username, password and db name.

Is this possible in mysql? Any help would be appreciated
Comments: Read 2 orAdd Your Own.

LiveJournal for MySQL Community.

View:User Info.
View:Website (www.mysql.org).
You're looking at the latest 20 entries. Missed some entries? Then simply jump back 20 entries.