MySQL MySQL UNIX时间戳到可读日期

//For example
SELECT users.name, pnts.points, FROM_UNIXTIME(pnts.time_stamp,'%Y %D %M %h:%i:%s') AS date, pnts.description, pnts.reference, pnts.operation, users.mail
FROM userpoints_txn pnts
LEFT JOIN users users ON users.uid = pnts.uid
WHERE 1

MySQL Mysql从select中多次插入

INSERT INTO table (field1, field1)( SELECT field1, field2 FROM table)

MySQL 在phpmyadmin中修复不可修复的MySql表

repair table tablename use_frm;

MySQL 更改自动增量

ALTER TABLE tbl AUTO_INCREMENT = 1000;

MySQL 按rand()减少时间

Original Query 

$totalrows = 10;

$sql = "SELECT 
 posts.Tags as tags, 
 posts.OwnerUserId as postsid, 
 posts.Id as postid, 
 posts.Body as body, 
 posts.Title as title, 
 users.Id as userid, 
 users.DisplayName as usersname  
FROM posts 
JOIN users ON posts.OwnerUserId = users.Id 
WHERE posts.Title != '' order by rand() asc limit " .  $totalrows;

$r = mysql_query($sql) or die(mysql_error());



Modified Version

$totalrows = 10;

$sql = "SELECT 
 posts.Tags as tags, 
 posts.OwnerUserId as postsid, 
 posts.Id as postid, 
 posts.Body as body, 
 posts.Title as title, 
 users.Id as userid, 
 users.DisplayName as usersname  
FROM posts 
JOIN users ON posts.OwnerUserId = users.Id 
JOIN (select posts.id from posts where posts.title != '' order by rand() asc limit " . $totalrows .") AS tmp_result
ON (posts.Id = tmp_result.Id)";


$r = mysql_query($sql) or die(mysql_error());

MySQL 从另一个现有表中的选择创建新表(包括复制数据结构)

create table NEW_TABLE_NAME select * from EXISTING_TABLE where SOME_VAILD_WHERE_CLAUSE

MySQL 安装mysql centos

yum install mysql
yum install mysql-server

MySQL 从详细统计数据迁移到每小时统计数据

insert into sitestats_rollup(hitdatetime,hitid,hitcount) select date_format(hitDate, "%Y-%m-%d %h:00:00"), hitKey, count(*) from sitestats group by 1,2 on duplicate key update hitcount=hitcount+1;

MySQL 来自命令行的MySQL

mysql
SHOW DATABASES;
mysql -u root -p 
SET PASSWORD FOR root@localhost=PASSWORD('#PasswordHere#');
FLUSH PRIVILEGES;
CREATE DATABASE #NAME#;
DROP DATABASE #NAME#;

<!-- Granting user privileges -->
GRANT ALL PRIVILEGES ON #databaseName#.*
TO 'username'@'localhost'
IDENTIFIED BY '#userpassword';
SHOW GRANTS FOR '#username#'@'localhost'

mysql -u #UserName# -p #databaseName#
SHOW TABLES;

MySQL WordPress:修复UTF-8问题

Follow these steps:
http://codex.wordpress.org/Converting_Database_Character_Sets
(see "Performing the actual conversion on your live database" section)

Then install this plugin:
UTF8 Sanitize (http://wordpress.org/extend/plugins/wp-utf8-sanitize/)
(fixes UTF8 encoding in titles).