2008年10月15日 星期三

Common useful mysql commands

use root account to login to database "mysql"
# mysql -u root mysql

Show all fields of a selected table
mysql> desc user;

mysql> select User,Host from mysql.user;

Some on-line help
mysql> help contents;
You asked for help about help category: "Contents"
For more information, type 'help ', where is one of the following
categories:
Account Management
Administration
Data Definition
Data Manipulation
Data Types
Functions
Functions and Modifiers for Use with GROUP BY
Geographic Features
Language Structure
Storage Engines
Stored Routines
Table Maintenance
Transactions
Triggers

mysql> Update user SET Insert_priv='y',Update_priv='y' where user='openser'; Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

# Before update the value. Show the record value of specified field in a indicated record (user)
mysql> Select User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Reload_priv From user WHERE user='openser';
+---------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+
| User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv |
+---------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+
| openser | Y | Y | Y | N | N | N | N |
+---------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+
1 row in set (0.00 sec)

# Update the value of specified field in a indicated record (user)
mysql> Update user SET Delete_priv='y',Create_priv='y',Drop_priv='y',Reload_priv='y' where user='openser'; Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

# After update the value. Show the record value of specified field in a indicated record (user)
mysql> Select User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Reload_priv From user WHERE user='openser';
+---------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+
| User | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv |
+---------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+
| openser | Y | Y | Y | Y | Y | Y | Y |
+---------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+
1 row in set (0.00 sec)

Linux Command - sed

Example1.
#/etc/links1 檔案內容
WAN1=rtk0
WAN2=rtk1
LAN1=rtk2
DMZ1=rtk3
DMZ2=rtk4
WAN3=rtk5

# sed -n '3p' /etc/links1
LAN1=rtk2 -->只印出第3行

# sed '5p' /etc/links1
WAN1=rtk0
WAN2=rtk1
LAN1=rtk2
DMZ1=rtk3
DMZ2=rtk4
DMZ2=rtk4 --> 印出第5行
WAN3=rtk5

./Orig file
/usr/home/vincent/EP/target/vendors/D-Link/DFL-1500/www/help/help_files/ad_bm.html
/usr/home/vincent/EP/target/vendors/D-Link/DFL-1500/www/help/help_files/ad_bm_action.html

// 經過執行sed 之後
sed 's/EP\/target\/vendors\/D-Link\/DFL-1500\/www\/help/Help\/Current/g' ./Orig > ./Comp

./Comp file
/usr/home/vincent/Help/Current/help_files/ad_bm.html
/usr/home/vincent/Help/Current/help_files/ad_bm_action.html


研究如何將 "所有的檔案路徑移除,只留下檔案名稱"
Enterprise$ cat x
/abc/123
/abc/der/123
/usr/home/vincent/Help/Current/help_files/ad_bm_action.html

# sed 's/\/([a-zA-Z0-9_]* \ / )*//g' ./x ==> 目前利用這個方法無法work

Enterprise$ sed 's/\/.*\///g' ./x ==> 這個方法是work的,但是太簡單了,需要再想過更好的方法:)
123
123
ad_bm_action.html


.config
#
# Automatically generated make config: don't edit
# Linux kernel version: 2.6.10
# Tue Nov 29 11:18:26 2005
#
CONFIG_X86=y
CONFIG_MMU=y
CONFIG_UID16=y
CONFIG_GENERIC_ISA_DMA=y
CONFIG_GENERIC_IOMAP=y

#
# Code maturity level options
#
CONFIG_EXPERIMENTAL=y
CONFIG_CLEAN_COMPILE=y
CONFIG_BROKEN_ON_SMP=y

# sed -ne 's/^\([A-Z0-9_]*\)=\(.*\)$/#define \1 \2/p' < .config > ./output

output
#define CONFIG_X86 y
#define CONFIG_MMU y
#define CONFIG_UID16 y
#define CONFIG_GENERIC_ISA_DMA y
#define CONFIG_GENERIC_IOMAP y
[略]


The separate token can be either ; or /
# echo --datadir=/var/lib/mysql | sed -e 's;--datadir=;;'
/var/lib/mysql
# echo --datadir=/var/lib/mysql | sed -e 's/--datadir=//'
/var/lib/mysql

We can use sign "#" as the separater, the example is a snapshot of the kamailio Makefile install target
# sed -e "s#/usr/.*lib/kamailio/modules/#/usr/local/lib/kamailio/modules/#g" < etc/kamailio.cfg

# make original file as the filename add suffix name ".old"
sed -i.old -e 's%ftp://ftp.gnu.org/gnu/gcc/releases/gcc-%http://ftp.gnu.org/gnu/gcc/gcc-%' -e 's/gdb //' make/gcc-uclibc-3.3.mk

2008年10月14日 星期二

Linux Command - Some useful tools

