2009年12月24日 星期四

Howto mount USB drive in Linux

Detecting USB hard drive

After you plug in your USB device to your USB port, linux will add new block device into /dev/ directory. At this stage you are not able to use this device as the USB filesystem needs to be mouted before you are able to retrieve any data. To find out what name your block device file have you can run fdisk command:

# fdisk -l

You will get output similar to this:
Disk /dev/sdb: 60.0 GB, 60060155904 bytes
255 heads, 63 sectors/track, 7301 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000b2b03

Device Boot Start End Blocks Id System
/dev/sdb1 1 7301 58645251 b W95 FAT32

3. Creating mount point

Create directory where you want to mount your device:
mkdir /mnt/sdb1
4. Edit /etc/fstab

To automate this process you can edit /etc/fstab file and add line similar to this:
/dev/sdb1 /mnt/sdb1 vfat defaults 0 0
Run mount command to mount all not yet mounted devices. Keep in mind that if you have more different USB devices in you system, device name can vary!!!
# mount -a

摘自:http://www.linuxconfig.org/Howto_mount_USB_drive_in_Linux

Big許功蓋文字一覽


ASCII(5C) == "\"
A45C么 AE5C娉 B85C稞 C25C擺 A55C功
AF5C珮 B95C鈾 C35C黠 A65C吒 B05C豹
BA5C暝 C45C孀 A75C吭 B15C崤 BB5C蓋
C55C髏 A85C沔 B25C淚 BC5C墦 C65C躡
A95C坼 B35C許 BD5C穀 AA5C歿 B45C廄
BE5C閱 AB5C俞 B55C琵 BF5C璞 AC5C枯
B65C跚 C05C餐 AD5C苒 B75C愧 C15C縷

ASCII(7C) == "|"
AA7C泜 B47C揉 A87C育 BE7C魯 B27C琍
BC7C慝 C67C鸛 A97C尚 B37C逖 BD7C罵
A77C坑 B17C悴 BB7C誡 C57C疊 A67C帆
B07C院 BA7C漏 C47C辮 AB7C咽 B57C稅
BF7C糕 AC7C洱 B67C閏 C07C嚐 AD7C迢
B77C會 C17C舉 A47C弋 AE7C徑 B87C腮
C27C甕 A57C四 AF7C砝 B97C頌 C37C牘

2009年12月21日 星期一

RHEL Linux安裝phpMyAdmin

到phpMyAdmin網頁下載最新的套件http://www.phpmyadmin.net/home_page/index.php
將下載回來的tar檔解開
#tar zxvf phpMyAdmin-2.11.8.1-all-languages.tar.gz
再將解壓縮的資料夾改名並移動到網頁的根目錄
(預設為/var/www/html)
#mv ./phpMyAdmin-2.11.8.1-all-languages /var/www/html/phpMyAdmin

#cd /var/www/html/phpMyAdmin
產生config.inc.php設定檔
預設是沒有這個檔案的,要先將config.sample.inc.php複製成config.inc.php
#cp ./config.sample.inc.php ./config.inc.php
將認證方式改為http或是cookie還有修改hostname

如果你要以http認證只要修改2個地方
#vi ./config.inc.php
$cfg['Servers'][$i]['auth_type'] = 'http'; <==改為http
$cfg['Servers'][$i]['host'] = '127.0.0.1'; <==改成你127.0.0.1

如果你要以cookie認證方式那你還要多設一個地方
#vi ./config.inc.php
$cfg['blowfish_secret'] = 'gtry356dfgejdkv42jnl5'; <==隨便輸入亂數的字讓cookie做密碼加密演算,最多46個字
$cfg['Servers'][$i]['auth_type'] = 'cookie'; <==改為cookie
$cfg['Servers'][$i]['host'] = 'example.com.tw'; <==改成你的電腦名稱

做完以上2個設定就完成了
因為之前有安裝一些php的套件,所以要重起httpd
#service httpd restart

