Database

记录一些关于数据库(MySQL)应用方面的信息。

Ubuntu安装MySQL

好久没写日志了,前段时间,域名没有备案,封掉了。

Ubuntu安装MySQL很方便,直接运行

sudo apt-get install mysql-server

就可以了。

但如果要MySQL能够外部访问的话,要做下修改。
登录MySQL

mysql -u root -p

授予需要外部访问的IP或者用户的权限

GRANT ALL PRIVILEGES ON *.* TO shishuo@'%' IDENTIFIED BY "shishuopassword"; 

其中 *.* 表示 数据库.表,你可以写为 shishuo.*
如:

GRANT ALL PRIVILEGES ON shishuodatabase.* TO shishuo@'%' IDENTIFIED BY "shishuopassword"; 

这条语句的意思就是,shishuo这个用户可以在任何IP下,用 shishuopassword 密码,访问shishuodatabase数据库,并具有对shishuodatabase的所有权限。

然后

vi /etc/mysql/my.cnf

修改
bind-address = 127.0.0.1

#bind-address = 127.0.0.1

重启

/etc/init.d/mysql restart

这样外部也能访问了。

Berkeley DB

Berkeley DB的资源链接:
  官方主页:http://www.oracle.com/database/berkeley-db/db/index.html
  产品下载:http://www.oracle.com/technology/software/products/berkeley-db/index.html
  官方开发者文档中心:http://www.oracle.com/technology/documentation/berkeley-db/db/index.html
  产品技术信息: http://www.oracle.com/technology/products/berkeley-db/pdf/berkeley-db-family-datasheet.pdf
  http://www.oracle.com/database/docs/berkeley-db-datasheet.pdf
  http://www.oracle.com/database/docs/Berkeley-DB-v-Relational.pdf

如果下载不了,可用国内的下载地址(http://download.linuxeden.com/DownSoft/?softid=1627)

SQL中Select语法

以下是摘自MySQL官方关于Select的语法,不过看上去有些复杂。
SELECT
    [ALL | DISTINCT | DISTINCTROW ]
      [HIGH_PRIORITY]
      [STRAIGHT_JOIN]
      [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
      [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr ...]
    [FROM table_references
    [WHERE where_condition]
    [GROUP BY {col_name | expr | position}
      [ASC | DESC], ... [WITH ROLLUP]]
    [HAVING where_condition]
    [ORDER BY {col_name | expr | position}
      [ASC | DESC], ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [PROCEDURE procedure_name(argument_list)]
    [INTO OUTFILE 'file_name' export_options
      | INTO DUMPFILE 'file_name'
      | INTO var_name [, var_name]]
    [FOR UPDATE | LOCK IN SHARE MODE]]

我做了些简化,如下
SELECT [DISTINCT] select_expr [, select_expr ...]
FROM table_references
WHERE where_condition
[GROUP BY {col_name | expr | position} [ASC | DESC]]
[HAVING where_condition]
[ORDER BY  {col_name | expr | position} [ASC | DESC]]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]

MySQL Install

shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db –user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe –user=mysql &

[译]MySQL的Set数据类型

原文地址:http://dev.mysql.com/tech-resources/articles/mysql-set-datatype.html

最近经常被使用的一个MySQL数据类型不得不算SET数据类型了,SET数据类型是一个String类型,但是由于其涉及复杂的增加,所以常常作为一个组合类型被提及到。在创建表的时候,一个SET类型可以存储指定的字符串的预定义列表中的任何数量的字符串。从SET数据类型与ENUM数据类型的预定义字符集工作方式来说,他们是相似的,但是ENUM数据类型限制你的预定义字符串集合中的一个成员,SET数据类型容许你存储多个预定义字符串,没有任何一个字符串,或者所有的字符串,都可以。

在MySQL的表里面,SET数据类型是作为一个Integer值被存储的。根据可利用元素的数量,SET数据类型将占用了0到8个字节。

MySQL的SET数据类型的要求

元素的个数 字节数
1 – 8 1
9 – 16 2
17 – 24 3
25 – 32 4
33 – 64 8

The SET elements are stored in the MySQL table as a bitmap: each element is represented by a single bit. To demonstrate this, lets look at the following sample table, which will be the basis for the rest of this tutorial. (NOTE: In the examples that follow, there are never whitespaces between elements and their comma seperators. Also note that only during the definition of a set are the elements individually wrapped in single quotes, otherwise the set as a whole gets only one set of quotes. Please do likewise.)

在MySQL的表里面,SET元素当作一个bitmap来存储的:每个元素都通过一个单一比特来代表。为了说明这个,让我们来看看下面的表。

单独增加主键和索引的SQL

ALTER TABLE user_relation_0 ADD INDEX `idx_user_relation` USING BTREE(`user_uuid_a`, `arefriends`);

ALTER TABLE user_relation_0 ADD CONSTRAINT  `pk_user_relation` PRIMARY KEY(`user_relation_uuid`);

MySQL的几条管理命令

CHECK TABLE `表名`     检查表
ANALYZE TABLE `表名` 分析表
REPAIR TABLE `表名`   修复表
OPTIMIZE TABLE `表名` 优化表
FLUSH TABLE `表名`     强制更新表
SHOW INDEX FROM `tbl_name`;

项目开发部署

1、下载开发工具
1> Eclipse
下载开发工具eclipse-jee-ganymede(
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/ganymede/SR2/eclipse-jee-ganymede-SR2-win32.zip)解压到 D:\Program Files\eclipse-ganymede

http://download.actuatechina.com/eclipse/technology/epp/downloads/release/ganymede/SR2/eclipse-jee-ganymede-SR2-win32.zip

选择workspace目录为D:\workspace

2> Resin

http://www.caucho.com/download/

http://www.caucho.com/download/resin-3.1.8.zip

3> nginx

http://nginx.net/

http://sysoev.ru/nginx/nginx-0.7.61.zip

4> mysql
Windows MSI Installer (x86)

http://www.mysql.com/

http://dev.mysql.com/downloads/mysql/5.0.html#win32

http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.0/mysql-5.0.83-win32.zip

http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQLGUITools/mysql-gui-tools-5.0-r17-win32.msi

5>memcached for win32

http://www.splinedancer.com/memcached-win32/

2、Eclipse插件下载地址
1> Hibernate Tools
#http://download.jboss.org/jbosstools/updates/development

http://download.jboss.org/jbosstools/updates/stable/

选择安装
#Tools Development Release和Hibernate Tools
FreeMarker IDE
Hibernate Tools

2> Spring IDE

http://springide.org/updatesite

3> SVN

http://subclipse.tigris.org/update_1.6.x

4> Javascript

http://download.macromedia.com/pub/labs/jseclipse/autoinstall/

以下是项目辅助的插件
5> checkstyle

http://eclipse-cs.sourceforge.net/update

6> findbug

http://findbugs.cs.umd.edu/eclipse