Show the file type ?
# type ulimit
ulimit is a shell builtin
# type vi
vi is aliased to `vim'
# type mysql
mysql is /usr/bin/mysql
# type mysqld_safe
mysqld_safe is /usr/bin/mysqld_safe

Question:
The "type" command is similar to the "file" command. What is the difference?
Answer:
The "file" command is used to determine the file type of a specified file.
And "type" command is used to determine the type of executable program. And "type" will also point the entire path of the specified program in the current file system.

Setup mysql

http://dev.mysql.com/doc/refman/5.0/en/access-denied.html

1. setup grant table for system to do the access control, run the following command to create the table(in the mysql folder) which will located in the the mysql installation directory (e.g. /var/lob/mysql)
/usr/bin/mysql_install_db

/usr/local/bin/mysql_install_db --user=mysql

2. run the mysqld server, main starting script of mysql
/usr/bin/mysqld_safe &

3. ps aux | grep mysql
mysql 7634 0.7 0.8 135872 17516 pts/11 Sl 14:11 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock

Generally, mysqld is statred with the following arguments
/usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock


4. Stop the mysqld
Either use kill to terminate the mysql or use mysqladmin
# /usr/bin/mysqladmin -u root shutdown

5. Trouble shooting
read the error log of mysql "/var/log/mysqld.log"

5.1. We must create the user "mysql" manually (Doesn't mysql offer standard procedure to create the "mysql" user)
# useradd -m mysql

5.2. Refer to the following information, mysqld need to setup the process id but the directory is not yet created. So we need to create it manually and set its user/group as mysql.
[ERROR] /usr/local/libexec/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)
081117 10:24:23 [ERROR] Can't start server: can't create PID file: No such file or directory

# mkdir /var/run/mysqld
chown mysql:mysql /var/run/mysqld/



default path of mysql file
the path of server daemon
==> /usr/libexec/mysqld
config file
==> /etc/my.cnf
default error log
==> err_log=/var/log/mysqld.log
default pid file
==> pid_file=/var/run/mysqld/mysqld.pid

data directory (mysql database repository?)
DATADIR=/var/lib/mysql

mysql use unix domain socket? so the specified unix socket file is in the following path..(just guesting.)
mysql_unix_port=/var/lib/mysql/mysql.sock



inside the mysqld_safe
default directory
MY_BASEDIR_VERSION=/usr
ledir=/usr/libexec
DATADIR=/var/lib/mysql
MYSQL_HOME=/usr


The my_print_defaults is only used in the mysql project?

man my_print_defaults
my_print_defaults - display options from option files

/usr/bin/my_print_defaults --loose-verbose mysqld server


One question, I can't kill the mysqld process. Either using kill -9 or kill -0. It is still alive. Just the process id is change only (since the process is killed but restored by the other mysql daemon)

# ps auxwww | grep mysql
mysql 10454 0.8 0.8 135872 17516 pts/11 Sl 17:35 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock
# killall -9 mysqld
# ps auxwww | grep mysql
mysql 10482 0.7 0.8 135872 17516 pts/11 Sl 17:36 0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --socket=/var/lib/mysql/mysql.sock

2008年10月12日 星期日

Configure kamailio experience

First you need to setup the mysql if you want to use the db_mysql module

Setup mysql via yum
# yum install mysql.i386 ==> include mysql client software
# yum install mysql-server.i386 ==> include mysqld mysqld_safe.. server program


We need to create the mysql related tables. Before we create the mysql table. We need to specify the db-engine type in the kamctlrc config file.
/usr/local/etc/kamailio/kamctlrc
DBENGINE=MYSQL

Then use the kamailio database script(kamdbctl) to create the related table
/usr/sbin/kamdbctl create

Run the kamailio program
./kamailio -D -ddddddddd

How to make kamailio TLS work?
* First you must compile the kamailio-1.4.0-tls_src.tar.gz source tarball with the TLS=1 set in the Makefile

* Second you must make sure the "fork = yes" in the kamailio config file
Refer to the document in the TLS tutorial
http://www.kamailio.org/docs/tls-devel.html#TLS-EXAMPLE

1.7. OpenSER with TLS - script example

IMPORTANT: The TLS support is based on TCP, and for allowing OpenSER to use TCP, it must be started in multi-process mode. So, there is a must to have the "fork" parameter set to "yes":

NOTE: Since the TLS engine is quite memory consuming, increase the used memory by the run time parameter "-m" (see OpenSER -h for more details).

* fork = yes ==> The most important part

Configure bugzilla experience

利用checksetup.pl 設定 bugzilla root e-mail address, 盡可能設定reachable e-mail address
開設帳號, 可以利用user 自行login 來create new account 的方式 (New Account), bugzilla 發bug 之後, 會自動送出e-mail 到負責bug的e-mail 信箱中

必要的設定,

Parameters-->
Required Settings -->
User Authentication -->
Email ==> Can't find this option :(


Users use bugzilla system need to register account first. Or the bugzilla will reject any accessing actions for the not authenticated user.
Parameters-->
Required Settings -->
User Authentication -->
requirelogin (Set on, original off)

Only the bugzilla administrator can create user account. Disable the user self register the bugzilla system.
Parameters-->
Required Settings -->
User Authentication -->
createemailregexp (set "" blank, original .* allow all e-mails)

If we disable the feature of user self creating account, then the bugzilla administrator must create user account for the new coming user.

The original descriptions of the bugzilla system for the "createemailregexp" field
This defines the regexp to use for email addresses that are permitted to self-register using a 'New Account' feature. The default (.*) permits any account matching the emailregexp to be created. If this parameter is left blank, no users will be permitted to create their own accounts and all accounts will have to be created by an administrator.

2008年10月8日 星期三

sendmail experience

Show the sendmail version

# /usr/sbin/sendmail -d0 < /dev/null | grep -i version