Wednesday Aug 27, 2008

We were migrating from 5.0.45 to 5.0.67 version of MySQL in OpenSolaris.As part of this migration project had to test the working of PHP with MySQL database .

Here are the steps outlined:

  1. Build the MYSQL 5.0.67 DB and the SVR4 packages namely SUNWmysql5r ,SUNWmysql5u and SUNWmysql5test .
  2. Install the new MySQL packages on an OpenSolaris  installed system.
  3. Make sure you have the PHP packagesSUNWphp524root,SUNWphp524usr,SUNWphp524core SUNWphp524-mysql and SUNWphp524-mysql-root already installed.These PHP packages form the base for the PHP Interpreter.
  4. Create a default root user in MySQL DB and connect to the database
  5.      
         #/usr/mysql/bin/mysqladmin -u root -password mysql
         #/usr/mysql/bin/mysql -uroot -pmysql 
    

    Welcome to the MySQL monitor. Commands end with ; or \g.

    Your MySQL connection id is 28

    Server version: 5.0.67 Source distribution

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql> use mysql;

    Database changed

    mysql> CREATE TABLE `cars` (

    -> `id` int UNIQUE NOT NULL,

    -> `name` varchar(40),

    -> `year` varchar(50),

    -> PRIMARY KEY(id)

    -> );

    Query OK, 0 rows affected (0.03 sec)

    mysql> INSERT INTO cars VALUES(1,'Mercedes','2000');

    Query OK, 1 row affected (0.00 sec)

    mysql> INSERT INTO cars VALUES(2,'BMW','2004');

    Query OK, 1 row affected (0.00 sec)

    mysql> INSERT INTO cars VALUES(3,'Audi','2001');

    Query OK, 1 row affected (0.00 sec) 

    mysql> select id ,name,year from cars;

     +----+----------+------+
    | id | name     | year |
    +----+----------+------+
    |  1 | Mercedes | 2000 |
    |  2 | BMW      | 2004 |
    |  3 | Audi     | 2001 |
    +----+----------+------+
    3 rows in set (0.00 sec)

    mysql>

    5.Write a sample php script as shown below called "test.php"

    <?php
    $username = "root";
    $password = "mysql";
    $hostname = "localhost";

    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password)
     or die("Unable to connect to MySQL");
    echo "Connected to MySQL \n";

    //select a database to work with
    $selected = mysql_select_db("mysql",$dbhandle)
      or die("Could not select mysql:" .mysql_error());

    //execute the SQL query and return records

    $result = mysql_query("select id,name,year from cars");

    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }

    if (mysql_num_rows($result) == 0) {
        echo "No rows found, nothing to print so am exiting";
        exit;
    }
    $row=mysql_fetch_row($result);

    // While a row of data exists, put that row in $row as an associative array
    // Note: If you're expecting just one row, no need to use a loop
    echo $row[0];
    echo $row[1];
    echo $row[2];
    ?>

    
     
    6. Execute the script as 
        
        
        
        
        
        
     /usr/php5/bin/php -f /tmp/test.php
    7. The Displayed Output should look like this
    [root@sa64-v20zc-blr03]/: /usr/php5/bin/php -f /tmp/test.php
    Connected to MySQL
    1Mercedes2000
    

Thursday Aug 21, 2008

  • Remove Packages from the Repository

Working with IPS ,I realize there is no direct way to remove the packages from the Repository.

# cd /var/pkg/repo/catalog
Edit the catalog file and remove the packages to be removed .

# /usr/lib/pkg.depotd --rebuild 

This refreshes the URL with right Statistics Information as well .

  • Publish SVR4 packages to the IPS Repository
# cd /packages 
# pkgsend -s <repository url> send <SVR4 package name> 
EXAMPLE: pkgsend -s http://pkg.opensolaris.org/webstack send SUNWmysql5u

Wednesday Aug 20, 2008

The Image Packaging System software is a network-centric packaging system written in Python.

On a x86 system with install OS as snv_95 ,I built the IPS respository using the below steps .

# hd clone ssh://anon@hg.opensolaris.org/hg/pkg/gate pkg-gate
# cd pkg-gate
# make install
 
Install the packages mainly SUNWipkg & SUNWchirpy-python from the packages
directory created one level up.
You could leave the GUI packages if you choose not to install the GUI .

