In my database of 5 million records ..
Structure of the table:
CREATE TABLE IF NOT EXISTS `music` (
`id` int(50) NOT NULL auto_increment,
`artistname` varchar(50) NOT NULL,
`songname` varchar(50) NOT NULL,
`duration` varchar(6) NOT NULL,
`url` varchar(255) NOT NULL,
`server` int(5) NOT NULL,
PRIMARY KEY (`id`),
KEY `artistname` (`artistname`),
KEY `songname` (`songname`),
KEY `url` (`url`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
How can I optimize the table and then doing a search through the fields “artistname ” and “songname”?
Sorry for bad english. From Russia with love 😀
Create a
FULLTEXTindex:and issue a query like this:
This will match across both
artistnameandsongname, even if the words are not leading.To match only the artist, you can create an additional index on
artistnameonly and use it in a query:The column set in the
MATCHclause should be exactly the same as in the index definition for the corresponding index to be used.Note that this clause will work even without the index, but in this case it will be much more slow.