Modified 2001/06/27 - JSB

MySQL Installation and Usage

Attention: Every now and then a change in the host server's state can cause MySQL to fail starting up, which, if it does happen generally does so on boot. (I don't actually know what caused the last instance of this failure on my development system, but things, such as a change of IP address assignments, did change the machine environment.) I have found that it usually takes the removal and recreation of the my.ini file in the WINNT directory for the starting of MySQL service to happen in this case. It is very important to reuse the original user/password combination (in my case, "admin/admin") to be able toaccess any DBs created under that account. For more detail review section I. below.

I. Installing MySQL into Windows Server 2000

  1. The first thing to do is to download the latest stable version of the MySQL Database Server software from the MySQL foundation at http://MySQL.com. (I used the Windows version 3.23.28, which downloads into a ZIP file called, mysql-3.23.28-win.zip.)

  2. Next you will need to extract (unZIP) the downloaded file into a temporary area and run the included Setup.exe file to install it.

    NOTE: If you are on NT and install MySQL in any other folder than C:\MYSQL and you intend to start MySQL as a service, you must or edit a file named C:\MY.INI (the MY.INI file will default to C:\WINNT directory) with the following information:

    [mysqld]
    basedir=E:/your-installation-path

  3. In the C:\mysql\bin directory (or wherever your "basedir" is installed) run the winmysqladmin.exe program bring up the DB server for the first time. This program will try to find the MY.INI file, querying for a username and password, into which it will want to append this username and password info (I used user "admin" and password "admin"):

    Special Note: If you are re-installing MySQL delete or rename the existing my.ini file, otherwise you may introduce conflicts by inheriting the prior installations's version of this file. (The MySQL uninstaller does not remove this file.)

    [WinMySQLadmin]
    Server=C:/mysql/bin/mysqld-nt.exe
    user=admin
    password=admin

  4. The winmysqladmin.exe program will usually insert itself into the system tray (small icons on the far right of the start bar) and load there in the background upon subsequent rebooting. (Clicking on this same icon and selecting the "Show me" option open this application to the desktop. Clicking on the "Hide me" button will place the winmysqladmin application back into the system tray as a traffic light icon.)

  5. Clicking on the "Databases" tab in the winmysqladmin application will show a particular database called "mysql" which contains info about the host, users, passwords and priviliges. As a superuser or administrator you will need to have full priviliges. To enable these priviliges ou must now run the MySqlManager.exe, which also resides in the C:\mysql\bin directory.

  6. The MySqlManager.exe application will open with a database project window, probably with the name MySqL1, containing two folders, Test and MySQL. Click on the MySQL folder and highlight the subdirectory named mysql. Then go to the Tools dropdown menu and click on SQL Query. In the query space enter the following SQL statement (admin is the username I have selected):

GRANT ALL PRIVILIGES ON *.* TO admin@localhost IDENTIFIED BY 'admin' WITH GRANT OPTION;

(The "IDENTIFIED" clause may be optional if no password, "admin" in this case, was supplied.)

Back to top of page.

II. Creating and Accessing the ODBC MySQL DB Connection Object

II.1. Installing and Registering the MyODBC Driver for MySQL with the Windows OS:

The steps to do this are as follows, using my actual MySQL DB called, 2000toMySQL:

  1. The setup32 binary distribution may be obtained from the file myodbc-xxx.zip at http://www.mysql.com/
  2. First unzip the file (in my case, myodbc-2.50.37-nt.zip) into a scratch directory.
  3. Execute the setup.exe MyODBC installer program by clicking on setup.exe.
  4. Click ""Continue" button.
  5. In the new "Install Drivers" box hightlight the "MyODBC" entry and click "OK" button.
  6. This registers the MyODBC driver with Windows and registers a sample MySQL DB as a datasource, called "sample-MySQL", see section 0.2 for more on this.

II.2. Registering the MySQL DB as a Datasource with the Windows OS:

The steps to do this are as follows, using my actual MySQL DB called, 2000toMySQL:

  1. Open the Windows Control Panel - Start>Settings>Control Panel.
  2. Click on "Administrative Tools".
  3. Click on "Data Sources (ODBC)".
  4. In the "ODBC Data Source Administrator Panel" tab to "User DSN".
  5. Click the "Add" button.
  6. In the resulting "Create New Data Source" panel select MySQL.
  7. Click the "Finish" button.
  8. In the resulting "TDX mysql Driver default configuration" panel:
  9. Enter "2000toMySQL" in the "Windows DSN Name" field.
  10. Enter "localhost" in the "MySQL host" field.
  11. Enter "2000toMySQL" in the "MySQL Database name" field.
  12. Enter "admin" in the "User" field.
  13. Enter "admin" in the "Password" field.
  14. Enter "3306" in the "Port" field.

