Google
 
Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Tuesday, February 24, 2009

export mysql บาง field

เมื่อวานมีคำถามมาว่า
พี่ครับ ผมต้องการ export ข้อมูลบาง field โดยใช้ mysql command ได้รึเปล่า

ลองค้น อาจารย์ กูเกิ้ล ได้คำตอบประมาณนี้

select a,b from tableA into outfile '/tmp/filename.csv' FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

ปล. ใช้ข้อมูล เสร็จ อย่าลืมลบ /tmp/filename.csv นะน้อง ^^

Friday, November 14, 2008

เจอ Too many connections ทำงัยดี

เมื่อวานนี้ มีน้องมาปรึกษาว่า เว็บเซิร์ฟเวอร์ขึ้น error "Too many connections" แบบนี้

แก้ปัญหาโดยการเพิ่มจำนวน connection เข้าไป เนื่องจาก default ของ mysql จะกำหนดไว้ 100 connection (แหล่งอ้างอิง)

แก้ไขโดยเพิ่ม "set-variable=max_connections= n" ใน /etc/mysql/my.cnf โดยที่ n : คือจำนวน connection ที่เพิ่มขึ้น

จากนั้น restart mysql เป็นอันเสร็จ

Friday, September 14, 2007

แปลง timestamp

โจทย์ คือ pw_lastauth คือ timestamp นับจากปี 1/1/1970
เราใช้วิธีแปลง โดยใช้ from_unixtime ครอบ field นั้นอีกที

$query = "select field_A, from_unixtime(field_B_which_is_timestamp) as login_time from table_name where from_unixtime(field_B_which_is_timestamp) > '2006-12-31 23:59:59'";

เพียงเท่านี้ก็ได้เวลา ที่คนอย่างเราเข้าใจแล้ว

Sunday, September 9, 2007

สร้าง table

กรณีที่ต้องการสร้าง table ใหม่ โดยมีโครงสร้างเหมือน table เก่า

create table new_table as select * from old_table where field = 'ไม่เคย match';


การ import ไฟล์ เข้า database ใช้คำสั่งนี้

LOAD DATA INFILE 'path/file' INTO TABLE table_name FIELDS TERMINATED BY '|';


ขอบันทึกไว้กันลืม