SQL

Database reserved keyword lists

These links lead to a list of words that are explicitly reserved for each database. One reason to avoid reserved words is that your data structure will not port to other databases

Understanding Database Joins

Craig Courtney writes a brief summary of the differences between INNER, LEFT and RIGHT joins in SQL.


An INNER JOIN returns only those rows from left table where they have a matching row in right table based on the join criteria.

A LEFT JOIN returns ALL rows from the left table even if no matching rows where found in the right table. Any values selected out of the right table will be null for those rows where no matching row is found in the right table.

A RIGHT JOIN works exactly the same as a left join but reversing the direction. So it would return all rows in the right table regardless of matching rows in the left table. It is recommended that you no use right joins as your query can always be rewritten to use left joins which tend to be more portable and easier to read.

Note: INNER joins are faster than LEFT joins at least according to the tests i've read about.

Securing A MySQL Install on Windows

The default install of MySQL on Windows allows users to:

  • Connect as root (with no password) from the localhost or any remote host. A root user can perform any operation to any database, even delete them.
  • Connect as an anonymous user (with no username or password). If you are connecting from localhost, you are allowed root privileges. Otherwise you are allowed to connect to any database whose name begins with "test"

This leaves your machine in a quite vulnerable state. At the least, you'll want to assign a password for the root user and delete the anonymous user privileges if they aren't necessary for your setup.

First, make sure mysql is running. Navigate to your mysql/bin directory (default is C:\mysql\bin) and click on winmysqladmin.exe. If it prompts you for a username and password, hit cancel.

Open up a command prompt and type in the following:

C:\mysql\bin>mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('your_password') WHERE User='root';
mysql> FLUSH PRIVILEGES;

And to remove those anonymous user entries in the user table, connect to the server as root using your new password and delete the rows.

C:\mysql\bin>mysql -p -u root
mysql> USE mysql;
mysql> DELETE FROM user WHERE User='';
mysql> DELETE FROM db WHERE User='';
mysql> FLUSH PRIVILEGES;
© 2007 Matt Westgate