wiki:MySql
Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 10 (modified by jardous, 13 years ago) (diff)

--

MySQL Installation

See DataBaseInstalation

Setup the database for TG to work with

Firstly need to set DB connection string in dev.cfg (for development environment, prod.cfg for production environment) like:

sqlobject.dburi="mysql://george@localhost/test"

assuming george as database username, localhost as hostname and test as database name.

Then we need to create database using shell:

$ mysql -h localhost -u root -p menagerie

mysql> CREATE DATABASE test;
Query OK, 1 row affected (0.03 sec)

mysql> GRANT ALL ON test.* TO 'george'@'localhost';
Query OK, 0 rows affected (0.11 sec)

mysql> CTRL+d
Bye

Now we can test the DB connection as follows:

shell> mysql -h localhost -u george -p test
Enter password: ENTER

Now it is everything prepared and we can create database structure using our model:

tg-admin sql create

To Transaction or Not to Transaction

By default TurboGears uses Transactions (the rest of this page applies if you want to use MySQL with Transactions).

Kevin has added a hook that allows you to disable transactions in TurboGears. If you do not want TurboGears to manage trancstions do this:

	
1. Kevin Dangoor
	Dec 29, 11:54 am   show options
From: Kevin Dangoor <dang...@gmail.com> - Find messages by this author
Date: Thu, 29 Dec 2005 11:54:25 -0500
Local: Thurs, Dec 29 2005 11:54 am
Subject: to the mysql users with rollback exceptions
Reply | Reply to Author | Forward | Print | Individual Message | Show original | Report Abuse

As of r417, if you put notrans_ in front of the DBURI, TurboGears will
silently ignore all begin/commit/rollback/end instructions.

Kevin 

If you want to use Transactions, read the rest of this page :-) Note that transactions is not the only reason why using InnoDB is a good idea. InnoDB also enforces data integrity much stricter than MyISAM and also has many more features.

Question: I tried changing my sqlobject.dburi from "mysql://..." to "notrans_mysql://..." but I found that it didn't work. I'm getting this traceback:

Traceback (most recent call last):
  File "/usr/lib/python2.4/site-packages/TurboGears-0.9a0dev_r657-py2.4.egg/turbogears/toolbox/catwalk/__init__.py", line 120, in __init__
    CatWalkState.createTable(ifNotExists=True)
  File "/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1457-py2.4.egg/sqlobject/main.py", line 1320, in createTable
    if ifNotExists and conn.tableExists(cls.sqlmeta.table):
AttributeError: 'NoneType' object has no attribute 'tableExists'

Background

when the command:

tg-admin sql create

is issued, the default table type is used.

Mike summerized the options in an excellent email.

Mike Stephen
Dec 17, 5:17 pm   show options
From: "Mike Stephen" <mike.r.step...@gmail.com> - Find messages by this author
Date: Sat, 17 Dec 2005 14:17:21 -0800
Local: Sat, Dec 17 2005 5:17 pm
Subject: Re: TurboGears, MySQL, Transactions, and InnoDB tables Oh My

Hi Mike,

I'm using MySQL with turbogears and they're working very nicely
together for me. What you need to do is to configure MySQL so that it
uses InnoDB as the default storage engine as Jonathan pointed out, so
that when you issue a create table statement, it'll be an InnoDB table
by default.

Do you have the MySQL Administrator GUI installed? If so, select
StartUp Variables from the left pane, then choose the General
Parameters tab. Down the bottom you'll see a Default Storage section.
Choose InnoDB from the drop-down.

Alternatively, you could add the following line to the [mysqld] section
of your my.ini file:

default-storage-engine=INNODB

Regards,

Mike.