Leaderboard (728 x 90)

Monday, December 21, 2009

PEAR on Windows reports "Invalid configuration directive"

After running go-pear.bat to configure PEAR on a Windows Server you may encounter the PHP error dialog "Invalid configuration directive". To correct the issue, modify the file C:\Program Files (x86)\PHP\pear.bat. Scroll down to the :RUN section and modify the line with the PHP directive "-d include_path":

Prepend ".;" before "%PHP_PEAR_INSTALL_DIR%", and do not include the quotes. The section of line will read:

"... -d include_path=".;%PHP_PEAR_INSTALL_DIR%" -f "%PHP_PEA..."

Save the file and re-run the "pear" command.

Reference: http://kb.rackforce.com/?View=entry&EntryID=97

Sunday, December 20, 2009

How to change hostname in Linux

run these command

vi /etc/sysconfig/network

edit HOSTNAME parameter to your new hostname
ex: HOSTNAME=server1.example.com

save and restart network and xinetd service with this command
/etc/init.d/network restart
/etc/init.d/xinetd restart

run this command to change current system's hostname
hostname server1.example.com

edit file /etc/hosts following
127.0.0.1 server1.example.com server1

exit shell and re-login to check the result

Monday, December 7, 2009

Default Seach Provider corrupt in IE8

When you install IE7 or IE8 on winxp sp2 before upgrade windows to sp3, you will can't remove IE7/IE8 by Add and Remove Program.

If you upgrade IE7 to IE8 on winxp sp3, you may receive following error when you launch IE.
รูปภาพ

Resolution:

1. Click Start.
2. Click Run.
3. Type in regedit and press enter.
4. In the registry editor, expand and navigate to the following registry key: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders.
5. Right click User Shell Folders.
6. Select New and then Expandable String value.
7. A new value is added in right pane.
8. Type in AppData and press enter.
9. Double click AppData.
10. Under value data type in:

%USERPROFILE%\Application Data

11. Note: If there is already AppData in the right pane, double click and correct it to %USERPROFILE%\Application Data

If the above steps do not work,
1. Click Start.
2. Click Control Panel.
3. Click User Accounts.
4. Click Create a new user account.
5. Choose appropirate name for the new user account.
6. Choose Administrator or Limited or Standard user. It's upto you.
7. Click Create.
8. Click Start, Log out from the current user account and log back in with the new one.
9. If the new user account is working for you, obviously, the old user account has got corrupted and you will have to use the new user account. Also, FYI: you can transfer old user settings and files to the new user account.

Repair Internet Explorer 6

A number of XP users have reported situations with Internet Explorer 6 becoming corrupted and reporting a number of different errors. While there is certainly no guarantee, the two procedures listed below have restored functionality to IE6 for many users experiencing problems.

Note: Both methods listed require that the Microsoft Windows XP CD-ROM be available.

Method 1: Microsoft Internet Explorer 6.x Repair for Windows XP

  • From the Start menu, select Run.
  • In the Open field, type sfc /scannow (Note: There is a space between sfc and /scannow)
  • Select the OK button.
  • Follow the prompts throughout the System File Checker process.
  • Reboot the computer when System File Checker completes.

Method 2: Microsoft Internet Explorer 6.x Repair for Windows XP

  • From the Start menu, select Search, select All Files and Folders.
  • Select More Advanced Options and place a checkmark beside Search Hidden Files and Folders option.
  • Ensure that Search System Folders and Search Subfolders are also checked.
  • In the All or Part of the File Name box, type ie.inf
  • In the Look In drop-down menu, select C: or the letter of the hard drive that contains the Windows folder.
  • Click the Search button.
  • In the search results pane, find the ie.inf file located in Windows\Inf folder.
  • Right click the ie.inf file and click Install on the context menu.
  • Reboot the computer when the file copy process is complete.
Reference: http://www.theeldergeek.com/repair_ie6.htm

Friday, December 4, 2009

How to Truncate Log File in SQL Server 2005

Introduction

SQL Server 2005 is quite different from SQL Server 2000. To truncate log file is one thing which is different from SQL Server 2000. In SQL Server 2000, you just use Shrink to whatever file size you like. In SQL Server 2005, sometimes I cannot shrink the log file at all.

Here I want to describe some tricks to truncate log file for a database in SQL Server 2005. The work environment is Microsoft SQL Server Management Studio.

I. Shrink the Log File Size at the Right Time

I found out this trick:

Immediately after I use the SSIS package or Import the data to the database (highlight the database->Tasks->Import data …), or Export the data from the database (highlight the database->Tasks->Export data …), I can shrink the log file to the desired size, for example, 1MB. That is, highlight the database->Tasks->Shrink->Files , set the file size, say, 1MB.

Then, click OK and you are done.

II. Eliminate the Log File Completely

Sometimes, we just do not need the big log file. For example, I have a 40GB log file. I am sure I do not need this log file and want to get rid of it completely to free up the hard drive space. The logic is:

  1. Detach the database
  2. Rename the log file
  3. Attach the database without the log file
  4. Delete the log file

Let’s say, the database name is testDev. In the SQL Server Management Studio,

  1. Highlight the database-> Tasks->Detach..-> Click OK
  2. Go to log file folder -> rename the testDev_log.ldf to be like testDev_log-aa.ldf
  3. Highlight Databases->Attach…-> Click Add -> add the database testDev, highlight the log file and click the ‘Remove’ button. This means you only attach testDev.mdf
  4. After this is done, you can verify the contents of the attached database and then delete the log file

This way we can safely delete the log file and free up the space.

Reference Site: http://www.codeproject.com/KB/database/truncate_log_SQL_server.aspx

Thursday, December 3, 2009

How to clear log and shrink database in MSSQL with transaction-sql

run this command:

backup log databasename with no_log
backup log databasename with truncate_only
dbcc shrinkdatabase(databasename,1)

How to check all database size in MSSQL

run this command in Management Studio
# exec sp_databases

