Showing posts with label MacOSX. Show all posts
Showing posts with label MacOSX. Show all posts

Friday, July 04, 2008

9.2.2. 识别符大小写敏感性[转自mysql5 中文手册]

在MySQL中,数据库对应数据目录中的目录。数据库中的每个表至少对应数据库目录中的一个文件(也可能是多个,取决于存储引擎)。因此,所使用操作系统的大小写敏感性决定了数据库名和表名的大小写敏感性。这说明在大多数Unix中数据库名和表名对大小写敏感,而在Windows中对大小写不敏感。一个显著的例外情况是Mac OS X,它基于Unix但使用默认文件系统类型(HFS+),对大小写不敏感。然而,Mac OS X也支持UFS卷,该卷对大小写敏感,就像Unix一样。

注释:尽管在某些平台中数据库名和表名对大小写不敏感,不应在同一查询中使用不同的大小写来引用给定的数据库或表。下面的查询不会工作,因为它同时引用了表my_tables和as MY_tables:

mysql> SELECT * FROM my_table WHERE MY_TABLE.col=1;
列、索引、存储子程序和触发器名在任何平台上对大小写不敏感,列的别名也不敏感。

默认情况,表别名在Unix中对大小写敏感,但在Windows或Mac OS X中对大小写不敏感。下面的查询在Unix中不会工作,因为它同时引用了别名a和A:

mysql> SELECT col_name FROM tbl_name AS a
-> WHERE a.col_name = 1 OR A.col_name = 2;
然而,该查询在Windows中是可以的。要想避免出现差别,最好采用一致的转换,例如总是用小写创建并引用数据库名和表名。在大多数移植和使用中建议使用该转换。

在MySQL中如何在硬盘上保存和使用表名和数据库名由lower-case-table-names系统变量确定,可以在启动mysqld时设置。lower-case-table-names可以采用下面的任一值:

0:
使用CREATE TABLE或CREATE DATABASE语句指定的大写和小写在硬盘上保存表名和数据库名。名称比较对大小写敏感。在Unix系统中的默认设置即如此。请注意如果在大小写不敏感的文件系统上用--lower-case-table-names=0强制设为0,并且使用不同的大小写访问MyISAM表名,会导致索引破坏。

1:
表名在硬盘上以小写保存,名称比较对大小写敏感。MySQL将所有表名转换为小写以便存储和查找。该行为也适合数据库名和表的别名。该值为Windows和Mac OS X系统中的默认值。

2:
表名和数据库名在硬盘上使用CREATE TABLE或CREATE DATABASE语句指定的大小写进行保存,但MySQL将它们转换为小写以便查找。名称比较对大小写敏感。注释:只在对大小写不敏感的文件系统上适用! InnoDB表名以小写保存,例如lower-case-table-names=1。

在Windows和Mac OS X中,lower-case-table-names的 默认值是1。

提示,手册中lower-case-table-names拼写有误,以此文为准。

Saturday, March 15, 2008

GeoIP libarary install for apache2 and ruby

1. Download the C API from http://www.maxmind.com/download/geoip/api/c/
2. Do the following to build and install GeoIP:
{{{
    ./configure
    make
    make check
    sudo make install
}}}
3. Download the ruby API from http://www.maxmind.com/download/geoip/api/ruby/
4. Do the following to build and install GeoIP ruby:
{{{
    ruby extconf.rb --with-geoip-include=/usr/local/include
    make
    sudo make install
}}}
5. Install mod_geoip
{{{
    sudo apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c
}}}
6. place
{{{
<IfModule mod_geoip.c>
    GeoIPEnable On
    GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat
LoadModule geoip_module /usr/lib/httpd/modules/mod_geoip.so
</IfModule>
}}}
inside your httpd.conf file.
If mod_geoip doesn't work, try taking the LoadModule geoip_module line outside the block.
If you get a "libGeoIP.so.1: cannot open shared object file: No such file or directory" error, add /usr/local/lib to /etc/ld.so.conf then run
/sbin/ldconfig /etc/ld.so.conf
7. mod_geoip can't install on Mac OSX because some unknown problem.
8. GeoIp ruby module install on Mac OSX is also some problem, but can install follow instruction of INSTALL
9. ruby example:


require 'net/geoip'

# access_type # Net::GeoIP::TYPE_DISK and Net::GeoIP::TYPE_RAM
#
g = Net::GeoIP.new(Net::GeoIP::TYPE_DISK)
# g = Net::GeoIP.open(db_filename[, access_type])


puts g.country_code_by_addr('220.181.37.55')
puts g.country_code_by_name('www.baidu.com')
puts g.country_code3_by_addr('220.181.37.55')
puts g.country_code3_by_name('www.baidu.com')
puts g.country_name_by_addr('220.181.37.55')
puts g.country_name_by_name('www.baidu.com')
puts g.country_id_by_addr('220.181.37.55')
puts g.country_id_by_name('www.baidu.com')
# >> CN
# >> CN
# >> CHN
# >> CHN
# >> China
# >> China
# >> 48
# >> 48

# puts g.region_by_addr('220.181.37.55') # Invalid database type GeoIP Country Edition, expected GeoIP Region Edition, Rev 1
# puts g.region_by_name('www.baidu.com') # Invalid database type GeoIP Country Edition, expected GeoIP Region Edition, Rev 1

# g.database_info() # Misc database info
# g.update_database(your_key_here[,debug]) # Updates your database

Reference:
1. http://www.maxmind.com/download/geoip/api/ruby/INSTALL
2. http://rubyforge.org/scm/?group_id=947
3. http://www.maxmind.com/app/ruby
4. http://www.howtoforge.com/mod-geoip-apache2-debian-etch
5. http://www.maxmind.com/app/mod_geoip

Saturday, August 25, 2007

Control Apache from System Preferences in OSX

Filed under Mac

Here’s a cool way to control Apache (other than the included version) on OSX. Apache will also auto start on boot using this method.

First, add this line to your httpd.conf file:

PidFile /private/var/run/httpd.pid

Now, open up Terminal and type the following:

cd /usr/sbin
mv apachectl apachectl_bak
ln -s /usr/local/apache2/bin/apachectl apachectl

Now you can go to System Preferences->Sharing and start or stop Personal Web Sharing. Enjoy!