顯示包含「MYSQL」標籤的文章。顯示所有文章
顯示包含「MYSQL」標籤的文章。顯示所有文章

2011/05/20

[ mysql ] Convert timestamp to date

SELECT FROM_UNIXTIME


mysql> SELECT FROM_UNIXTIME(1196440219)

-> '2007-11-30 10:30:19'

2011/02/28

Combine use of "group_concat" and "having" inside "group by"

select count(*),sum(sale_price),REPLACE(group_concat(sales_id),',','<br/>') from ebay_sold
group by sale_date
having sum(sale_price) >100

Cannot connect to MYSQL externally via software

An example of how to add SELECT privileges to a user using GRANT

GRANT SELECT ON db_base.* TO db_user@'localhost' IDENTIFIED BY 'db_passwd';
If SELECT is not enough for our user we can add more privileges using a query similar to the one below:


An example of how to add a selection of privileges to a user using GRANT

GRANT SELECT, INSERT, DELETE ON db_base.* TO db_user@'localhost' IDENTIFIED BY 'db_passwd';
If you want to GRANT ALL the privileges to a user then use this query:
An example of how to Grant Privileges in MySQL

GRANT ALL PRIVILEGES ON db_base.* TO db_user @'%' IDENTIFIED BY 'db_passwd';
As you see in the latest example we use '%' instead of localhost, which means that our user can use all the privileges from every host.


Sometimes you need to grant privileges to a user for a specific table. To specify the table, replace '*' in 'db_base.*' with your table's name.

An example of how to Grant Privileges in MySQL

GRANT ALL PRIVILEGES ON db_base.phonebook TO db_user @'%' IDENTIFIED BY 'db_passwd';
Once you have given the desired privileges for your user, you will need to FLUSH privileges in order to complete the setup and to make the new settings work. To do so, run this command within the SQL command prompt:

FLUSH PRIVILEGES;