Sunday, November 29, 2009

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'tablename'

Symptom
Exception Details:
System.Data.SqlClient.SqlException: Invalid object name 'dbo.Events'.
Invalid object name 'dbo.Locations'.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location
of the exception can
be identified using the exception stack trace below.


Cause
Default schema is mismatch or no table with such name.


Solution
Change default schema for the login username to schema that is table schema.
Check table if exists.

Friday, November 20, 2009

คำสั่งใน sun solaris ที่ใช้แทนคำสั่ง yum หรือ apt-get

Instructions for Solaris package installation from Solaris Blastwave (CSW packages) site:

Run the following command for Solaris 10/Open Solaris (Intel and Sparc platforms)

pkgadd -d http://blastwave.network.com/csw/pkgutil_`/sbin/uname -p`.pkg

The above command will install CSWpkgutil package. This command can be used to install Solaris dependencies and indirect dependencies.

For example: The command below will install curl and its dependencies

# /opt/csw/bin/pkgutil --install curl

For more information about using pkgutil, click here

Tuesday, November 3, 2009

Limiting views on shared SQL server installations

For shared SQL Server installations, SSMS will allow all customers to see the names of other databases. You can change that default behavior with a SQL Server 2005 configuration change.

To do so, on your SQL 2005 servers, revoke "View Any Database" from public. Then, customers of a shared server, will only see their database, provided you've made the customer the owner of the database. An easy way to do this is with the stored procedure sp_changedbowner or with Alter Database.

Tuesday, October 27, 2009

ext4 filesystem

1. Introduction

Ext4 วิวัฒนาการมาจากระบบไฟล์ของลีนุกซ์ที่ได้รับความนิยมมากที่สุดก็คือ Ext3
Ext3 นั้นมีจุดเด่นก็คือระบบไฟล์แบบ Journaling ที่เพิ่มเข้าไปใน Ext2
แต่ Ext4 ได้ปรับปรุงแก้ไขส่วนสำคัญในเรื่องของโครงสร้างของระบบไฟล์ อย่างเช่น
ได้มีการกำหนดพื้นที่ที่เก็บข้อมูลไฟล์ไว้ล่วงหน้า ทำให้ระบบไฟล์มีการจัดสรรพื้นที่เก็บข้อมูลที่ดีขึ้น
ประสิทธิภาพมากขึ้นรวมทั้งความน่าเชื่อถือและคุณสมบัติที่ดีขึ้นอีกด้วย

Note :
1. Ext4 ถูกนำมาใช้ใน kernel 2.6.28
2. Journaling หมายถึง เมื่อข้อมูลในระบบเสียหาย ไม่ต้องมีการใช้คำสั่ง fsck
เพื่อตรวจสอบและซ่อมแซมแฟ้มข้อมูลนั้น เพราะว่าการทำงานของ journaling
นั้นจะมีการกู้แฟ้มข้อมูลที่เสียหายขึ้นมาให้โดยอัติโนมัติ


2. EXT4 features

2.1 Large file system/file sizes
Ext3 รองรับพื้นที่ได้มากสุด 16 TB และขนาดของไฟล์ใหญ่ที่สุด 2 TB
แต่ Ext4 ได้มีการเพิ่ม block address เป็นขนาด 48-bit
ทำให้สามารถรองรับพื้นที่ได้ถึง 1 EB (= 1,048,576 TB)และขนาดของไฟล์ใหญ่ที่สุด 16 TB

1 EB = 1024 PB
1 PB = 1024 TB
1 TB = 1024 GB

แล้วเขายังตั้งคำถามต่ออีกว่า ทำไมไม่เป็น 64bit หละ?
เขาบอกว่ามันมีข้อจำกัดอยู่ซึ่งถ้าเป็นขนาด 64 bit แล้วจะมี address บางส่วนหายไป
ซึ่งผมลองคำนวณดูว่า Ext4 ขนาด 64bit นี้จะพื้นที่มากถึง 74,000EB เลยที่เดียว

Note :
ขนาดของบล็อค(block size) ใน Ext4 เท่ากับ 4KB


2.2 Sub Directory
ใน Ext3 มีไดเรกทอรีย่อย 32,000 ไดเรกทอรีย่อย
แต่ใน Ext4 สามารถมีไดเรกทอรีย่อยได้ถึง 64,000 ไดเรกทอรีย่อย

Note :
ตรงนี้บางแหล่งอ้างอิงบอกว่ามีได้ถึง 640,000 หรือบางแหล่งบอกว่ามีได้ไม่จำกัด


2.3 Extents (การเขียนไฟล์แบบใหม่ใน Ext4)
Extents เป็นการเขียนไฟล์แบบใหม่ที่เพิ่มเข้ามาใน Ext4 แทนที่ block mapping ใน Ext3
ซึ่ง Extents จะมีการจองพื้นที่ที่อยู่ติดกัน ก่อนที่จะเขียนไฟล์
ทำให้ไฟล์ที่มีขนาดใหญ่มีประสิทธิภาพมากขึ้นและช่วยลดการกระจายของข้อมูล

2.4 Multiblock allocation
ใน Ext3 เวลาที่มีการเขียนไฟล์ก็จะมีการจัดสรรพื้นที่ทีละบล็อค (only allocates one block)
ในแต่ละครั้งที่เขียนลงไฟล์ ก็คือว่าถ้ามีการเขียนไฟล์ขนาด 100MB
ก็จะมีการจัดสรรบล็อคในการเขียนไฟล์ 25,600 ครั้ง (block size = 4KB)
แต่ใน Ext4 ใช้ "multiblock allocator" (mballoc) ซึ่งจะมีการจัดสรรบล็อกได้ทีละหลายๆบล็อค
ในการเรียกเขียนไฟล์ใน1ครั้ง