網路上很多舊文章都說要改
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '*****';
那是舊的認證方法了,現在為了安全考量已不這麼做了.

You don't have permission to access/phpMyAdmin/ on this server.

關閉SELinux即可
shell>vi /etc/sysconfig/selinux
selinux=disable

shell>vi /etc/grub.conf
kernel /vmlinuz-2.6.18-8.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet selinux=0
在quiet后面加上selinux=0

2009年12月20日 星期日

XenServer 在RHEL5下實作LVM

需求:
-新增三個LVM的partition,各100M
-新增三個PV
-新增一個VG,size=100M
-新增一個LV,size=50M
-動態放大VG,size+200M
-動態放大LV,size+50M

-新增三個LVM的partition,各100M
root@new-host-6:~^G[root@new-host-6 ~]# fdisk /dev/hda

The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (908-1044, default 908):
Using default value 908
Last cylinder or +size or +sizeM or +sizeK (908-1044, default 1044): +100M

Command (m for help): n
First cylinder (921-1044, default 921):
Using default value 921
Last cylinder or +size or +sizeM or +sizeK (921-1044, default 1044): +100M

Command (m for help): n
First cylinder (934-1044, default 934):
Using default value 934
Last cylinder or +size or +sizeM or +sizeK (934-1044, default 1044): +100M

Command (m for help): p

Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 778 6144862+ 83 Linux
/dev/hda3 779 843 522112+ 82 Linux swap / Solaris
/dev/hda4 844 1044 1614532+ 5 Extended
/dev/hda5 844 907 514048+ 83 Linux
/dev/hda6 908 920 104391 83 Linux
/dev/hda7 921 933 104391 83 Linux
/dev/hda8 934 946 104391 83 Linux

Command (m for help): t
Partition number (1-8): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)

Command (m for help): t
Partition number (1-8): 7
Hex code (type L to list codes): 8e
Changed system type of partition 7 to 8e (Linux LVM)

Command (m for help): t
Partition number (1-8): 8
Hex code (type L to list codes): 8e
Changed system type of partition 8 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 778 6144862+ 83 Linux
/dev/hda3 779 843 522112+ 82 Linux swap / Solaris
/dev/hda4 844 1044 1614532+ 5 Extended
/dev/hda5 844 907 514048+ 83 Linux
/dev/hda6 908 920 104391 8e Linux LVM
/dev/hda7 921 933 104391 8e Linux LVM
/dev/hda8 934 946 104391 8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
重新開機,讓它生效!
[root@new-host-6 ~]# reboot

-新增三個PV
[root@new-host-6 ~]# pvcreate /dev/hda6
Physical volume "/dev/hda6" successfully created
[root@new-host-6 ~]# pvcreate /dev/hda7
Physical volume "/dev/hda7" successfully created
[root@new-host-6 ~]# pvcreate /dev/hda8
Physical volume "/dev/hda8" successfully created
驗證一下
[root@new-host-6 ~]# pvdisplay
--- NEW Physical volume ---
PV Name /dev/hda6
VG Name
PV Size 101.94 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID NPXgcU-Pad8-EsG7-gFtI-hK66-8ua8-H0c78U

--- NEW Physical volume ---
PV Name /dev/hda7
VG Name
PV Size 101.94 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID NeXk3q-RKtl-Ias2-TIO0-0gbq-IdU9-XuL5DC

--- NEW Physical volume ---
PV Name /dev/hda8
VG Name
PV Size 101.94 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Y9ERKn-oo61-mWj3-IOIZ-ba2p-QJID-UGzi4Q

-新增一個VG,size=100M
[root@new-host-6 ~]# vgcreate rootvg /dev/hda6
Volume group "rootvg" successfully created
驗證一下
[root@new-host-6 ~]# vgdisplay
--- Volume group ---
VG Name rootvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 100.00 MB
PE Size 4.00 MB
Total PE 25
Alloc PE / Size 0 / 0
Free PE / Size 25 / 100.00 MB
VG UUID 2XpLIi-L1Cp-IbbB-cJ38-id6b-U6Qh-K4j3Gu

