หน้าเว็บ

แสดงบทความที่มีป้ายกำกับ mysql แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ mysql แสดงบทความทั้งหมด

วันพุธที่ 22 ตุลาคม พ.ศ. 2557

Mysql Connection utf8

ให้เพิ่ม useUnicode=true&characterEncoding=UTF-8 ต่อท้าย connection
URL= jdbc:mysql://127.0.0.1:3306/mydatabase?useUnicode=true&characterEncoding=UTF-8

วันจันทร์ที่ 24 กันยายน พ.ศ. 2555

create drop and grant user mysql linux command line

Create user
...
...
YourHost@Server:~$ mysql - u root -p
Enter password : 

...
mysql> create user 'redcrow'@'localhost' identified by 'redcrowpassword';
Query OK, 0 rows affected (0.00 sec)

//conect from any host will use '%'
//mysql> create user 'redcrow'@'%' identified by 'redcrowpassword';
//Query OK, 0 rows affected (0.00 sec)

mysql>
...
...
Drop user

วันจันทร์ที่ 5 มีนาคม พ.ศ. 2555

mysql search around [Haversine formula algorithm (finding locations nearby)]

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;

        เป็น algorithm ที่ใช้ในการค้นหาพิกัดตำแหน่ง GPS ที่อยู่ในรัศมีที่เรากำหนด  เช่นจากตัวอย่าง code ข้างบน  บอกว่าให้ค้นหา  id ที่อยู่รอบๆ GPS  37,-122(latitude,longitude)  ในรัศมี 25 ไมล์  มาจำนวน 20 คน 

3959 คือ รัศมีของโลกมีหน่วยเป็นไมล์
ถ้าจะใช้หน่วยเป็นกิโลเมตรในการค้นหา  ให้เปลี่ยนเป็น 6371  

วันเสาร์ที่ 7 มกราคม พ.ศ. 2555

ใช้งาน mysql ผ่าน terminal

ก่อนอื่นเราต้องติดตั้ง mysql-server  และ  mysql-client ก่อนด้วยคำสั่ง
$sudo apt-get install mysql-server mysql-client

        mysql-server คือฐานข้อมูล(database-server)ที่เราใช้สำหรับเก็บข้อมูล   ซึ่งตอนติดตั้งมันจะให้เราใส่ password  ของ user root  ลงไป  เราก็ใส่ไปแล้วก็จำไว้ด้วย 
        mysql-client คือโปรแกรมที่ใช้สำหรับเข้าถึง mysql-server  ผ่านทาง terminal


การเข้าใช้งานเราจะพิมพ์คำสั่ง
$mysql -u root -p
จากนั้นก็ให้เราพิมพ์  password  ของ user root(ของ mysql-server)  ลงไป  เช่น


หากต้องการออกจาก mysql  ก็ให้พิมพ์คำสั่ง exit ลงไป
mysql > exit