Configuring MySQL

Posted by Chief on Nov 12, 2009 in System Administration
No Comments

The following is how I set up MySQL on wharf.

  1. First, ensure mysql is installed: ls /etc/init.d/my*
  2. Now, make mysql start on boot: sudo /sbin/chkconfig --level 35 mysqld on
  3. Start the mysql server: sudo /etc/init.d/mysqld start
  4. Make MySQL more secure: sudo /usr/bin/mysql_secure_installation
  5. Log into mysql as root: mysql -u root -p [to be entered by prompt]
  6. Add another mysql user:
    mysql> CREATE USER 'newuser'@'%' IDENTIFIED BY 'newuserpass';
    mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON *.* TO 'newuser'@'%';
    mysql> FLUSH PRIVILEGES;
  7. Exit mysql: mysql> exit
  8. Test: mysql -u <newuser> -p <newuserpass>

Tags: , , , , ,

Things that Kill MySQL Performance

Posted by Chief on Nov 4, 2009 in Lessons
No Comments
  1. Failing to plan for scaling out, scaling up
  2. Not using EXPLAIN (learn from your mistakes)
  3. Using the wrong data types (hint: use smallest fixed-size)
  4. Using persistent connections in PHP (leads to zombie processes)
  5. Using a heavy DB abstraction layer (hint: use PDO or custom)
  6. Using the wrong storage engine (MEMORY, ARCHIVE, InnoDB, etc.)
  7. Using indexes improperly (hint: select in the order of the index; hint: keep primary key small)
  8. Issuing SQL queries that can’t be cached easily; having too large of a query cache
  9. Using stored procedures when prepared statements are better
  10. Using functions on indexed columns in the WHERE clause
  11. Not indexing important columns; having redundant indexes
  12. Using sub-queries when joins would be better
  13. Issuing avoidable deep scans
  14. Doing SELECT COUNT(*) without WHERE on InnoDB table.
  15. Failing to profile/benchmark your SQL
  16. Not using AUTO_INCREMENT if applicable
  17. Not using ON DUPLICATE KEY UPDATE (1 query vs 2)

Reference:

Tags: , , , ,

MySQL DNS Caching

Posted by Chief on Dec 23, 2008 in Lessons
No Comments

On December 12, 2008, SCCOOS metadata system was broken. The error was cryptic, but the message was clear: Connection to [IP] denied.

Resolution

Using the MySQL command-line tool:

mysql -u admin -p [-h ] [-P ]
mysql> flush hosts;

That’s it!

Chain of Events

  • UCSD’s DNS was polluted, identifying 132.239.123.144 as ridge2000.org for the past few weeks.
  • Sandbar was restarted last week, freeing up both the OS and MySQL DNS caches, which meant all new connections will need to query a DNS server to identify whether it’s an allowed machine or not (do you see a security vulnerability?).
  • Both the OS and MySQL cached the hostname, but MySQL further rejected all connections from alfredo because MySQL thought that alfredo was ridge2000 instead.
  • The mysql database, user table identifies user sccoos can connect to sandbar from alfredo.ucsd.edu.
  • The OS cache probably cleared, but since so few machines access sandbar, the MySQL cache hadn’t filled up yet.
  • Just last night (2008-12-22), the UCSD DNS purged the ridge2000.org name from its list, so UCSD’s DNS is clean, but any caches may still be polluted.
  • Windows machines cycle their caches regularly, so the problem isn’t more wide-spread or commonly understood.
  • The long-lasting MySQL DNS cache is disturbing, but alternatives would cripple the imperative nature of a database.

References

Tags: , , , ,

Copyright © 2010 cat brain.log | less All rights reserved.
Shades v1.2 theme from BuyNowShop.com.