Magnets can destroy data. While this is certainly true of the floppy disc and some (very) old hard drives, you might wonder whether it's true of musical mediums such as cassette tapes and CDs. Well, floppy discs were vulnerable to magnetic force because they arranged the data magnetically. As such, understanding the effect of magnets on other mediums requires understanding of how they work.
How Cassette Tapes Work
The "tape" inside a cassette tape stores information by arranging tiny magnetic particles a certain way. The tape plays back when the tape touches the magnetic spindle heads in the tape player, moving and causing an electromagnetic pulse that is interpreted as sound. The important thing to note here is that cassette tapes are recorded and played back essentially by arranging and interpreting magnetic particles.
Magnets' Effect on Tapes
Because of the tapes' magnetic nature, powerful magnets can profoundly distort the data on them, or sometimes even erase them. Even your standard ceramic (refrigerator) magnet is powerful enough to damage the tape, if left in direct exposure. For this reason, it's a good idea to keep your collection of rare-earth magnets and your collection of '80s dance cassettes on opposite sides of the house.
How CDs work
A CD uses lasers to playback. Tiny grooves on the surface of the CD are recognized by the laser, which is used to read the grooves. The CD player then interprets the data and translates it as sound. For our purposes, the main difference between the CD and the cassette tape is that magnets are used neither to record nor to playback CDs.
Magnets' Effect on CDs
Magnets have no affect CDs. While a magnet may be attracted to the metal surface of the CD, the magnet can't affect the data on the disc because the data on the disc is not arranged magnetically. While a powerful magnet's attraction to the disc could physically scratch the disc if you're not careful, this can't strictly be called a magnetic effect on the data. You can safely consider your CD collection magnet-proof.
If you want magnet-proof music, CDs are the way to go. Happily, CDs, being the newer technology, also sound better and are much easier to find in this day and age. If you have a large cassette tape collection, know that this distortion can be caused not only by magnets you might have lying around the house, but in some cases by the tape itself---magnetic force from one layer of tape can affect the one above or below it. The best way to prevent this sort of damage is to rewind or fast forward your tapes at least once a year.