2.5 delayed allocation
ในระบบไฟล์แบบเก่าจะมีการการจัดสรรพื้นที่ของบล็อคโดยทันทีเพื่อให้ข้อมูลถูกเขียนลงดิสก์
แต่ในบางครั้งข้อมูลอาจจะถูกเก็บไว้ที่แคช (cache)
ไม่ได้ถูกเขียนลงดิสก์จริงๆ มันก็จะเสียเวลาไปกับการ จัดสรรพื้นที่ของบล็อคไป

ใน Ext4 ใช้เทคนิคที่เรียกว่า allocate-on-flush หรือที่รู้จักกันในชื่อ delayed allocation
ซึ่งวิธีของ delayed allocation นี้ ถ้าเกิดมีการเขียนไฟล์ขึ้นมามันจะยังไม่จัดสรรพื้นที่ของบล็อคที่จะเขียนโดยทันที
จนกว่าข้อมูลนั้นจะถูกเขียนลงดิสก์จริงๆ จึงจะมีการจัดสรรพื้นที่ของบล็อค

2.6 Faster file system checking (Fast fsck)
เพิ่มความเร็วในการตรวจสอบและซ่อมแซมแฟ้มข้อมูลของระบบไฟล์
เหมือนกับ Scandisk บน window

(ภาพจาก kerneltrap.org)

2.7 Compatibility
ในระบบไฟล์ Ext3 สามารถเปลี่ยนไปเป็น Ext4 ด้วยวิธีง่ายๆเพียงแค่ 2 คำสั่ง
คือ tune2fs และ fsck (จะกล่าวถึงในหัวข้อที่ 3.2) นั่นก็หมายความว่าเราสามารถเพิ่มประสิทธิภาพ
เรื่องข้อจำกัดของพื้นที่ในการเก็บข้อมูล และคุณสมบัติที่เพิ่มขึ้นในระบบไฟล์ของเรา
โดยไม่ต้อง reformatting และ/หรือ reinstalling โปรแกรมและระบบปฏิบัติการ

และเขายังบอกอีกว่า เราสามารถอัพเกรดระบบไฟล์โดยที่ไม่ต้องเสี่ยงกับข้อมูลที่สูญหาย
(แต่เขาวงเล็บไว้ว่า "เพื่อความแน่ใจก็ควรจะ backup ข้อมูลสำคัญๆไว้แม้ว่าจะไม่ได้อัพเกรดระบบไฟล์ก็ตาม")

ตรงนี้สำคัญ : เมื่อเราเปลี่ยนระบบไฟล์จาก Ext3 ไปเป็น Ext4 ด้วยวิธีข้างต้นนี้ ครั้งหนึ่งแล้ว
เราจะไม่สามารถเปลี่ยนระบบไฟล์กลับไปเป็น Ext3 ได้เนื่องจาก Ext4 มีโครงสร้างของระบบไฟล์แบบใหม่
ถ้าเราเปลี่ยนกลับไปเป็น Ext3 ระบบจะแจ้งเตือนว่า "wrong fs type"
(แต่เราสามารถเปลี่ยนระบบไฟล์กลับมาเป็น Ext3 ได้อีกครั้งหนึ่งด้วยวิธี mount จะกล่าวถึงในหัวข้อที่ 3.3)

2.8 Improved timestamps
แก้ปัญหา Year 2038 problem ด้วยการเพิ่มไปอีก 2 bit ที่ timestamp field
ทำให้ขยายเวลาไปอีกกว่า 500 ปี

(ภาพแสดงปัญหาปี 2038)

2.9 Persistent preallocation
คุณสมบัตินี้ผมขออธิบายง่ายๆด้วยการไปเปรียบเทียบกับบน window นะครับ
ก็คือให้นึกถึงเวลาที่เราโหลดบิต (P2P applications) แม้ว่าเราจะโหลดไฟล์ยังไม่เสร็จก็ตาม
สมมติว่าโหลดไป 20% แต่การจองพื้นที่สำหรับการเขียนไฟล์ก็จองไป 100%
ซึ่งตรงนี้เป็นการจองพื้นที่แบบถาวรแม้ว่าเราจะปิดเครื่องไปแล้วมาโหลดต่ออีกวันหนึ่งก็ตาม
ใน linux ก็เหมือนกันตรงนี้จะมาช่วยลดการกระจายของข้อมูล

2.10 Online defragmentation (คุณสมบัตินี้กำลังอยู่ในช่วงพัฒนาและจะมาเพิ่มในอนาคต)
ถึงจะมี delayed allocation, extents และ multiblock allocation มาช่วยในการลดกระจายของข้อมูล
แต่บางทีก็ยังเกิดการกระจายของข้อมูลได้อยู่ ตรงนี้เขาเปรียบเทียบให้ดูว่า
ถ้าเราเขียนไฟล์ขึ้นมา 3 ไฟล์ลงบนดิสก์ แล้ววันหนึ่งต่อมาเรามาแก้ไขไฟล์ที่อยู่ตรงกลาง
แต่การแก้ไขนี้มันไปเพิ่มขนาดหรือจำนวนบิต ทำให้พื้นที่ตรงนั้นไม่พอ ไฟล์ที่เราแก้ไขจึงต้องไปอยู่อีกที่หนึ่ง
ซึ่งไม่อยู่ติดกับที่เหลืออีก 2ไฟล์เดิม

เพื่อแก้ไขปัญหานี้ใน Ext4 จึงมี e4defrag tool
ซึ่งสามารถจัดระเบียบของข้อมูลเฉพาะของไฟล์นั้นๆ หรือทั้งระบบก็ได้

2.11 Inode-related features
  • Larger inodes : เพิ่มขนาดของ inode เป็น 256 bytes ( จากของเดิม 128 bytes ใน Ext3 )
    เพื่อรองรับการเก็บ timestamps แบบ Nanoseconds
  • Inode reservation : เพิ่มการจองให้ inode เมื่อมีการสร้าง Directory (คาดว่าจะมีใช้ในอนาคต)
    เมื่อมีการสร้างไฟล์ใหม่ขึ้นมาใน Directory ระบบก็จะสามารถใช้ inode ตรงส่วนที่ถูกจองไว้ได้เลย
  • Nanoseconds timestamps : ที่ inode fields ในส่วนของ modified time จะเก็บ timestamps
    ในหน่วย nanosecond แทนที่หน่วย second ใน Ext3

