Posts

Showing posts from August, 2009

[Level 2] Declare and Handlers in MySQL Stored Procedure.

In MySQL stored procedure, we use use "DECLARE" statement to define some variables, like: Local Variable, Conditions and handlers and Cursors. Something you should to take care is about the sequence of these variables declaration. The correct sequence is: 1. Variables 2. Conditions 3. Cursors 4. Handlers IF the sequence is not correct, you will get a error message while building stored procedure. The example for these variables declaration as below: 1. Variables: mysql> DECLARE no int; 2. Conditions mysql> DECLARE co CONDITION FOR SQLSTATE '23000'; 3. Cursors mysql> DECLARE cu CURSOR FOR SELECT * FROM MYSQL.USER; 4. Handlers mysql> DECLARE CONTINUE HANDLER FOR co BEGIN END; -- the empty between BEGIN and END means to ignore the handler, do nothing. Wish this helps. regards, Stanley Huang

[Level 1] Switch between user and role in OpenSolaris.

As we know, when we add a new user during OpenSolaris installation wizards, then installer will switch "root" from user to role. And we cannot login the system with role "root". How can we switch root from user to role, after that, how can we switch back? You can use the command below: 0. how to verify root is user or role: [case 1: root is role] # cat /etc/user_attr | grep ^root; root::::type=role;auths=solaris.*,solaris.grant;profiles=All;lock_after_retries=no;clearance=admin_high;min_label=admin_low [case 2: root is user] # cat /etc/user_attr | grep ^root; root::::type=normal;auths=solaris.*,solaris.grant;profiles=All;lock_after_retries=no;clearance=admin_high;min_label=admin_low 1. Change root from role to user: # rolemod -K type=normal root; 2. Change root from user to role: # usermod -K type=role root; Wish this helps. regards, Stanley Huang

[Level 2] How Fast to Clone a Zone in OpenSolaris?

How long do I need for clone a new testing zone from a production zone? 10 mins, 20 mins or more? Such kind of answer maybe you think is. Do not consider about the time that service down spends in your system (for some special AP, that maybe take a long time to stop), it just need few seconds to build a new testing environment. How could it be so fast? Because OpenSolaris cloning a zone just use the new feature of ZFS clone technology. When you create a zone and set the zonepath just under a zfs mount point, the command zoneadm will create a ZFS for your zone. Ex. # zfs list rpool/zones NAME            USED  AVAIL  REFER  MOUNTPOINT rpool/zones   278M  32.9G    27K  /export/zones zonecfg> set zonepath=/export/zones/zone1 zonecfg>... # zoneadm -z zone1 install A ZFS file system has been created for this zone. How do we clone a zone with zone1? The step as the following 1. halt source zone # zlogin zone1 init 5 2. export config from zone1 zonecfg -z zone1 expor

[Level 2] MySQL Stored Procedure Characteristics

MySQL Stored Procedure has two major characters, "SQL SECURITY" and "Data Use". "SQL SECURITY" defines what's the effect user while procedure is called, and "Data Use" indicates the procedure R/W. The detail information as the following: 1. SQL SECURITY:   a. DEFINER-The routine will have the privileges of the user who created it.   b. INVOKER-The routine will have the privileges of ther user who run it.   If you want to change the character, use the command as below:   mysql> ALTER PROCEDURE procedure_name SQL SECURITY [DEFINER/INVOKER]; 2. Data Use:   a. CONTAONS SQL-The option indicates that the routine has the SQL statement but it does not have read or write data.   b. NO SQL-The option indicates that the routine does not have SQL statement.   c. READS SQL DATA-The option indicates that the routine has the SQL statement with read data only.   d. MODIFIES SQL DATA-The option indicates that the routine has the SQL statement wi

[Level 1] Chime, the DTrace GUI tool.

Chime is a DTrace GUI tool. The way you can install and use as the following steps: 1. First, get the package from OpenSolaris.og, the link as below. http://opensolaris.org/os/project/dtrace-chime/install/ Because Chime is developed by Java, you must have Java 6 since 1.4.41 environment for Chime to run. 2. Start Chime: You have to check the account runs Chime has the privileges to run DTrace. The Command as below. # /opt/OSOL0chime/bin/chime 3. Choose category: Default Chime has six categories, and choose one that you want. 4. Choose traces: Choose the trace you want. At the same time, the right column will show the description of the trace you choose. 5. Click "Run" to execute: And it will pop out the screen with information sheet. If you want to make your own trace, you can click menu bar with option File -> New Trace, Following the wizard, and insert the information needed. (I recommend that you should have basic knowledge of D-script) The specific par

