หน้าเว็บ

Thursday, February 19, 2015

MySQL DATEDIFF() หาผลต่างระหว่างวันที่

SELECT DATEDIFF('2008-11-30','2008-11-29') AS DiffDate

ผลลัพธ์ที่ได้ = 1

Find duplicate records in MySQL - หาเรคคอร์ดที่ซ้ำกันใน MySQL

Find duplicate records in MySQL

Do a SELECT with a GROUP BY clause. Let's say name is the column you want to find duplicates in:

SELECT name, COUNT(*) c FROM table GROUP BY name HAVING c > 1;

This will return a result with the name value in the first column, and a count of how many times that value appears in the second.

Credit : http://stackoverflow.com/questions/688549/finding-duplicate-values-in-mysql

Wednesday, February 18, 2015

MySQL - Adding User Accounts And Grant all privileges

Adding User Accounts
 mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
    ->     WITH GRANT OPTION;
mysql> CREATE USER 'admin'@'localhost';
mysql> GRANT RELOAD,PROCESS ON *.* TO 'admin'@'localhost';
mysql> CREATE USER 'dummy'@'localhost';
-------------------------------------------------------------------------------------------------------------

grant all privileges on database_name.* to username@localhost identified by'password';
flush privileges;
* คำสั่ง flush privileges คือการสั่งให้ MySQL update ข้อมูลใหม่ที่เราเพิ่ง update เข้าไป

ถ้าอยากให้connectจากที่อื่นได้เปลี่ยนจาก localhostเป็น%ก็จะได้เป็นusername@'%'
grant all privileges on username.* to dbname@'%' identified by 'password';

แล้วก็ถ้าสมมติว่าจะเอาuserนี้ออกไม่ให้ connectdatabase
revoke all on database_name.* from username@localhost;



Credit : http://nuxfixer.blogspot.com/search/label/MySQL