Inode จะเก็บรายละเอียดต่างๆของไฟล์ เช่น
• การแสดงสิทธิต่าง ๆ ของไฟล์
• การบอกถึงชนิดของไฟล์
• แสดงถึงเจ้าของและกลุ่มเจ้าของไฟล์
• วันเวลาที่สร้างไฟล์ เปลี่ยนแปลงไฟล์ หรือการเข้าถึงไฟล์ (access file)
• จำนวนการเชื่อมโยงของไฟล์เชื่อมโยง


3. How to use Ext4

3.1 Creating a new Ext4 filesystem

$ mkfs -t ext4 /dev/filesystem

Or

$ mkfs.ext4 /dev/filesystem


3.2 Migrate existing Ext3 filesystems to Ext4
ในการอัพเกรดระบบไฟล์จาก Ext3 ไปเป็น Ext4 เราใช้เพียง 2 คำสั่งคือ tune2fs and fsck
แล้วก่อนทำอย่าลืม umount filesystem ก่อนนะครับ

tonhor@ubuntu:~# tune2fs -O extents,uninit_bg,dir_index /dev/filesystem

tune2fs 1.41.4 (27-Jan-2009)
Please run e2fsck on the filesystem.


tonhor@ubuntu:~# fsck -pDf /dev/filesystem

fsck 1.41.4 (27-Jan-2009)
/dev/sdb1: Group descriptor 0 checksum is invalid. FIXED.
/dev/sdb1: Group descriptor 1 checksum is invalid. FIXED.
/dev/sdb1: Group descriptor 2 checksum is invalid. FIXED.
/dev/sdb1: Group descriptor 3 checksum is invalid. FIXED.
/dev/sdb1: Group descriptor 4 checksum is invalid. FIXED.
[..]


3.3 Mount an existing Ext3 filesystem with Ext4 without changing the format
ถ้าเราต้องการให้ระบบไฟล์ของเราเปลี่ยนจาก Ext3 เป็น Ext4 แล้วสามารถเปลี่ยนกลับมาเป็น Ext3 ได้อีก
เราสามารถใช้การ mount ระบบไฟล์ Ext3 เป็น Ext4 ได้

tonhor@ubuntu:~# mount -t ext4 /dev/filesystem /mnt/ext3


และเปลี่ยนระบบไฟล์กลับมาเป็น Ext3 อีกครั้งด้วยการ mount
tonhor@ubuntu:~# mount -t ext3 /dev/filesystem /mnt/ext3

ที่มา: http://tonhor.exteen.com/20090502/what-is-ext4-ext4

Tuesday, October 13, 2009

Ext3 – Reserved blocks percentage

Get back your missing unused disk space

According to tune2fs manual, reserved blocks are designed to keep your system from failing when you run out of space. Its reserves space for privileged processes such as daemons (like syslogd, for ex.) and other root level processes; also the reserved space can prevent the filesystem from fragmenting as it fills up. By default this is 5% regardless of the size of the partition.

On large partitions (250GB drives and up are quite common these days), the default 5% reserved space can be quite a lot (12.5Gb in my example). For ext3 partitions you can tune this parameter by using tune2fs with the parameter -m. For ex. to decrease this to 3% you would run (for ex. on /dev/sda1):
tune2fs -m 3 /dev/sda1
You should be very careful when ‘playing’ with this parameter and be sure you know what you are doing before changing this value.

ที่มา: http://www.ducea.com/2008/03/04/ext3-re ... ercentage/
ที่มา: http://ubuntuforums.org/archive/index.p ... 60160.html

Saturday, October 3, 2009

Free Antivirus จาก Microsoft

รายงานข่าวล่าสุด ไมโครซอฟท์ (Microsoft) ยืนยันว่า จะเริ่มเปิดให้ดาวน์โหลดฟรี!!! สำหรับซอฟต์แวร์ "แอนตี้ไวรัส" (เวอร์ชันสมบูรณ์) ของทางบริษัทภายในวันนี้ หลังจากที่ได้ออกเวอร์ชันทดสอบให้ลองใช้มาตั้งแต่เดือนมิถุนายนที่ผ่านมา

Microsoft Security Essentials เป็นซอฟต์แวร์แอนตี้ไวรัสของไมโครซอฟท์ที่เปิดให้ผู้ใช้สามารถดาวน์โหลดไป ใช้งานได้ฟรี โดยซอฟต์แวร์จะอัพเดตตัวเองแบบรายวัน (daily update) เพื่อให้คอมพิวเตอร์ของผู้ใช้ปลอดภัยจากมัลแวร์ใหม่ๆ ที่สามารถขโมยพาสเวิร์ด หรือเปลี่ยนพีซีของผู้ใช้ให้กลายเป็นเซิร์ฟเวอร์ส่งสแปมได้ทันท่วงที โดยไมโครซอฟท์ย้ำว่า มัน (MS Security Essentials) จะไม่ทำให้คอมพิวเตอร์ของคุณทำงานช้าลง

นอกจากนี้ไมโครซอฟท์ยังกล่าวอีกด้วยว่า การเปิดให้ดาวน์โหลดซอฟต์แวร์แอนตี้ไวรัสของทางบริษัทนั้น ไม่ได้มีเจตนาที่จะขโมยธุรกิจจากบริษัทต่างๆ อย่าง แมคอาฟี่ (McAfee) และไซแมนเทค (Symantec) ซึ่งเป็นบริษัทผู้ผลิตโปรแกรมแอนตี้ไวรัสที่ได้รับความนิยมสูงสุดในปัจจุบัน และมาพร้อมกับคุณสมบัติการทำงานทีมากกว่า โดยซอฟต์แวร์แอนตี้ไวรัสที่เปิดใหดาวน์โหลดฟรีนี้จะเหมาะกับเจ้าของเครื่อง คอมพิวเตอร์ที่ยังไม่ได้ติดตั้งแอนตี้ไวรัสไว้ภายในเครื่อง

