MySQL for Windows NWNX2

The following steps describe how to download, install, and setup a MySQL server on your Windows machine for use with NWNX2.

In case you have questions beyond this, an excellent reference is the MySQL online manual. The Bugzilla installation guide, though not written specifically for this purpose, also has very good instructions on installing MySQL.

Download

MySQL 5.1 is currently the recommended version of MySQL, though anything 3.0 or later should work. The server can be downloaded here.

Installation

Server Install

  1. Download the server executable -- the "Windows Essentials" one is the easiest to install.
  2. Run the executable. Take all the defaults that apply. See this article for a step-by-step account of all the options you get during the install.
  3. Configure the server as needed. The explanations of the options should be enough to use common sense to decide; if you’re still not sure of something, the defaults should all work fine.

Client Install

  1. Download and install a MySQL client – for the purposes of this tutorial, we’ll use SQLyog.
  2. The SQLyog developers have a habit of changing the interface significantly with every major version. The following instructions were written with v8.01 in mind.
  3. You should be presented with a “Connect to MySQL Host” dialog upon starting SQLyog and clicking through any nag screens.
  4. Enter the host address (localhost is fine if you installed it on the same machine you’re running the client on), username “root”, and the password you chose during the server install, then click Connect.

Creating the NWN database and user

Next, you must create the database and user for NWNX. You can name them anything you want, but ‘nwn’ is a perennial favorite for both. For clarity, we will use ‘nwndb’, ‘nwnuser’, and ‘nwnpassword’ below.

  1. In the query window/prompt of your client, enter and run the following query: CREATE DATABASE nwndb; (To run a query in SQLyog, click the “Execute Current Query” button or press F9).
  2. Clear the query window, and enter and run the query: GRANT ALL ON nwndb.* TO ‘nwnuser’@’%’ IDENTIFIED BY ‘nwnpassword’;
    1. If you're not familiar with SQL syntax, the above means, in English, "Create a new user (GRANT). It has full access (ALL) to all tables in the nwndb (ON nwndb.*). The user's name is nwnuser (TO 'nwnuser') and it's allowed to connect to the server from anywhere (@'%') [to restrict this, you would use @’localhost’ or similar]. Its password is nwnpassword (IDENTIFIED BY 'nwnpassword').
  3. Enter and run the following to make the server recognize the new user: FLUSH PRIVILEGES;

Creating the Database Tables

Now tables need to be created in the database to actually hold the data. A table is similar to a spreadsheet, and creating a table defines the columns in that spreadsheet. The most important is pwdata, which is the default table used by the APS scripts provided with nwnx_odbc.

  1. Make sure you have the nwndb database selected (in SQLyog, you choose it from the Object Browser at the left of the screen), then enter and run the following query: CREATE TABLE `pwdata` (`player` varchar(64) NOT NULL default '~', `tag` varchar(64) NOT NULL default '~', `name` varchar(64) NOT NULL default '~', `val` text, `expire` int(11) default NULL, `last` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (`player`,`tag`,`name`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Various persistent variables';

Configuring NWNX

  1. Open NWNX.ini and uncomment (remove the ; from the beginning of each line) the section beginning with source = mysql. Comment any other different source sections.
  2. Set the appropriate username, password, and database in the config lines. An example of a working configuration is below:
[ODBC2]
; Log file
MaxLogSize = 512 ; in KByte
LogLevel = 2 ; 0=nothing, 1=only errors, 2=everything

; Use these five settings for MySQL connections
source = mysql
server = localhost
user   = nwnuser
pwd    = nwnpassword
db     = nwndb

That's it! Start up NWNX and try it out.