From GridLAB-D Wiki
Jump to: navigation, search

 *** WORKING DRAFT *** 
Please review, edit and comment as necessary.


HowTo:mysql - MySQL How To Guide Template:NEW30

The mysql module was designed to offer a high level of compatibility with the player, recorder, and collector objects in the tape module. This guide offers a HowTo for implementing mysql interfaces and converting tape I/O to mysql I/O.

Setup the default connection

The default database connects to the server on the localhost (on port 127.0.0.1 or socket name /tmp/mysql.sock) using the database schema gridlabd with the user gridlabd (no password).

To use the default database you must install a MySQL server on the localhost. The installation procedure depends on the host platform and can be found at www.mysql.com. We strongly recommend also installed the MySQL WorkBench to allow administration of the server. Using the workbench you should create a user gridlabd with full control of the schema gridlabd. If you are concerned about the security of this schema, you can also set the password for this user and restrict access to localhost clients only.

A simple mysql recorder

The simple example of a mysql recorder is illustrated by the following example. The module declaration replaces a conventional tape module declaration and the specifications of the object is compatible (although not always identical):

// Examples:mysql_recorder_1.glm
module mysql;
database { 
  // uses defaults (see mysql for details)
}
class test {
  randomvar x; // random number
}
object test {
  x "type:normal(0,1); refresh:1hr"; // updated every hour
  object recorder {
    table "test";
    property x;
  };
}

Omitting all specifications for the database object uses the default connection.

If you want to record the values in a different unit than the unit to property you are recording, you must specify the unit with the property. If the property you are are recording also has a unit, the value will be converted automatically as it is sampled:

// Examples:mysql_recorder_2.glm
module mysql;
database { 
  // uses defaults (see mysql for details)
}
class test {
  randomvar x[h]; // random number of hours
}
object test {
  x type:normal(0,1); refresh:1hr"; // updated every hour
  object recorder {
    table "test";
    property x[min]; // converts hours to minutes
  };
}

A simple mysql player

 TODO: 

A simple mysql collector

 TODO: 

Using multiple mysql databases

 TODO: 

Converting a tape recorder to mysql

 TODO: 

Converting a tape player to mysql

 TODO: 

Converting a tape collector to mysql

 TODO: 

See also