(หมายเหตุ: ขณะรายงานข่าวทางเว็บไซต์ยังเปิดให้บริการดาวน์โหลดเวอร์ชันเบต้า และเปิดให้เฉพาะบางประเทศเท่านั้น)

ที่มา: http://www.arip.co.th/news.php?id=410048
แหล่งดาวน์โหลด: http://www.microsoft.com/Security_essentials/

Client does not support authentication protocol

ใน MySQL 4.1 ขึ้นไปนั้น ได้ใช้ hashing algorithm ในการเก็บ password เพื่อใช้ในการ Authentication Protocol แบบใหม่ซึ่งทำให้ยังไม่สนับสนุนใน PHP หรือ software client ใน version เก่าๆ (หรือใหม่ๆ บางตัวก็ยังไม่สนับสนุน) ถ้าคุณ upgrade ไปเป็น MySQL 4.1 หรือสูงกว่า การติดต่อเพื่อเข้าไปใช้งานนั้น จะขึ้นข้อความว่า

Client does not support authentication protocol requested by server; consider upgrading MySQL client.

สาเหตุ มาจากการที่ MySQL ได้ทำการปรับเปลี่ยนการเข้ารหัส password ใหม่อย่างที่ได้กล่าวไปแล้วโดย ถ้าใน MySQL version ก่อน 4.1 นั้นใช้การเข้ารหัสที่มีความยาว 16 bytes แต่ใน version ตั้งแต่ 4.1 ขึ้นมาถึงปัจจุบันนี้จะใช้การเข้ารหัสที่มีความยาว 41 bytes ซึ่ง client บางตัวยังไม่สนับสนุน password hashing algorithm แบบนี้ครับ ซึ่งการเข้ารหัส password ที่มีความยาว 41bytes นี้จะทำให้การถอดรหัสเพื่อทำการ hack ข้อมูลนั้นทำได้ยากขึ้นมากเลยทีเดียวครับ

โดยถ้าเราเปรียบเทียบจากตัวก่อนหน้า version 4.1 จะได้

mysql> SELECT PASSWORD(’mypass’);
+——————–+
| PASSWORD(’mypass’) |
+——————–+
| 6f8c114b58f2ce9e |
+——————–+

แต่ถ้าเราใช้คำสั่งเดียวกันใน version หลังจาก 4.1 จะได้

mysql> SELECT PASSWORD(’mypass’);
+———————————————–+
| PASSWORD(’mypass’) |
+———————————————–+
| *43c8aa34cdc98eddd3de1fe9a9c2c2a9f92bb2098d75 |
+———————————————–+

จะเห็นความแตกต่างของการเข้ารหัส password ของ MySQL ครับ

การแก้ไขปัญหานี้ทำได้โดยการ

* ทำการ upgrade ตัว client ที่ติดต่อกับ MySQL ให้เป็น version ที่สนับสนุน hashing algorithm ที่เก็บ password ใหม่ใน MySQL 4.1 ขึ้นไป (client ที่ว่านี้หมายถึง PHP MySQL Module, MySQL Front, PHPMyAdmin และตัวจัดการข้อมูลต่างๆ ที่เชื่อมต่อกับ MySQL ถือเป็น client ทั้งหมดครับ)
* เมื่อทำการติดต่อกับ server โดยใช้ pre-4.1 client program ให้ใช้บัญชี username ที่ใช้ pre-4.1-style password แทนการใช้ username ที่ใช้ style password แบบเก่า
* ทำการ Reset password ไปเป็น pre-4.1 style โดยใช้คำสั่ง SET PASSWORD และ OLD_PASSWORD() function โดยทำใน MySQL Command Line Client ซึ่งใช้คำสั่งดังนี้

mysql> SET PASSWORD FOR

-> ‘some_user‘@’some_host‘ = OLD_PASSWORD(’newpwd‘);

* some_host ให้เปลี่ยนเป็น hostname ที่ใช้เช่น localhost, 127.0.0.1, 192.168.0.1 หรือที่เป็น hostname นั้นๆ
* some_user ให้เปลี่ยนเป็น username ที่ใช้เช่น root, admin หรือ username อื่นๆ ที่ต้องการ
* newpwd ให้เป็นเป็น password ที่ใช้เช่น 1234, abcde หรือที่ต้องการ

ตัวอย่าง :

mysql> SET PASSWORD FOR

-> ‘root‘@’localhost‘ = OLD_PASSWORD(’1234‘);

คือกำหนด password ใหม่ให้กับ root ที่ localhost โดยใช้ hashing algorithm password แบบเก่าโดยกำหนด password คือ 1234

แล้วทำการ UPDATE และ FLUSH PRIVILEGES โดยใช้สั่ง

mysql> UPDATE mysql.user SET Password = OLD_PASSWORD(’newpwd‘)

-> WHERE Host = ‘some_host‘ AND User = ‘some_user‘;

mysql> FLUSH PRIVILEGES;

ตัวอย่าง :

mysql> UPDATE mysql.user SET Password = OLD_PASSWORD(’1234‘)

-> WHERE Host = ‘localhost‘ AND User = ‘root‘;

mysql> FLUSH PRIVILEGES;

* ด้วยวิธีด้านบนนี้เหมาะสำหรับใช้ในกรณีที่มี user ที่อยู่ในฐานข้อมูลน้อยๆ เท่านั้น มิเช่นนั้นแล้วอาจจะต้องเปลี่ยนกันมือหงิก -_-"