# /usr/lib/pkg.depotd -d repository_directory -p port_value

EXAMPLE: /usr/lib/pkg.depotd -d /export/home/user1/repository1 -p 9000

This starts the pkg.depotd server at port 9000 .Default port number 80. To confirm that the repository has been created, open your browser and type the following command http://localhost:port_value

If repository directory is not specified ,by default repository is built in /var/pkg/repo

Check to see how the repository looks like

 
[root@sa64-v20zc-blr03]/var/pkg/repo: ls
catalog  cfg_cache   file   index   pkg   trans   updatelog

Tuesday Aug 19, 2008

DTrace is a comprehensive dynamic tracing framework for  the Solaris Operating System. DTrace provides a powerful infrastructure that permits administrators, developers,  and  service personnel to concisely answer arbitrary questions about the behavior of the operating system and user programs.

Recently we enabled dtrace support for MySQL 5.1 for OpenSolaris.Here I list the way dtrace support needs to be enabled and the testing that needs to follow to check the dtrace functionality .

  • Add --enable-dtrace flag as configure option for 32 bit compilation in the Makefile
  • Add --enable-dtrace DTRACEFLAGS="-64" for 64 bit compilation in the Makefile


After the package is built and installed ,test dtrace functionality as follows.

As root
1)#dtrace -l | grep mysql

This should give you complete listing of the dtrace probes that are supported by the MySQL patch.
Example

17727 mysql24788            mysqld __1cNsp_instr_stmtJexec_core6MpnDTHD_pI_i_ query_execute_start
17728 mysql24788            mysqld __1cVexecute_sqlcom_select6FpnDTHD_pnKTABLE_LIST__b_ select_end
17729 mysql24788            mysqld __1cVexecute_sqlcom_select6FpnDTHD_pnKTABLE_LIST__b_ select_start
17730 mysql24788            mysqld __1cVmysql_execute_command6FpnDTHD__i_ update_end
17731 mysql24788            mysqld __1cHhandlerNha_update_row6MpkCpC_i_ update_row_end
17732 mysql24788            mysqld __1cHhandlerNha_update_row6MpkCpC_i_ update_row_start
17733 mysql24788            mysqld __1cVmysql_execute_command6FpnDTHD__i_ update_start

2) dtrace -n mysql24788:mysqld:__1cVexecute_sqlcom_select6FpnDTHD_pnKTABLE_LIST__b_:select_start

Do a ^C here ,it says matched 1probe ...

3) Run step 2 again and while running step 2 again ,open another session ,connect to database and execute any select statement ,you should see the dtrace count increasing ...

Example :

A simple select statement will look like this 
mysql> select User,Host,Password from user; 

Hope this helps beginners with dtrace .

MySQL 5.0.45 is available in Solaris Express Developer Edition (SXDE) 01/08 with Solaris Service Management Facility (SMF) enabled. Recently MySQL 5.0.45 for 64-bit content was integrated with Open Solaris build 87.

First a quick recap of what is SMF:

SMF is the core component of the predictive self-healing technology available in Solaris 10, which provides automatic recovery from software and hardware failures as well as adminstrative errors. Some of the advantages of using SMF are as under:

  • Failed services are automatically restarted in dependency order, whether they failed as the result of administrator error, software bug, or were affected by an uncorrectable hardware error.
  • More information is available about misconfigured or misbehaving services, including an explanation of why a service isn't running , as well as individual, persistent log files for each service.
  • Problems during the boot process are easier to debug, as boot verbosity can be controlled, service startup messages are logged, and console access is provided more reliably during startup failures. *Administrators can securely delegate tasks to non-root users more easily, including the ability to configure, start, stop, or restart services .
  • Large systems boot faster by starting services in parallel according to their dependencies.

 Below are the SMF service manifest to enable the 64-bit server and accompanying shell script needed to integrate MySQL with Solaris SMF.

Perform the following steps to import the manifest into the SMF repository.

1.Save the following XML code to a file called "mysql.xml" in /var/svc/manifest/application/database. You need to create the directory if it doesn't exist and have the appropriate privileges to perform this action. The default instance of the manifest assumes that the database user is mysql and the database directory is /var/mysql/5.0/data . If any of them is different, update the above XML accordingly.

2. Save the following shell script to a file called "mysql"