-新增一個LV,size=50M
[root@new-host-6 ~]# lvcreate -L +50M -n lv01 rootvg
Rounding up size to full physical extent 52.00 MB
Logical volume "lv01" created
驗證一下
[root@new-host-6 ~]# lvdisplay
--- Logical volume ---
LV Name /dev/rootvg/lv01
VG Name rootvg
LV UUID zWA1PJ-iy4L-PZcG-NgNw-eSue-7xmP-Tw2HNs
LV Write Access read/write
LV Status available
# open 0
LV Size 52.00 MB
Current LE 13
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0
建立一個mount point: /mnt/lvm,並將其格式化成ext3檔案格式,掛載於/mnt/lvm下
[root@new-host-6 ~]# mkdir /mnt/lvm
[root@new-host-6 ~]# mke2fs -j /dev/rootvg/lv01
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
13328 inodes, 53248 blocks
2662 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=54525952
7 block groups
8192 blocks per group, 8192 fragments per group
1904 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@new-host-6 ~]# mount /dev/rootvg/lv01 /mnt/lvm/
[root@new-host-6 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 5.7G 2.9G 2.6G 53% /
/dev/hda1 99M 9.8M 84M 11% /boot
tmpfs 125M 0 125M 0% /dev/shm
/dev/hda5 487M 11M 451M 3% /home
/dev/mapper/rootvg-lv01
51M 4.9M 43M 11% /mnt/lvm
Copy一些檔案到此目錄下,以供等會驗證動態放大檔案系統時,資料不會消失
[root@new-host-6 ~]# cp -r /boot/ /mnt/lvm/
[root@new-host-6 ~]# cd /mnt/lvm/
[root@new-host-6 lvm]# ll
total 13
drwxr-xr-x 4 root root 1024 Apr 10 20:17 boot
drwx------ 2 root root 12288 Apr 10 20:15 lost+found
[root@new-host-6 lvm]#

-動態放大VG,size+200M
[root@new-host-6 lvm]# vgextend rootvg /dev/hda7 /dev/hda8
Volume group "rootvg" successfully extended
驗證一下
[root@new-host-6 lvm]# vgdisplay
--- Volume group ---
VG Name rootvg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size 300.00 MB
PE Size 4.00 MB
Total PE 75
Alloc PE / Size 13 / 52.00 MB
Free PE / Size 62 / 248.00 MB
VG UUID 2XpLIi-L1Cp-IbbB-cJ38-id6b-U6Qh-K4j3Gu

-動態放大LV,size+50M
[root@new-host-6 lvm]# lvextend -L +50M /dev/rootvg/lv01
Rounding up size to full physical extent 52.00 MB
Extending logical volume lv01 to 104.00 MB
Logical volume lv01 successfully resized
驗證一下
[root@new-host-6 lvm]# lvdisplay
--- Logical volume ---
LV Name /dev/rootvg/lv01
VG Name rootvg
LV UUID zWA1PJ-iy4L-PZcG-NgNw-eSue-7xmP-Tw2HNs
LV Write Access read/write
LV Status available
# open 1
LV Size 104.00 MB
Current LE 26
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0
[root@new-host-6 lvm]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 5.7G 2.9G 2.6G 53% /
/dev/hda1 99M 9.8M 84M 11% /boot
tmpfs 125M 0 125M 0% /dev/shm
/dev/hda5 487M 11M 451M 3% /home
/dev/mapper/rootvg-lv01
51M 9.1M 39M 20% /mnt/lvm
此時因為還沒執行線上更新大小的動作,所以磁區大小還不會放大喔!
這裡跟RHEL4不同,改用resize2fs 來線上更新
[root@new-host-6 lvm]# resize2fs /dev/rootvg/lv01
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/rootvg/lv01 is mounted on /mnt/lvm; on-line resizing required
Performing an on-line resize of /dev/rootvg/lv01 to 106496 (1k) blocks.
The filesystem on /dev/rootvg/lv01 is now 106496 blocks long.

[root@new-host-6 lvm]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 5.7G 2.9G 2.6G 53% /
/dev/hda1 99M 9.8M 84M 11% /boot
tmpfs 125M 0 125M 0% /dev/shm
/dev/hda5 487M 11M 451M 3% /home
/dev/mapper/rootvg-lv01
101M 9.5M 87M 10% /mnt/lvm
[root@new-host-6 lvm]# cd /mnt/lvm/
[root@new-host-6 lvm]# ll
total 13
drwxr-xr-x 4 root root 1024 Apr 10 20:17 boot
drwx------ 2 root root 12288 Apr 10 20:15 lost+found
資料沒有遺失,磁區確成功放大了!

摘自:http://hi.baidu.com/yep0213/blog/item/42445eedb50bbcd72e2e215b.html

上面為完成文章,我想要在Xenserver中新增空間,我的完整做法如下(註:我新增了一顆HDD - hdb):

#fdisk -l
#fdisk /dev/hdb
The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n
First cylinder (908-1044, default 908):
Using default value 908
Last cylinder or +size or +sizeM or +sizeK (908-1044, default 1044): +100000M

Command (m for help): t
Partition number (1-8): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

#reboot

#lvextend -L +100G /dev/mapper/VolGroup00-LogVol00
#resize2fs /dev/VolGroup00/LogVol00
# sync;sync;sync;shutdown -r now

PS : Delete Physical / Logical Volumes
#lvremove /dev/VolGroup00/LogVol03


以下是我在原本10G的VM加入100G的步驟:
1.shutdown VM
2.Add Storage 100G
3.start VM
4.fdisk /dev/hdb

Command (m for help): n
First cylinder (934-1044, default 934):
Using default value 934
Last cylinder or +size or +sizeM or +sizeK (934-1044, default 1044): +100000M

Command (m for help): p #看cylinder狀況

Command (m for help): t
Partition number (1): 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!


5.sync;sync;sync;reboot
6.pvcreate /dev/hdb1
7.vgextend VolGroup00 /dev/hdb1
8.vgextend VolGroup00 /dev/hdb1
9.lvextend -L +99G /dev/mapper/VolGroup00-LogVol00
10.lvdisplay
11.resize2fs /dev/VolGroup00/LogVol00

完成~

[Debug] XenServer vgscan Couldn't find device with uuid

indigo:~# vgscan
Reading all physical volumes. This may take a while...
Couldn't find device with uuid 'p4YzIv-Ntiq-NxPo-J4tw-UDXF-4w4V-FiXqLl'.
Couldn't find all physical volumes for volume group storage.
Volume group "storage" not found

solve : vgreduce --removemissing vg00

XenServer - 新增儲存裝置 - 硬碟

基本上在 XenServer 要新增硬碟要用手動命令列的方式來進行,這裡的硬碟表示為本地端的硬碟,如系統上的 SATA 或是 SAS 的硬碟,而且還要重新開機從能完成. XenServer 採用的是 LVM 的方式來管裡硬碟空間,所以它可以很簡單的方式把硬碟空間放大縮小,LVM(Logical Volume Manager)是一種可以動態變更 partition 大小的方式,可以讓你能更容易利用管理你的硬碟.有興趣的可以參考 LVM-簡介 - http://benjr.tw/?q=node/55 不說廢話方法如下:
第一步:
關機後將新的硬碟加入到系統中,並設定好,確定在系統的 BIOS 可以正確無誤的看到你的硬碟.
第二步:
進入到 XenServer 並進入命令列模式 (Configuration / Local Command Shell) 並使用 Fdisk 確定可以看到你的硬碟

[root@benjr ~]# fdisk -l
Disk /dev/sda: 146.8 GB, 146814976000 bytes
255 heads, 63 sectors/track, 17849 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 499 4008186 83 Linux
/dev/sda2 500 998 4008217+ 83 Linux
/dev/sda3 999 17849 135355657+ 83 Linux
Disk /dev/sdb: 73.4 GB, 73407488000 bytes
255 heads, 63 sectors/track, 8924 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
/dev/sdb 將是我要新增的硬碟.
第三步:
產生 physical volume

[root@benhr ~]#pvcreate /dev/sdb
第四步:
將 XenSource volume group 加入新的硬碟:

[root@benjr ~]# vgextend VG_XenSource /dev/sdb
其中的 VG_XenSource 會不太一樣你可以透過 tab 鍵來直接完成他的全名.你也可以透過 vgscan 的指令來看 VG_XenSource 的全名.pvcreate 和 vgextend 是做什麼用的有興趣請參考. http://benjr.tw/?q=node/56
第五步:
重新開機吧!你會在 UI (Configuration / Disks and Storage Repositories / Current Storage Repositories / Local storage)看到硬碟空間變大了.

2009年12月18日 星期五

MySQL big5轉utf8編碼

mysqldump -uroot -p --default-character-set=latin1 nfspc >nfspc.sql
mysqldump -uroot -p --default-character-set=latin1 pigfather >pigfather.sql

piconv -f big5 -t utf8 nfspc.sql >nfspc_utf8.sql
piconv -f big5 -t utf8 pigfather.sql >pigfather_utf8.sql

vi nfspc_utf8.sql

SET NAMES utf8;
SET CHARACTER_SET_CLIENT=utf8;
SET CHARACTER_SET_RESULTS=utf8;

:1,$s/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8/g
:1,$s/latin1/utf8/gc
:1,$s/許\\/許/g
:1,$s/功\\/功/g
:1,$s/蓋\\/蓋/g
:1,$s/餐\\/餐/g
:1,$s/愧\\/愧/g
:1,$s/擺\\/擺/g
:1,$s/穀\\/穀/g
:1,$s/淚\\/淚/g
:1,$s/豹\\/豹/g
:1,$s/珮\\/珮/g


mysql -uroot -p nfspc < nfspc_utf8.sql
mysql -uroot -p pigfather < pigfather_utf8.sql

摘自:http://tw.myblog.yahoo.com/d89413125/article?mid=70&prev=74&next=62

SQL Join語法

SQL Join語法

Join有兩種屬性:
INNER
OUTER

1.INNER
只顯示匹配的行.

2.OUTER
不論是否匹配,都顯示行.
LEFT, RIGHT, FULL 都帶有OUTER屬性

Join共有六種:
Inner Join
Natural Join
Left Outer Join
Right Outer Join
Full Outer Join
Cross Join

1.Inner Join
Inner Join其實等同於多個Where條件式的連結,

FROM a, b WHERE a.id = b.id AND b.val > 5
FROM a INNER JOIN b ON (a.id = b.id) WHERE b.val > 5
是一樣的

2.Natural Join
Natural Join只是自動的匹配兩個表之間相同的欄位,

FROM a, b WHERE a.id = b.id AND b.val > 5
FROM a NATURAL JOIN b WHERE b.val > 5
是一樣的.
可用在任何一種Inner 或 Outer Join.
Natural 與 USING 也是很相像的,只是Natural
只會讓兩個表的相同欄位出現一次.

3.Left Outer Join
4.Right Outer Join
其實這兩個幾乎是一樣的,只是方向性的不同.
以Left Outer Join來說,左邊顯示所有左表的值,而右邊顯示右表匹配的值.
如果沒有匹配的右表表,則放空值.
Right Outer Join則左右方向相反.

5.Full Outer Join
左右表都顯示,匹配的則顯示,沒有匹配的放空值.
好比把 Left Outer Join 和 Right Outer Join作聯集.

6.Cross Join
交叉連結,會得到兩個表的所有乘積組合.

資料來源:http://www.wretch.cc/blog/sky4s/2250385

MySQL Tarball Source 安裝備忘

下載 MySQL 4.1.x Source (Compressed GNU TAR archive)

建立 mysql 帳號 (刻意讓 uid / gid 同 FC3 RPM 安裝)

groupadd -g 27 mysql
useradd -u 27 -g mysql -d /var/lib/mysql mysql

安裝 MySQL

tar zxf mysql-4.1.22.tar.gz
cd mysql-4.1.22
./configure --prefix=/usr/local/mysql
make && make install

cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql-log-rotate /etc/logrotate.d/mysql
cp support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql

初始化資料庫與系統環境

export PATH=$PATH:/usr/local/mysql/bin
mysql_install_db --user=mysql
cd /usr/local/mysql
chown -R root .
chown -R mysql var
chgrp -R mysql .

設置管理員帳號密碼 (首次啟動 MySQL)

Script 方式

/etc/init.d/mysql start
mysqladmin -u root password 'your_password'

停止 MySQL: /etc/init.d/mysql stop

手動方式

mysqld_safe --user=mysql &
mysqladmin -u root password 'your_password'

停止 MySQL: mysqladmin -u root -p shutdown

設定系統環境

設定 Log File
vi /etc/my.cnf

[safe_mysqld]
err-log = /usr/local/mysql/var/mysqld.log

設定 mysqladmin 參數檔
vi /root/.my.cnf

[mysqladmin]
password=your_password
user=root

加入路徑 (PATH)
vi ~/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
#source ~/.bash_profile

設定 shared library
vi /etc/ld.so.conf

/usr/local/mysql/lib/mysql

ldconfig

讓 Perl 支援 MySQL

cpan (或 perl -MCPAN -e shell)

install DBI::DBD

install DBD::mysql

若 DBD::mysql 安裝失敗

到 http://search.cpan.org 找 DBD::mysql, 下載 tarball source

perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config

make && make install


附錄: 其他備忘

mirror tips
rsync -a --compress --progress --bwlimit=10 root@master.host:/remote/path /local/path
MySQL Replication
每 5 分鐘執行 rsync 同步 /blog
mysqldump
mysqldump -u root -p db_name > dump_file.sql
mysql -u root -p -A db_name < dump_file.sql

摘自:http://cha.homeip.net/blog/archives/2007/09/mysql_tarball_s.html

Linux RHEL MySQL 5.1.41安裝教學

到http://dev.mysql.com/downloads/mysql/5.1.html下載
Source downloads -- Compressed GNU TAR archive (tar.gz)

shell> yum -y install gcc-c++
shell> yum -y install ncurses-devel

shell> tar -zxvf mysql-5.1.41.tar.gz
shell> cd mysql-5.1.41
shell> CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
-fno-exceptions -fno-rtti" ./configure \
--prefix=/usr/local/mysql --enable-assembler \
--with-mysqld-ldflags=-all-static --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all
shell> make
shell> make install

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip < mysql-VERSION.tar.gz | tar -xvf -
shell> cd mysql-VERSION
shell> ./configure --prefix=/usr/local/mysql
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql var
shell> bin/mysqld_safe --user=mysql &

shell> cp support-files/mysql.server /etc/init.d
shell> /etc/init.d
shell> chmod +x mysql.server
shell> /etc/init.d/mysql.server start|stop|restart

[Debug] MySQL Error

Q1.rpm 安裝 MySQL-5.0.77-0.src.rpm 失敗?

Error Meaage:

利用 rpm 指令來手動安裝 MySQL-5.0.77-0.src.rpm 失敗,並出現如下錯誤訊息。

# rpm -ivh MySQL-5.0.77-0.src.rpm
1:MySQL warning: user mysqldev does not exist - using root
warning: user mysqldev does not exist - using root
warning: user mysqldev does not exist - using root
########################################### [100%]
Ans:

代表目前用來安裝 MySQL-5.0.77-0.src.rpm 使用者為 root 機於安全性的考量,系統您建立一個用來安裝 mysql 的使用者帳號 (mysqldev),在新增 mysqldev 使用者之後便可順利執行 rpm 指令來安裝 MySQL-5.0.77-0.src.rpm。

#useradd mysqldev
#rpm -ivh MySQL-5.0.77-0.src.rpm
1:MySQL ########################################### [100%]
Q2.configure: error: no acceptable C compiler found in $PATH?

Error Meaage:

順利解開 MySQL-5.0.77-0.src.rpm 後執行 ./configure 指令來進行環境配置時失敗,並出現如下錯誤訊息。

#cd mysql-5.0.77
#./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking "character sets"... default: latin1, collation: latin1_swedish_ci; compiled in: latin1 latin1 utf8
checking whether to compile national Unicode collations... yes
checking whether build environment is sane... yes
checking whether make sets $(MAKE)... (cached) yes
checking for gawk... (cached) gawk
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/src/redhat/SOURCES/mysql-5.0.77':
configure: error: no acceptable C compiler found in $PATH //系統沒有安裝 gcc 套件 (無法編譯)
Ans:

原因在於目前系統並沒有安裝 gcc 套件所以進行環境設定 (./configure) 時並出現錯誤訊息,安裝好 gcc 套件後即可順利執行。

#yum -y install gcc-c++
Q3.checking for termcap functions library... configure: error: No curses/termcap library found?

Error Meaage:

順利解開 MySQL-5.0.77-0.src.rpm 後執行 ./configure 指令來進行環境配置時失敗,並出現如下錯誤訊息。

#cd mysql-5.0.77
#./configure
...略...
checking for termcap functions library... configure: error: No curses/termcap library found
Ans:

請使用如下參數來配合 ./configure 指令即可

./configure --with-named-curses-libs=/usr/lib/libncursesw.so.5
Q4.mysqladmin: connect to server at 'localhost' failed?

Error Meaage:

剛安裝好 MySQL 並啟動 MySQL 服務成功之後,使用 mysqladmin 設定 MySQL 管理者 (root) 密碼時失敗,並出現如下錯誤訊息。且也無法使用 mysql -u root -p 來登入 MySQL?

#mysqladmin -u root password 123456
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'
Ans:

請依如下步驟來重新設定 MySQL 管理者密碼 (也適用於密碼忘記時,前提是擁有主機系統管理權限),完成如下步驟後即可使用 mysql -u root -p 來登入 MySQL。

停止 MySQL 服務
#/etc/rc.d/init.d/mysql stop
Shutting down MySQL.. [ OK ]
執行指令 mysqld_safe 啟動 MySQL 服務於安全模式
#mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 28107
執行 mysql 指令來登入 MySQL
#mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.77-community MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
執行 UPDATE 指令重新設定 MySQL 管理者密碼為 123456
mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
執行 FLUSH 指令更新 MySQL 設定
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
執行 quit 指令離開 MySQL
mysql> quit
Bye
執行指令重新啟動 MySQL 服務
#/etc/rc.d/init.d/mysql restart
Shutting down MySQL.. [ OK ]
Starting MySQL [ OK ]
Q5.ERROR 1064 (42000) at line 1: You have an error in your SQL syntax near '嚜?

Error Meaage:

匯入 Dump Files 至指定的資料庫時失敗並出現如下錯誤訊息。

#mysql -u root -p databases_name < backup1.sql
Enter password:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '嚜?
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"' at line 1
使用 vi 來查看 backup1.sql 內容時為正常,若使用 less 指令來查看 backup1.sql 內容時則看到第一行有此字 嚜?

#less backup1.sql
嚜?- phpMyAdmin SQL Dump
-- version 2.11.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
...略...
Ans:

主因 MySQL 資料庫編碼格式設定為 [UTF-8] 但匯入的 backup1.sql 檔案編碼格式不是 [UTF-8] 所導致的。

[資安論壇 • 檢視主題 - 求助 ~ FC3 MySQL 3.x匯入到F7 MySQL 5.x字元集問題]

Q6.如何移除預設的 mysql-5.0.45-7.el5.i386?

Error Meaage:

CentOS 5.2 安裝時有勾選 KDE 及 Server 選項,但當嘗試要安裝 MySQL-server-community-5.0.82-0.rhel5.i386.rpm 時出現如下錯誤訊息

#rpm -ivh MySQL-server-community-5.0.82-0.rhel5.i386.rpm
error: Failed dependencies:
MySQL conflicts with mysql-5.0.45-7.el5.i386
系統顯示與目前的 mysql-5.0.45-7.el5.i386 產生衝突,嘗試使用 rpm -e 指令來移除它但出現如下錯誤訊息 (相依套件關系)

#rpm -e mysql-5.0.45-7.el5
error: Failed dependencies:
libmysqlclient.so.15 is needed by (installed) dovecot-1.0.7-2.el5.i386
libmysqlclient.so.15(libmysqlclient_15) is needed by (installed) dovecot-1.0.7-2.el5.i386
Ans:

由於有套件相依性的關系因此必須加上 --nodeps 參數來強制移除 mysql-5.0.45-7.el5,移除後即可順利安裝 MySQL-server-community-5.0.82-0.rhel5.i386.rpm

#rpm -e mysql-5.0.45-7.el5 --nodeps
#rpm -ivh MySQL-server-community-5.0.82-0.rhel5.i386.rpm
Preparing... ########################################### [100%]
1:MySQL-server-community ########################################### [100%]
Q7.error: cannot create %sourcedir /usr/src/redhat/SOURCES

Error Meaage:

安裝 MySQL-5.0.82-0.src.rpm 套件時出現如下錯誤訊息

#rpm -ivh MySQL-5.0.82-0.src.rpm
error: cannot create %sourcedir /usr/src/redhat/SOURCES
Ans:

此訊息為系統找不到該資料夾 (/usr/src/redhat/SOURCES) 或資料夾權限錯誤所引起,此次狀況為系統不存在該資料夾,因此建立該資料夾後即可順利安裝 src rpm.

#mkdir -p /usr/src/redhat/SOURCES
#rpm -ivh MySQL-5.0.82-0.src.rpm
1:MySQL ########################################### [100%]

摘自:http://www.weithenn.org/cgi-bin/wiki.pl?lighttpd_php_mysql-LAMP_%E6%9E%B6%E8%A8%AD

2009年12月17日 星期四

如何寫print.css ?

在html內連結css的時候要加上後面那句media的語法


自己另外建一個print.css的檔案
內容可以類似這樣:
body {color:#000000; background:#ffffff; font-family:"Times New Roman", Times, serif; font-size:12pt;}
a{text-decoration:underline; color:#0000ff;}
#left-box, #right-box, #top_text_ad {display:none;}
#main-box, #frm_apply, #content_index, #span_data{ overflow:visible; clear:both; display: block; }

display:none的部分,是把不要列印的部分給加進去
最後一行是顯示要顯示的東西,可以視情況加,也有不需要的時候
大致上body跟a都是一定要設定的,把背景設定白色,字設定黑色,讓人比較好列印
諸如此類的

2009年12月7日 星期一

vi 裡的中文字變亂碼!!

在 /etc/profile.local 加上
export LANG=en_US.UTF-8
登出再登入後,就搞定了。變成正常的中文字了~

wibiya widget