* ถ้ามี user ในฐานข้อมูลมากๆ และการปรับเปลี่ยนวิธีด้านบนทั้งหมดเป็นการยากในการทำระบบฐานข้อมูลกลับมา ใช้งานได้ปกติในเวลาอันสั้น เราสามารถบอกให้ MySQL ใช้ password hashing algorithm แบบเก่าตอน start-up service ได้เลย แต่แนะนำให้ใช้งานชั่วคราวเท่านั้นครับ และเมื่อมีเวลาให้ทำการปรับเปลี่ยนไปใช้ระบบ password hashing algorithm แบบใหม่แทน

โดยเริ่มการทำงานของ mysqld ด้วย –old-passwords ที่เป็น option command

ตัวอย่าง :

c:\MySQL\bin\mysqld –old-passwords


ที่มา: http://www.thaicyberpoint.com/ford/blog/id/101/

Thursday, October 1, 2009

ลืม password mysql จะสามารถกู้ข้อมูลได้อย่างไร

ขั้นตอนแรก
แก้ไขไฟล์คอนฟิก my.cnf หรือ my.ini โดยเพิ่มบรรทัดต่อไปนี้เข้าไปในส่วนของ [mysqld]
skip-grant-tables
แล้ว restart service mysql

ขั้นตอนที่สองให้พิมพ์คอมมานด์ต่อไปนี้
mysql -u root mysql


ขั้นตอนที่สามให้รัน statement ต่อไปนี้
update user set password=password('newpassword') where user='root';
flush privileges

ขั้นตอนที่สี่
แก้ไขไฟล์คอนฟิก my.cnf หรือ my.ini โดยเอาบรรทัดต่อไปนี้ออกจากส่วนของ [mysqld]
skip-grant-tables
แล้ว resert service mysql

เสร็จแล้วครับ
ลองทดสอบโดยคำสั่ง
mysql -u root -pnewpassword

Wednesday, September 30, 2009

เราจะสามารถทราบ root password ของ mysql ใน plesk ได้อย่างไร

ขึ้นอยู่กับชนิดของ database server ที่ใช้เก็บฐานข้อมูลของ plesk

============================================
กรณีที่เป็น Microsoft Access
============================================
Start >>Run ใส่ %plesk_dir%\admin\db\ แล้วกด Enter
เปิดไฟล์ psa.mdb ด้วยโปรแกรม Microsoft Access
============================================
กรณีที่เป็น Microsoft SQL Server
============================================
เปิดโปรแกรม Microsoft SQL Management Studio เพื่อเชื่อมต่อไปยัง Database Server แล้วเลือก database ที่ชื่อ psa
============================================
กรณีที่เป็น MySQL
============================================
ให้เปิด command prompt แล้วรันคอมมานด์
cd %plesk_dir%\Databases\MySQL\bin
mysql -P8306 -uadmin -p psa
============================================

จากนั้นให้เปิดดู table ที่ชื่อ DatabaseServers เพื่อดูข้อมูล admin ที่ใช้จัดการ database server

mysqldump ข้อมูลภาษาไทยเพี้ยน จะกู้กลับคืนมาได้อย่างไร

การใช้คำสั่ง mysqldump ข้อมูลภาษาไทยเพี้ยน จะ Import เข้าไปได้อย่างไร ในการแก้ปัญหาเรื่องภาษาไทยเพี้ยน จำเป็นต้องมีความรู้ความเข้าใจใน character set เป็นอย่างดีพอสมควร อ่านได้ที่ ความรู้เรื่อง mysql ตอน ปัญหาภาษาไทย กับ character set

ในบทความนี้ผมจะไม่กล่าวถึงเรื่องเกี่ยวกับ character set แต่จะกล่าวถึงวิธีการกู้ข้อมูลที่ผิดเพี้ยนไปนั้นกลับขึ้นมา

โดยก่อนอื่นให้ดูจากไฟล์ที่ dump ขึ้นมาว่ามีความผิดปกติในการเข้ารหัสข้อมูลภาษาไทยอย่างไรบ้าง

เช่น ถ้าตัวอักษรภาษาไทยกลายเป็นชุดอักษรสามตัวที่ขึ้นต้น ภหมายความว่ามีการเข้ารหัสด้วย utf8 แต่ถอดรหัสด้วย latin1

วิธีแก้ไข คือ
1. import ข้อมูลเดิมเข้าไปโดยไม่ต้องสนใจภาษาที่ผิดเพี้ยน
2. export อีกครั้งโดยเลือก default charset เป็น latin1 ด้วยคำสั่ง

mysqldump -u root -ppassword --default-character-set=latin1 --skip-set-charset -B dbname > dbname.sql

3. import ข้อมูลที่ export มาใหม่ โดยเลือก default charset เป็น utf8 ด้วยคำสั่ง

mysql -u root -ppassword --default-character-set=utf8 < dbname.sql

จะเห็นได้ว่า keyword ของการกู้ข้อมูลที่มีการเข้ารหัสผิดพลาด คือจะต้องทราบว่าข้อมูลผ่านการเข้ารหัสมาด้วย charset อะไรบ้าง นั่นเอง

เพื่อให้เข้าใจง่ายยิ่งขึ้น
ให้ นึกภาพข้อมูลที่รับส่งกันภายในคอมพิวเตอร์หรือระหว่างคอมพิวเตอร์ จะส่งกันเป็นข้อมูลไบนารี ดังนั้นเมื่อต้องการส่งข้อมูลที่เป็นตัวอักษรต่างๆ จะต้องมีการเข้ารหัสตัวอักษรให้เป็นตัวเลขฐานสองหรือข้อมูลไบนารีก่อน จากนั้นจึงส่งไปยังปลายทาง จากนั้นเมื่อผู้รับได้รับข้อมูลที่เป็นไบนารี จึงถอดรหัสข้อมูลไบนารีเป็นข้อมูลตัวอักษรอีกที

ดูตารางการเข้ารหัสสำหรับ UTF8
ดูตารางการเข้ารหัสสำหรับ TIS620
ดูตารางการเข้ารหัสสำหรับ LATIN1

