Tips_sql   >   Mysql   >   MySQL (All Contents)
This section covers various tips related to setting up and working with MySQL from the perspective of an Omnis Studio programmer. I started using MySQL in early 2006 when writing a ticket tracking system for a European Appliance warranty provider.
The reason for using MySQL was that it was free and Omnis Studio provided a DAM to connect to MySQL. I verified with MySQL to make sure that it was legal to use the free version for business use. I only required a commericial version if I was shipping MySQL on a CD or in some other form of an auto installer. As long as MySQL was being installed manually on the client's server it was 100% okay to use the free version. (Good to know)
At the time of doing this work I was developing and testing on a MacBook Pro running Mac OS 10.4.5. The customer was using the Debian flavour of Linux for a server and with WindowXP/98 clients.
My ISP installed MySQL 5.0, PHP 5.1, and phpMyAdmin 2.7 on the Linux box so I can't give any advice on how that was done. He said Debian makes it really easy.
I installed MySQL 5.0, PHP 4.4, and phpMyAdmin 2.7 on my MacBook Pro laptop which came with Apache 1.3 preinstalled. After many hours of struggling and searching for answers on Google I managed to get everything working satisfactory on my laptop. If you are attempting the same feat, see the topic on .Installing MySQL 5.0 on my MacBook Pro (intel) running Mac OS 10.4.5 was fairly simple.
I downloaded MySQL 5.0 from the mysql.com website.
Once downloaded I ran their Mac friendly package installer. You should also install the
package.The mysql files are installed at /usr/local/mysql/
The readme.txt file talks about setting up aliases to the mysql program or a path in the $HOME/.bashrc file. The aliases only work until you restart, so that is a waste of time. The path instructions didn't work. I finally got the path to work in a .profile file. You can execute the following from the command line to create a .profile file in your home directory.
cd ~
pico -w .profile
export PATH=$PATH:/usr/local/mysql/bin
If you use .profile file you must set and save the file as plain text. If you allow the text editing program to save the file as rich text or some other non-plain format the configuration file will not work.
or some other word processing program to create or edit any configuration files, like theNext you will need to set up users and privileges.
If you need to change the default database startup settings you will need to go to the /usr/loca/mysql/support-files/ directory and read the my-*.cnf files to see which one you should use. Follow the directions at the top of the file.Installing MySQL 5.0 on a WinXP computer is very easy.
Downloaded MySQL for WinXP from the mysql.com website and run their installer.
The installer asks you for a password for the root user. Go ahead and enter a password that you won't forget. This saves you from having to set the root user password manually.
One of the installer screens has a checkbox for adding the path to the Program Files\mysql\bin file, be sure to set to check the option.
To get to the mysql> command line prompt:
After you finish with the installer you should may want to add a database administrator user other than root.
mysql -u root -p
You will likely need to use the command line to get MySQL setup with the intials users and a database. I tried using GUI tools but ran into buggy behavior here and there.
is the best GUI tool I found, but you are best to get the initial users set up using the command line. MySQL installs with a user named root with no password. The first thing you want to do is add a password to root as follows:mysql -u root
mysql -u root -p
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');
GRANT ALL PRIVILEGES ON *.* TO 'DBADMIN'@'localhost' IDENTIFIED BY 'MyPassword' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'DBADMIN'@'%' IDENTIFIED BY 'MyPassword' WITH GRANT OPTION;
flush privileges;
exit
mysql -u root -p
exit
mysql -u DBADMIN -p
All going well you will be able to login to mysql with your specified password and user. If not, you'll have to use and the online documentation to find answers.
With
Installing up and running you can move on to installing which is a great GUI tool to use for administering MySQL. It is browser based so you don't need any client side software to use it. and on my MacBook Pro is where I spent many hours. Hopefully the tips in the section will save you some grief. Once it is set up and running works great!When you open a session using the MYSQLDAM you may want to issue the following initial statement for setting various defaults.
SET @@global.innodb_flush_log_at_trx_commit=1, @@session.max_allowed_packet=16*1024*1024, @@session.autocommit=1, @@session.tx_isolation='READ-COMMITTED';
@@global.innodb_flush_log_at_trx_commit=1 means that the logs are written when a transaction is committed instead of the default which is every minute or so.Ê This is slower, but more dependable.You should create a my.cnf file on your MySQL server so that you can set various things on the server side.
The my.cfg file needs should be located in the etc directory. If it doesn't exist you will need to copy it from the /usr/local/mysql/support-files directory as follows:
You can now edit the my.cnf file with you favorite text editor. e.g. pico my.cnf
The following are some settings which I have added/changed in the my.cnf file.
From the mysql prompt in the terminal:
create database newdatabasename;
If you want to avoid headaches with moving your data around or restoring from backups, set MySQL to use lower case table names.
# The MySQL server
[mysqld]
lower_case_table_names=1
That's all there is to it!
When you create new tables, the table names will be in lower case. Trust me this will make dumping and restoring databases a lot more reliable.I ran into problems with binary columns and the MYSQLDAM
The error I hit was:
SQL Error Type: 2
SQL Error Code: -107
SQL Error Text: The data buffers could not be allocated
MySQL does not support the chuncking of binary data, so in order to successfully fetch the LOB, the buffer size must be greater than or equal to the column size.
kStatementBufferAllocationFailed occurs when the MYSQLDAM fails to allocate a buffer needed to store the data for one of the result columns.
This usually occurs with binary data where the column size is very large, or where the user is trying to fetch multiple LOB columns.
To solve the problem I did the following after opening a session with the MySQL database:
; Set session properties to avoid errors with binary columns.
Do sessobj.$connectoption(kMySqlOptDataTruncation,kTrue)
Calculate Size as 17000000
Do irSessionObj.$blobsize.$assign(Size)
Do irSessionObj.$lobthreshold.$assign(Size)
Do irSessionObj.$lobchunksize.$assign(Size)
To stop the MySQL server from command line enter:
mysqladmin -u root -p shutdown
To start the MySQL server from command line enter:
mysqld_safe &
The MySQL syntax for setting a timestamp column's date to the current date/time is as follows:
NOW()
Calculate SQLText as "UPDATE TableName SET ModDateColName=NOW(),ColName1=[$cinst.ColName1], etc."
Do StmntObj.$execdirect(SQLText) Returns FlagOK
Other MySQL date/time functions are as follows:
CURRENT_TIMESTAMP or CURRENT_TIMESTAMP()
CURDATE() or CURRENT_DATE or CURRENT_DATE()
CURTIME() or CURRENT_TIME or CURRENT_TIME()
The default transaction setting for MySQL is REPEATABLE READ. The problem with this settings is that it can lock a chunk of records. To avoid this I prefer to use READ COMMITTED.
You can change the transaction_isolation setting on your server by adding the following to your my.cnf file (See the tip on if you don't have one set up.)
tx_isolation='READ-COMMITTED'
This should go somewhere just before [mysqldump] in the my.cnf file.
I recommend that you set up an Admin Configuration Settings block just before [mysqldump] for this and other custom settings.
# Admin Configuration Settings - 2007-09-12 Doug K.
transaction_isolation='READ-COMMITTED'
wait_timeout=432000 # 5 days
# End Admin Configuration Settings
If your clients leave your Omnis Studio application open for more than eight hours without any activity the MySQL server will automatically time out and close their connection. In this case, you normally get one of the following error codes (which one you get is operating system-dependent):
By default, the server closes the connection after eight hours if nothing has happened. You can change the time limit by setting the wait_timeout variable when you start mysqld.
If you have a script, you just have to issue the query again for the client to do an automatic reconnection. This assumes that you have automatic reconnection in the client enabled (which is the default for the mysql command-line client).
You can change the wait_timeout setting on your server by adding the following to your my.cfg file (See the tip on if you don't have one set up.)
wait_timeout=432000 # 5 days
This should go somewhere just before [mysqldump] in the my.cfg file.
I recommend that you set up an Admin Configuration Settings block just before [mysqldump] for this and other custom settings.
# Admin Configuration Settings - 2007-09-12 Doug K.
tx_isolation='READ-COMMITTED'
wait_timeout=432000 # 5 days
# End Admin Configuration Settings
You can use mysqldump to create a backup of a MySQL database, or to send the database to someone else, or move it to another server. It is easy to do, and blazing fast.
The syntax from the shell is:
mysqldump TheDatabaseName -p > TheFullTargetFilePath
Example:
mysqldump LibraryData -p > /Users/doug/Desktop/LibraryDataDump.sql
To import the data into a new database:
create database NewDatabase;
create database LibraryData2;
mysql -u UserName -p DBName < TheFullTargetFilePath
mysql -u root -p LibraryData2 < /Users/doug/Desktop/LibraryDataDump.sql
To do a mysqldump of just the data, not create table statements use the following syntax:
mysqldump --no-create-info -u MySQLUserName DatabaseName > TargetFilePath
An example:
mysqldump --no-create-info -u root MyData > /Users/doug/Desktop/MyData_20081128.sql
is a widely used GUI administration tool for
Installing . Being browser based you don't need any client side software to use it and depending on how you set it up you could also access if from anywhere on the internet. and on my MacBook Pro is where I spent many hours. Hopefully the tips in this section will save you some grief. Once is set up and running it works great.Before you do anything, check to see if
is installed and enabled on your Mac as follows:<?php phpinfo() ?>
If you need to enable PHP do the following from the command line:
#LoadModule php5_module
#LoadModule php4_module
#AddModule mod_php4.c
On WinXP you will need to install/enable web server software on their computer. You can only run your computer as a web server if you have WinXP Pro. Afer installing and setting up your computer as a web server type in http://localhost/ in your browser to test whether or not it is working.
Once you have your WinXP computer working as a web server you are ready to install PHP.
Google for Download PHP for WinXP and then download and install the latest version of PHP following the directions provided.is easy to install, but I had a tough time getting the config file sorted out so that it would work on my MacBook Pro.
$cfg['blowfish_secret'] = 'ae85mh04wq23'; // Enter a random string to be used for blowfish encryption
// Server(s) configuration
$i = 0;
$i++;
$cfg['Servers'][$i]['host'] = '127.0.0.1'; // 'localhost' did NOT work!
$cfg['Servers'][$i]['connect_type'] = 'socket'; // 'tcp' did NOT work!
$cfg['Servers'][$i]['auth_type'] = 'cookie'; // Using cookies is easiest and safest setup.
$cfg['Servers'][$i]['user'] = ''; // MySQL user - empty for cookies
$cfg['Servers'][$i]['password'] = ''; // MySQL password - empty for cookies
?>