getproparg() {
        val=`svcprop -p $1 $SMF_FMRI`
        [ -n "$val" ] && echo $val
}

MYSQLBIN=`getproparg mysql/bin`
MYSQLDATA=`getproparg mysql/data`
PIDFILE=${MYSQLDATA}/`/usr/bin/uname -n`.pid


if [ -z $SMF_FMRI ]; then
        echo "SMF framework variables are not initialized."
        exit $SMF_EXIT_ERR
fi

if [ -z ${MYSQLDATA} ]; then
        echo "mysql/data property not set"
        exit $SMF_EXIT_ERR_CONFIG
fi

if [ ! -d ${MYSQLDATA} ]; then
        echo "mysql/data directory ${MYSQLDATA} is not a valid MySQL data directory"
        exit $SMF_EXIT_ERR_CONFIG
fi

if [ ! -d ${MYSQLDATA}/mysql ]; then
        ${MYSQLBIN}/mysql_install_db --user=mysql --datadir=${MYSQLDATA}
fi


mysql_start()   {
        MYSQLDVAL=`getproparg mysql/enable_64bit mysql:version_50`
        if [ "$MYSQLDVAL" != "" ] ; then
        case "$MYSQLDVAL" in
        true|1)
                #Check if the system architecture supports 64-bit applications
                PLATFORM=`isainfo -b`
                if [ "${PLATFORM}" != "64" ]; then
                echo "This system is not capable of supporting 64-bit applications."
                echo "Set the \"enable_64bit\" property value to \"false\" to start the 32-bit server."
                exit $SMF_EXIT_ERR_CONFIG
                else
                echo ${MYSQLBIN}/64/mysqld --user=mysql --datadir=${MYSQLDATA} --pid-file=${PIDFILE} > /dev/null &
                ${MYSQLBIN}/64/mysqld --user=mysql --datadir=${MYSQLDATA} --pid-file=${PIDFILE} > /dev/null &
                fi
        ;;
        false|0)
                echo ${MYSQLBIN}/mysqld --user=mysql --datadir=${MYSQLDATA} --pid-file=${PIDFILE}
                ${MYSQLBIN}/mysqld --user=mysql --datadir=${MYSQLDATA} --pid-file=${PIDFILE} > /dev/null &

        ;;
        esac
        fi
 
}


mysql_stop()    {
        if [ -f ${PIDFILE} ]; then
        pkill mysqld
        fi
}

case "$1" in
'start')
        mysql_start
        ;;

'stop')
        mysql_stop
        ;;


*)
        echo "Usage: $0 {start|stop}"
        exit 1
        ;;

esac
exit $SMF_EXIT_OK

3. Place the shell script "mysql" in /lib/svc/method.

4. Change the permission to 555. You need to have the appropriate write privileges to copy files into this directory.

5. Initially the service instance is disabled. Use the following command to see the state.

# svcs mysql

6. Start the service for the default instance by executing the following command:

# /usr/sbin/svcadm enable mysql

By default the 32 bit mysqld server is started .

7. To start the 64-bit mysqld server via SMF ,do the following .

#svccfg

svc>select mysql:version_50

svc:/application/database/mysql:version_50>listprop mysql/enable_64bit

mysql/enable_64bit boolean false

svc:/application/database/mysql:version_50>setprop mysql/enable_64bit=true svc:/application/database/mysql:version_50>listprop mysql/enable_64bit

mysql/enable_64bit boolean true

svc:/application/database/mysql:version_50>quit

8. Refresh the manifest as follows with the updated configuration

#svcadm refresh mysql:version_50

9. Start the 64-bit mysqld server

#svcadm enable mysql:version_50

10.Check if the mysqld is started from /usr/mysql/5.0/bin/64 do the following

# svcs mysql

STATE   STIME        FMRI

online     21:08:38          svc:/application/database/mysql:version_50

# ps -eaf | grep mysqld

mysql 18181 1 0 21:08:38 ? 0:07 /usr/mysql/5.0/bin/64/mysqld --user=mysql --datadir=/var/mysql/5.0/data --pid-file

The 64-bit server is initiated. From this point on the MySQL process is controlled by the Solaris SMF. For more details on how to use SMF, refer to the following BigAdmin site: http://www.sun.com/bigadmin/content/selfheal/

This blog copyright 2009 by Sunanda Menon