จะ เห็นว่า ตัวอักษร ก เมื่อเข้ารหัสด้วย utf8 จะได้ข้อมูล 3 ไบต์ คือ 0xe0 0xb8 0x81 (เลขฐานสิบหก) จากนั้นเมื่อนำมาถอดรหัสด้วย latin1 จะได้ e0=à b8=¸ 81=ไม่มีค่า เป็นต้น

บทความที่เกี่ยวข้อง
mysqldump ข้อมูลภาษาไทยเพี้ยน จะกู้กลับคืนมาได้อย่างไร
ความรู้เรื่อง mysql ตอน ปัญหาภาษาไทย กับ character set
mysql: เมื่อภาษาไทยกลายเป็น ?????????

การ dump ข้อมูลใน MySQL ให้ถูกต้องตาม Character-set

สำหรับบันทึกนี้ขอกล่าวถึงเคล็ดลับในการแปลงฐานข้อมูลจากเดิมที่เป็น latin1 หรือ tis620 ให้เป็น utf8 นะครับ

มี เงื่อนไขเบื้องต้นว่า หาก character-set ของฐานข้อมูลเป็น tis620 หรือ latin1 (ความจริงเป็น tis620 ครับ เพราะ latin1 ไม่ใช่ character-set ของภาษาไทย) ต้องไม่กำหนดค่า

default-character-set=utf8

ใน my.cnf (สำหรับ Linux อยู่ที่ /etc/my.cnf หรือ /etc/mysql/my.cnf)

หลาย คนอาจจะชินกับการใช้ phpMyAdmin หากใช้แล้วไม่มีปัญหาก็ใช้ต่อไปครับ โดยปกติ เวลาจะ dump ข้อมูลโดยใช้ phpMyAdmin ก็ใช้วิธี export ออกมาเป็น SQL จะดีที่สุด วิธีที่จะดูว่า มีปัญหาหรือไม่ ก็คือ ลองเปิดไฟล์ที่ Export ออกมานั้นด้วย Text Editor ดู หรือใช้ command อื่นๆ เปิดดูก็ได้ครับ หากสามารถอ่านออกเป็นภาษาไทยได้ ก็แสดงว่า ไม่มีปัญหาครับ

ใน ที่นี้อยากแนะให้ใช้คำสั่ง mysqldump ซึ่งเป็น command line tool ที่นิยมใช้ใน Linux ครับ เข้าใจว่า ใน MS WIndows ก็มีเหมือนกัน วิธีใช้ก็ไม่น่าจะต่างกันมากครับ

ในการ dump ข้อมูล สิ่งที่ต้องทราบคือ character-set ของข้อมูลคือ อะไร ส่วนใหญ่จะไม่หนีจาก 3 ตัวนี้ครับ คือ latin1, tis620 และ utf8

หากไม่ทราบ ก็ลองด้วยการกำหนด character-set ไปเรื่อยๆ

วิธีการใช้คำสั่งก็ คือ

mysqldump --default-character-set=latin1 -h MySQLserver -u username -p DBName >DBName.sql

ตัว สีแดงคือ ค่าที่ต้องกำหนดให้ถูกต้องครับ หากเครื่องที่ทำการเรียกคำสั่ง mysqldump เป็นเครื่องเดียวกับ MySQL Server ก็ไม่ต้องมี "-h MySQLserver" ก็ได้ครับ

username คือ ชื่อ user ที่มีสิทธิ์ในการ access ฐานข้อมูล DBName

หาก โปรแกรมจัดการฐานข้อมูลที่ใช้อยู่แสดงผลเป็น character-set 8 bits (พวก tis-620, windows-874, iso-8859-11) การกำหนด --default-character-set=latin1 มักจะไม่มีปัญหาครับ ซึ่งหมายถึงอ่านออกเป็นภาษาที่ถูกต้องแน่นอนครับ

แต่สิ่งที่ต้องทราบต่อไปก็คือ ภาษาไทยที่แสดงนั้น มี character-set ที่แท้จริงเป็น tis620 ครับ ไม่ใช่ latin1 ครับ

หากเปิดไฟล์ DBName.sql ดู จะพบว่า ที่หัวไฟล์มีหลายบรรทัดเป็น

-- MySQL dump 10.9
--
-- Host: localhost Database: moodle
-- ------------------------------------------------------
-- Server version 4.1.20

ส่วน 5 บรรทัดข้างบนนี้ เป็น comment จะไม่สนใจก็ได้ครับ

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES latin1 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 *
/;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

หลาย บรรทัดเหล่านี้ดูเหมือนจะเป็น comment แต่ไม่ใช่ครับ มันมีความหมายครับ เช่น 40101 หมายถึง MySQL รุ่น 4.1.1 และ 40014 หมายถึง MySQL รุ่น 4.0.14 และในแต่ละบรรทัดก็มีความหมายว่า หากเป็น MySQL รุ่นเท่ากับหรือสูงกว่าที่บอกไว้ต้นบรรทัด ก็จะ run คำสั่งที่ตามมา เช่น

/*!40101 SET NAMES latin1 */; ก็หมายถึง หากเรา import ข้อมูล DBName.sql เข้า MySQL Server รุ่นที่เท่ากับหรือสูงกว่า 4.1.1 ก็จะมีการสั่งให้ SET NAMES latin1 ซึ่งหมายถึงการตั้งค่าการสื่อสารข้อมูลด้วย character-set lantin1 แต่ถ้าเป็นการ import ข้อมูลเข้า MySQL Server รุ่นที่ต่ำกว่า 4.1.1 บรรทัดนั้นก็จะถูกข้ามไปครับ

สิ่งที่สำคัญในที่นี้ก็คือ การกำหนดให้เป็น latin1 ในที่นี้ อาจจะทำให้ import ข้อมูลผิดพลาด หากไม่แน่ใจก็ให้ลบบรรทัดนี้ทิ้งไป