II.3. Creating and Accessing the ODBC MySQL DB Connection Object from VBScript

The following is a working VBSript sample of code I used to create the MySQL connection object:

<%@ LANGUAGE = VBScript %>

<%
' Open/Create MySQL DB to get Access2000 data - these live at mysql\data\2000toMYSQL
Set OBJmysqlDbConnection = Server.CreateObject("ADODB.Connection")
OBJmysqlDbConnection.Open("Driver={mySQL}; Server=localhost; DATABASE=2000toMYSQL; UID=admin; PWD=admin;")

SQLQuery = "CREATE TABLE MASS_COUNTIES (COUNTY_ID INTEGER NOT NULL , COUNTY_NAME CHARACTER(30) NOT NULL ) ;"

connectionStatus = OBJmysqlDbConnection.Execute(SQLQuery) %>

Back to top of page.

III. JSP Installation JDBC for MySQL into a J2EE Server

In the setenv.bat file add environement variable values for both CLASSPATH and J2EE_CLASSPATH. Ensure to have the .JAR JDBC j-archive files pointed at in the J2EE_CLASSPATH. In this example we shall use the a 3rd party MySQL JDBC driver in the file. mm.mysql-2.0.4-bin.jar:

set CLASSPATH=.;%JAVA_HOME%\lib set J2EE_CLASSPATH=.;%J2EE_HOME%\lib;%J2EE_HOME%\lib\system;%J2EE_HOME%\lib\system\mm.mysql-2.0.4-bin.jar

** JDBC drivers must reside in %J2EE_HOME%\lib\system as this directory is cleared for the system permissions required for the type of system level activities performed by this class of drivers.

Make sure that the the J2EE server is stopped and do the following, again using MySQL as an example:

(For the j2eeadmin tool usage go to http://java.sun.com/j2ee/tutorial/doc/Tools2.html#63229. The following also points to the JDBS section included with the j2ee documentation in the actual j2ee installation: file:///D:/j2sdkee1.3/doc/release/ConfigGuide.html#12442)

For drivers without XA Datasource support:

1. Add the JDBC driver.
    Syntax:
j2eeadmin -addJdbcDriver <class name>
    My actual MySQL example:
j2eeadmin -addJdbcDriver org.gjt.mm.mysql.Driver
    Oracle Example:
j2eeadmin -addJdbcDriver oracle.jdbc.driver.OracleDriver

2. Add the DataSource:
    Syntax:
j2eeadmin -addJdbcDatasource <jndi name> <url>
    My actual MySQL example:
j2eeadmin -addJdbcDatasource jdbc/MySQL jdbc:mysql:localhost:3306:2000toMySQL
    Oracle Example:
j2eeadmin -addJdbcDatasource jdbc/Oracle jdbc:oracle:thin@rtc:1521:acct

    NB: This presumes that 1.) an ODBC Driver for MySQL has been installed and registered with the Windows OS and that 2.) the MySQL DB has been registered as a Datasource with the Windows OS. The steps for doing this are listed after item 3, below.

3. Restart the server and browse to the server (localhost:8000 or localhost:9191 on my J2EE setup):
j2ee [-verbose]

More about drivers with and without XA Datasource support, using and not using data sources, as well as experimenting with placing JDBC drivers as JDK , not J2EE, runtime extensions (%JAVA_HOME%\jre\lib\ext).

We will actually want to use a native MySQL driver so that we do not have to register datasources with Windows, an extra maintenance step we do not want to pursue. However, in my initial investigations in how to access MySQL DBs from ASP led me to using a Windows based ODBC driver. The MM and Caucho drivers that I have downloaded and tinkered with are actually native type 4 dirvers for MySQL. The MyODBC driver is used to register MySQL DBs as a datasource in Windows ODBC so that they may be accessed from ASP. JSP, on the other hand, requires eith the MM or Caucho driver for MySQL access. What is confusing, and I am still working out, is the rquirement for a j2eeadmin datasource registration, perhaps is merely a nomenclature issue. My research on Deja seems to indicate this j2eeadmin datasource requirement reflected by the following JSP code fragment:

String MySQLdriver = "org.gjt.mm.mysql.Driver";
String MySQLurl = "jdbc:mysql://localhost:3306/2000toMySQL/?user=admin?password=admin";
// Make the JDBC connection object.
Class.forName(MySQLdriver);
MySQLconn = DriverManager.getConnection(MySQLurl);
MySQLstatement = MySQLconn.createStatement();

Back to top of page.

Edit 
Language: fr  | it  | de  | es  | pt  | ar  | he  | da  | nl  | zh  | ja  | ko  | none 
skyCalendar

This Version:
Archived at: https://www.skybuilders.com/Users/Jesse/Docs/mySQLusage.20010606114318.html

Requests
 Version: 11660 | Series: 12894