title: Need advice on how to optimize this database further
body: <p>I'm about to develop a chatsystem based on PHP / MySQL. Both the database and the website will run on the same server. I'd like to be able to support 300 users online at the same time. This will obviously generate lots of queries continuesly. Therefor optimizing the database design is a must.</p>
  
  <p>My skills with MySQL are average. I did my best to learn about optimizing and did everything I understood myself. Still I'm not sure if it's good enough. I'm hoping you guys can take a look at it and give advise on how to optimize it further.</p>
  
  <p>Any other tips on how to reduce the serverload are welcome aswell. Just keep in mind that all messages must be saved due to local law.</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `bans` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `userid` int(11) NOT NULL,
      `ipaddress` varchar(32) NOT NULL,
      `reason` text,
      `bandate` datetime DEFAULT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `BAN_INDEX` (`userid`,`ipaddress`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  CREATE TABLE IF NOT EXISTS `chatboxes` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `boxname` varchar(32) NOT NULL,
      `password` varchar(32) NOT NULL,
      `accesslvl` tinyint(1) NOT NULL DEFAULT '1',
      PRIMARY KEY (`id`),
      UNIQUE KEY `BOX_INDEX` (`boxname`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  CREATE TABLE IF NOT EXISTS `ignorelist` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `userid` int(11) NOT NULL,
      `blockedusr` varchar(16) NOT NULL,
      PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  CREATE TABLE IF NOT EXISTS `messages` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `userid` int(11) NOT NULL,
      `boxname` varchar(32) NOT NULL,
      `message` text,
      `receiver` varchar(16) NOT NULL,
      `alert` tinyint(1) NOT NULL DEFAULT '0',
      `msgdate` datetime DEFAULT NULL,
      PRIMARY KEY (`id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  
  CREATE TABLE IF NOT EXISTS `users` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(16) NOT NULL,
      `password` varchar(32) NOT NULL,
      `email` varchar(64) NOT NULL,
      `gender` tinyint(1) NOT NULL DEFAULT '0',
      `sexpref` tinyint(1) NOT NULL DEFAULT '0',
      `birthdate` date DEFAULT NULL,
      `regdate` datetime DEFAULT NULL,
      `lastlogin` datetime DEFAULT NULL,
      `warnings` tinyint(1) NOT NULL DEFAULT '0',
      `accesslvl` tinyint(1) NOT NULL DEFAULT '1',
      `kicks` tinyint(3) NOT NULL DEFAULT '0',
      `ipaddress` varchar(32) NOT NULL,
      `online` tinyint(1) NOT NULL DEFAULT '0',
      PRIMARY KEY (`id`),
      UNIQUE KEY `USER_INDEX` (`username`,`email`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
  </code></pre>