ส่วนที่จะเป็นปัญหาต่อมา คือ ในส่วนของไฟล์ที่เกี่ยวกับการสร้างตาราง เช่น

CREATE TABLE `mdl_assignment` (
`id` int(10) unsigned NOT NULL auto_increment,
`course` int(10) unsigned NOT NULL default '0',
`description` text NOT NULL,
`format` tinyint(2) unsigned NOT NULL default '0',
`resubmit` tinyint(2) unsigned NOT NULL default '0',
`type` int(10) unsigned NOT NULL default '1',
`maxbytes` int(10) unsigned NOT NULL default '100000',
`timedue` int(10) unsigned NOT NULL default '0',
`grade` int(10) NOT NULL default '0',
`timemodified` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `course` (`course`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

ให้สังเกตที่บรรทัดสุดท้ายครับ ตรงนี้ ให้ทำการลบ DEFAULT CHARSET=latin1 ออกให้หมด

ตรวจสอบไฟล์ให้แน่ใจว่า สามารถอ่านได้เป็นปกติ โดยที่เป็น tis-620

ขั้นตอนต่อมา คือ การ import ข้อมูลเข้า MySQL Server ที่กำหนด default-character-set=utf8 ใน my.cnf แล้ว

โดยปกติ ก็ใช้คำสั่ง

mysql --default-character-set=tis620 -h MySQLserver -u username -p DBName < DBName.sql

สังเกต ว่า การกำหนด --default-character-set=tis620 ในคำสั่งนี้ ต้องระบบ character-set ของไฟล์ให้ตรงกัน โดยไม่จำเป็นต้องแปลงไฟล์ให้เป็น utf8 ครับ เพราะ MySQL Server จะทำการแปลงให้เอง

สิ่งสำคัญต่อไป ก็คือ โปรแกรมที่ใช้จัดการฐานข้อมูลครับ ต้องใช้ character-set เหมือนกับของฐานข้อมูลเท่านั้นครับ และก็มีเคล็ดลับอีกเล็กน้อย ซึ่งจะได้กล่าวในบันทึกอื่นต่อไปครับ

ที่มา: http://share.psu.ac.th/blog/myopensource/5425

Tuesday, September 29, 2009

ติดตั้ง ASP.NET 32 bit ใน Windows 64 bit อย่างไร

ในการติดตั้งซอฟต์แวร์บางตัว เช่น Report Service ของ SQL Server 2005 32 bit จะต้องทำงานร่วมกับ ASP.NET 2.0 32 bit เท่านั้น หรือ
ใน กรณีทีต้องการติดตั้ง ASP.NET 1.1 บน Windows 64 bit จะเกิดปัญหา คือไม่สามารถทำงานได้ถูกต้อง เพราะ ASP.NET 1.1 จะทำงานได้เฉพาะบนโหมด 32 bit เท่านั้น

โดยปกติ IIS 6.0 บน Windows 64 bit จะทำงานรองรับทั้งโหมด 32 bit และ 64 bit แต่จะทำงานได้แค่โหมดใดโหมดหนึ่งเท่านั้น ซึ่งโดยค่าตั้งต้นจะทำงานในโหมด 64 bit

เช่นเดียวกันกับ ASP.NET 2.0 ซึ่งสามารถทำงานได้ทั้งในโหมด 32 bit และ 64 bit แต่จะทำงานได้ในโหมดใดโหมดหนึ่งเท่านั้น

แต่ ASP.NET 1.1 จะทำงานได้เฉพาะบนโหมด 32 bit เท่านั้น

คำ ถามก็คือ ในกรณีที่ต้องการติดตั้งใช้งาน ASP.NET 1.1 ร่วมกับ ASP.NET 2.0 พร้อมกัน จะสามารถทำได้อย่างไร หรือในกรณีที่ต้องการติดตั้ง Report Service ของ SQL Server 2005 32 bit บน Windows 64 bit จะสามารถทำได้อย่างไร คำตอบก็ชัดเจนครับ นั่นก็คือ ต้องเปลี่ยนโหมดของ IIS และ ASP.NET 2.0 ไปทำงานในโหมด 32 บิต ครับ

ขั้นตอนการสลับโหมดการทำงานของ IIS 6.0 บน Windows 64 bit
คลิกที่ Start คลิก Run พิมพ์ cmd แล้วคลิก OK
ถ้าต้องเปิดใช้งาน IIS 6.0 โหมด 32 bit ให้พิมพ์คำสั่งต่อไปนี้:
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1
ถ้าต้องเปิดใช้งาน IIS 6.0 โหมด 64 bit ให้พิมพ์คำสั่งต่อไปนี้:
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 0

ขั้นตอนการสลับโหมดการทำงานของ ASP.NET 2.0
คลิกที่ Start คลิก Run พิมพ์ cmd แล้วคลิก OK

ถ้าต้องการติดตั้ง ASP.NET 2.0 โหมด 32 bit ให้พิมพ์คำสั่งต่อไปนี้
%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i
ไปที่ Control Panel >> Administrative Tools >> Internet Information Services Manager
ในรายการ Web Service Extensions ให้ตรวจสอบว่าสถานะของ ASP.NET v.2.0.50727 (32 bit) มีค่าเป็น Allowed หรือไม่ ถ้าไม่ ให้เปลี่ยน สถานะเป็น Allowed

ถ้าต้องการติดตั้ง ASP.NET 2.0 โหมด 64 bit ให้พิมพ์คำสั่งต่อไปนี้
%SYSTEMROOT%\Microsoft.NET\Framework64\v2.0.50727\aspnet_regiis.exe -i
ไปที่ Control Panel >> Administrative Tools >> Internet Information Services Manager
ในรายการ Web Service Extensions ให้ตรวจสอบว่าสถานะของ ASP.NET v.2.0.50727 มีค่าเป็น Allowed หรือไม่ ถ้าไม่ ให้เปลี่ยน สถานะเป็น Allowed