Database 101

From SaruWiki
Revision as of 22:03, 28 August 2008 by Saruman! (talk | contribs) (updated post-installation tasks)
Jump to navigation Jump to search

MySQL installation

As with any package to be installed: use aptitude, update your APT, then make sure all your (other) software is up-to-date. Then find package mysql-server - under Lenny it'll be version 5.0.51a-something. Installing it will also automatically install some dependent packages, like mysql-common, mysql-client etcetera. So after downloading some 40MiB of files, MySQL is installed. Should you consult the official MySQL documentation, you might see mention of the mysql_install_db script - do not worry about that, since Debian has run it for you when it was setting up the database.

To now configure the MySQL server, please take the following steps: Think up a strong password for the MySQL root user; something like waYacUbaT2uW. DON'T use this example password, generate your own one!. Start the MySQL client from the command line:

mysql -u root

Then, from the mysql client prompt, set the password for the MySQL root user. At installation time, two accounts "root" were created, each with an empty password - NOT safe! One account is used to connect to the MySQL server from localhost, one to connect from the IP address of the machine. They can be treated as two different accounts, but we don't recommend that. We thus give both accounts the same password:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('waYacUbaT2uW');
mysql> SET PASSWORD FOR 'root'@'<hostname>' = PASSWORD('waYacUbaT2uW');

Furthermore, there are two anonymous accounts created. These also have no password, and get full permission on the test database, as well as on any database who's name begins with test_. These accounts can be fitted with a password (like we did for root - just use two quotes with nothing inbetween them, instead of two quotes with root inbetween), or they can be removed - which we recommend. The (single) command for this is:

mysql> DROP USER '';

To verify the installation you might want to take some of the following steps:

  • run mysqlshow -u root -p, and see if that command outputs at least two databases (information_schema and mysql);
  • check out the settings of your MySQL server by running mysqladmin -u root -p variables (piping the output to less or a file, if necessary);
  • have a peek in /var/lib/mysql; the database data files should be there;
  • check /var/log for two logfiles mysql.err and mysql.log.