Database Usage.

Using databases on DreamHost is not really a difficult thing once you have managed to get your head around the terminology used.

Think of a database as a large box or container. Into that box you can place smaller boxes called tables. Those smaller boxes (tables) will contain even smaller boxes called records. Those records will contain the information or data.

To locate the large box, the database, we give it an address, a hostname. The hostname is really just a file name since everything involved in Linux/Unix revolves around everything being “just a file”.

We also need someone, a user, who is going to look after that database, and of course to do it securely, that user will need to password protect the database.

So we end up needing these bits of information in setting up a database:-

  • A Hostname
  • A database name
  • A user name
  • A users password

Recently DreamHost changed the way databases were set up and the outcome is that now a number of databases can be set-up using the same Hostname.

So select a meaningful hostname now and then add your databases as you need them. Because ‘tables’ (the smaller boxes inside the big database box) are given unique names you could in fact get by with just one database serving several programs. Each program would identify a table in two parts, using the program name and the purpose of the table. So in a forum program you could have a table called ‘forum_users’ another program, a blog program, might use ‘blog_users’.

However in practice it can become very confusing having a mixture of tables in one database so it is more convenient to create one database per program. Many hosting providers only allow one database but DreamHost have no restriction and you can create your databases as you need them.

When creating the database use a logical name that you can tie in to your chosen program, say a forum program. So you could choose ‘forum’. But just in case you decide to add more forum programs and hence databases you might want to select ‘forum1′ as the database name to make it more meaningful.

Next a location or hostname is needed for the databases. If you had just one computer and the database (MySQL, SQL) program was installed on it you might choose ‘localhost’. But DreamHost uses a hostname setup which can be likened to using sub-domains.

So choose a hostname (really it is a sub-domain, but a sub-domain that the database creation section will set up for you.) for your new database ‘forum1′. Since you might have several databases using this hostname you could choose something like ‘databases.example.com’ where ‘example.com’ is your domain name. DreamHost even offer a suggestion of ‘mysql’ to give you ‘mysql.example.com’ . So why not choose that?

Lastly we will need a user/password combination to manage the database and to allow our Forum program to manage it automatically. This new username does not have to be an existing username, although it can be. Perhaps a username that reflects the program might be useful so we can use the database name of ‘forum1′ and since it is a username we can add an ‘u’ to it and create a username of ‘forum1u’.

User ‘forum1u’ will need a password so give the user a password of your choice, say ‘123abc456%’.

We now have all the bits of information we require and can click ‘create’ to create a database. Like most things there is a period of time required to set all these things. Especially the ‘hostname’ which is really a sub-domain. It might need anything from a few minutes to several hours to ensure the ‘hostname’ has, just like a domain name, propagated around the Internet.

So we can provide the information that will be needed by programs using a database.

  • A Hostname called ‘mysql.example.com’
  • A database name called ‘forum1′
  • A user name called ‘forum1u’
  • A users password which is ‘123abc456%’

After we install our program ‘forum’ the installation notes may tell us to insert the database details into the config.php file. So we can do just that. Usually it will require some means of connecting to the computer using either FTP or SSH in order to edit the config.php. It is quite simple with FTP. Just use the view/edit option to open the file in your computers editor.

You may see something like:-

//
// Enter your database settings here.
//

$dbms = ‘mysql’;

$dbhost = ‘localhost’;
$dbname = ‘dbname’;
$dbuser = ‘dbuser’;
$dbpasswd = ‘user password’;

$table_prefix = ‘phpbb_’;

define(’PHPBB_INSTALLED’, true);

?>

So using our newly acquired database details we could rewrite the above as:-

//
// Enter your database settings here.
//

$dbms = ‘mysql’;

$dbhost = ‘mysql.example.com’;
$dbname = ‘forum1′;
$dbuser = ‘forum1u’;
$dbpasswd = ‘123abc456%’;

$table_prefix = ‘phpbb_’;

define(’PHPBB_INSTALLED’, true);

?>

The ‘dbms’ part is just indicating to the program that MySQL is the chosen database system, and $table_prefix = ‘phpbb_’; is just the prefix given to each table within a database to make it unique as mentioned in previous paragraphs.

So we just save our edited file back to the server via the FTP program and the database set part has been completed.

Leave a Reply