|
| 1 | +# ChatScript MySQL |
| 2 | + |
| 3 | +© Bruce Wilcox, mailto:gowilcox@gmail.com www.brilligunderstanding.com |
| 4 | +<br>Revision 6/25/2017 cs7.51 |
| 5 | + |
| 6 | +## Using MySQL as file server |
| 7 | + |
| 8 | +One can also use MySQL as a replacement for the local file system of the USERS directory. |
| 9 | +This allows you to scale CS horizontally by having multiple CS servers all connecting to |
| 10 | +a common MySQL machine so a user can be routed to any server. To do this, on the ChatScript |
| 11 | +command line provide the following command line params: |
| 12 | +``` |
| 13 | +mysqlhost=127.0.0.1 mysqlport=3306 mysqldb=chatscript mysqluser=chatuser mysqlpasswd=password |
| 14 | +``` |
| 15 | +It's probably easier to put these 5 params in a config file and use the config= command line param. |
| 16 | + |
| 17 | +The MySQL code assumes the userfiles table exists in the database. You can create a database and |
| 18 | +the userfiles table using the following statements: |
| 19 | +``` |
| 20 | +create database chatscript character set 'UTF8'; |
| 21 | +create user chatuser identified by 'password'; |
| 22 | +grant all on chatscript.* to chatuser; |
| 23 | +use chatscript; |
| 24 | +create table userfiles (userid varchar(400) PRIMARY KEY, file blob); |
| 25 | +``` |
| 26 | + |
| 27 | +The MySQL code uses the following prepared statement queries to read, insert, and update a user record: |
| 28 | +``` |
| 29 | +-- read a user |
| 30 | +SELECT file FROM userfiles WHERE userid = ? |
| 31 | +-- insert a user |
| 32 | +INSERT INTO userfiles (file, userid) VALUES (?, ?) |
| 33 | +-- update a user |
| 34 | +UPDATE userfiles SET file = ? WHERE userid = ? |
| 35 | +``` |
| 36 | + |
| 37 | +You can override these queries to support alternate schemas. However, the MySQL module |
| 38 | +assumes that any sql used to override the default queries will use the same sequence of arguments. |
| 39 | +For example, assume you want to store user data in a table named 'randomusertable.' The following |
| 40 | +parameters can be used to override the default MySQL queries: |
| 41 | +``` |
| 42 | +mysqluserread=SELECT userdata FROM randomusertable WHERE username=? |
| 43 | +mysqluserinsert=INSERT INTO randomusertable (userdata,username) VALUES (?, ?) |
| 44 | +mysqluserupdate=UPDATE randomusertable SET userdata = ? WHERE username = ? |
| 45 | +``` |
| 46 | + |
| 47 | +Note that the default and override queries use the same arguments in the same order. |
0 commit comments