[Level 3] Systemtap on Linux.

Today, my boss want me to find some data to compare with Solaris and Linux. And I find a freeware(GPL) on Linux, called systemtap . It looks like the "DTrace" in Solaris. As the documents writes, the we have to download the kernel package then we can start to use it. The commands as the following: # yum install systemtap kernel-devel yum-utils # debuginfo-install kernel   The sample "script" as the following: # stap -ve 'probe begin { log("hello world") exit () }' # stap -c df -e 'probe syscall.* \ { if (target()==pid()) log(name." ".argstr) }'    Any Linux user use this before? Wish this helps. regards, Stanley Huang

[Level 1] Solve MySQL case insensitive problem.

In default, MySQL is case insensitive. ex. mysql> select * from t where n = 'a'; +------+ | n    | +------+ | A    | +------+ If we want to solve this problem, we can use following ways: 1. Modify you SQL statement(temporary solution), add the key word 'binary' before your string. ex. mysql> select * from t where n = binary 'a'; Empty set (0.00 sec) mysql> select * from t where n = binary 'A'; +------+ | n    | +------+ | A    | +------+ 1 row in set (0.00 sec) 2. Modify the table schema, and let the column be case sensitive. mysql> select * from t where n = 'a'; Empty set (0.00 sec) mysql> select * from t where n = 'A'; +------+ | n    | +------+ | A    | +------+ 1 row in set (0.00 sec) 3. To let the new table has case sensitive feature, modifing the database character and collation. (If you want the new table with case insensitive, you can assign the table with "not" case se

[Level 1] Set wifi manually.

Although, OpenSolaris has NWAM, can let user easy to setup the wifi. But how can we do if we want to setup wifi manually?  The steps as the following: 1. Check wireless interface is plumbed or not. if not, plumb it.    Ex1. Plumb all interface.   # ifconfig -a   Ex2. Plumb the interface name that you know.   # ifconfig ipw0 plumb 2. Scan the ap.   # wificonfig -i ipw0 scan essid           bssid             type          encryption      signallevel test-ap          12:34:56:78:90:00 access point  wep             12 3. Setting wifi profile and use WEP for authentication. In this case I set the WEP password as "1234567890" and profile name as "test-profile". After setting is done, use subcommand "showprofile" to show profiles.   # wificonfig createprofile test-profile essid=test-ap encryption=WEP wepkey1=1234567890   # wificonfig showprofile [ses-ap]         essid=test-ap         encryption=WEP         bssid=12:34:56:78:90:00         we

[Level 3] ZFS ARC stat script.

Sometimes, when we use OpenSolaris, we will find out the memory usage is very high. That's because ZFS ARC architecture will use memory as possible, and how can we know the ZFS ARC status? Actually we can use the command "kstat", but it seems to hard for general end user. And I found out a good script from World Wide Web, Neelakanth Nadgir , who writes a script in perl for easy to check ZFS ARC. And this script is worth for you to read. regards, Stanley Huang ******************************************************************************** #!/bin/perl -w # # Print out ZFS ARC Statistics exported via kstat(1) # For a definition of fields, or usage, use arctstat.pl -v # # Author: Neelakanth Nadgir http://blogs.sun.com/realneel # Comments/Questions/Feedback to neel_sun.com or neel_gnu.org # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, Version 1.0 only # (the "License"

[Level 1] Install MySQL in OpenSolaris

The Step as the following: 1. Use Package Mangement to download MySQL 5.1 (SUNWmysql51) 2. Start MySQL server # /etc/init.d/mysql start 3. set root password # mysqladmin -u'root' password 'new_password' 4. Login MySQL by mysql client with root account. # mysql -u'root' -p'new_password' regards, Stanley Huang

[Level 3] Script for Solaris Zone FSS.

The following script that I found in the world wide web. It is a good utility that you can adjust cpu priority with FSS for your zone. with this helps, regards, Stanley Huang #!/usr/bin/ksh # # zonefss - zone FSS administration. Solaris 10. # FSS : Fair Share Scheduler # # 05-Apr-2005, ver 0.50 (first release) # # USAGE: zonefss -l | -z zone shares # eg, # zonefss -l # list FSS share values for all zones # zonefss -z global 10 # set the global zone shares to 10 # # Standard Disclaimer: This is freeware, use at your own risk. # # 05-Apr-2005 Brendan Gregg Created this. # ### Process Arguments PATH=/usr/bin:/usr/sbin list=0 set=0 if [[ "$1" == "-l" ]]; then shift; list=1 fi if [[ "$1" == "-z" ]]; then shift; set=1 zone=$1; shift shares=$1; shift fi ### List FSS shares if (( list )); then printf "%4s %-16s %s\n" "ID" "NAME" "SHA

[Level 3] Open HA Cluster Whitepaper

I got the information from Nicholas Solter's blog. Nicholas is one of the authors writing OpenSolaris Bible . If you are the one who interests Open HA Cluster and OpenSolaris, I recommend you to read the Open HA Cluster Whitepaper . regards, Stanley Huang

OpenSolaris on SLX

Today, I find out a website which use vedio to present about the SUN technology. Of course, included OpenSolaris. After viewing some vedio, that impress me. I recommend you to watch it when you have free time. The website as the following: https://slx.sun.com/channel/1179273732 regards, Stanley Huang

[Level 1] How to set ip forwarding in OpenSolaris

It's easy to set ip forwarding in OpenSolaris. The command the following: # routeadm -u -e ipv4-forwarding To check the config again: # routeadm

How often does other user group hold the meeting?

We hold the meeting for 3-4 times in past few years, and I wonder how often does other user group hold the meeting. Then I find out one of these user group has almost 30 times, the number is six times of ours. They hold the meeting every month, that surprises me. Maybe we can let the meeting more often as possible. But one thing before that, we should study OpenSolaris more, and we could share more information to those who interested it.

[Level 2] ZFS and DTrace in Mac.

My friend who use Mac OS X, and told me that the Mac OS X support ZFS and DTrace. It surprises me! ZFS and DTrace is the new feature of Solaris 10, of course, OpenSolaris also has these two features, too. So I try the ZFS and DTrace on Mac immediately. After test, I have the two following conclusions. 1. Mac support ZFS but for read only, so Mac cannot modify ZFS. That's so pity. The primary reason that I love ZFS just because I can have snapshot, clone. Readonly, is not the impression that I know about ZFS. 2. In OpenSolaris, it has over 60K probes(use command to check how many probes your system has, "/usr/sbin/dtrace -l | wc -l"), so I can detect the system behavior. But when I use the command, I found out the Mac OS only have just over 20K probes, just the 1/3 of OpenSolaris. And I try the D-script, it does work. That's a good gift that all Mac fans should to cherish. Really, because DTrace can be used for online debug, performance and you do not need to modify

[Level 1] Create OpenSolaris zone

Today I try to install zone in OpenSolaris. I find out the default value of global attribute "brand" is ipkg. Then I modify this attribute with value "native" ( Solaris 10 default attribute value ). After I execute the command "zoneadm -z myzone install", it will be failed with the following message: [root@Stanley-NB]:/shell/SolarisCommands/zones# zoneadm -z myzone install sh: line 1: /usr/lib/lu/lucreatezone: not found What's the command "lucreatezone"? It's the Solaris 10 command for create a new zone with live upgrade.

[Level 3] One shell a day, keep commands away~

The following the script is my template to create a new shell script. with this helps, regards, Staley Huang #!/usr/bin/bash #/usr/bin/bash -xvu # -x: print command and arguments after interpreted # -v: print command and arguments before interpreted # -f: no file globbing # -u: treat unbound variable as error # ex. # a=1 # b=$a # c=$d ( Error: unbound variable / parameter not set ... ) # ##Bash Note: # while $1=null # if [ -f $1] => true # if [ -d $1] => true # if [ -f "$1" ] => false # if [ -d "$1" ] => false # ################################################################ # # Customize the setting following the key search # [##**--] # # psedu code: # # ################################################################ # # This template file is for ceating bash script program # All copyright reserved by Stanley Huang # # __ script name ___________: [##**--(/shell/_shell_template.sh)] ## Do no