Archives by Tag 'MySQL'

Gentoo+Nginx+PHP(php-fpm)+MySQL+xcache

By Symphony - Last updated: Sunday, April 3, 2011

要使nginx和php协同工作,nginx需要加入fastcgi这个use,要使用fpm,php需要加入fpm这个use。 echo "www-servers/nginx fastcgi" >> /etc/package.use echo "dev-lang/php fpm mysqli mysql pcntl pdo postgres soap sockets sqlite3 truetype zip" >> /etc/package.use 安装 time emerge -av nginx php 安装过程大概需要持续半个小时。。。 完成后编辑 /etc/nginx/nginx.conf,加入高亮部分。 server { listen 127.0.0.1; server_name localhost; access_log /var/log/nginx/localhost.access_log main; error_log /var/log/nginx/localhost.error_log info; root /var/www/localhost/htdocs; location ~ .php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi.conf; } } 重启nginx和php-fpm即可。 [...]

mysql项目实践知识汇总(本文长期更新)

By Symphony - Last updated: Monday, May 10, 2010

1、如果记录存在,则执行update,否则,插入一条新纪录: INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1; 这里假设a为主键或者唯一索引,当a已存在时,则执行update部分,否则执行insert部分。ps. 要执行此语句必须有字段是主键或者唯一索引。 2、读写分离。对许多网站,读操作都远大于写,据说ebay读写比例高达265:1,而且还在不断增长。很多这样的网站都使用一种读写分离的方法来优化数据库。 读写分离的好处: 针对write db和read db进行配置,比如:a. read db设为读优先,写进程比如等待所有读进程完成才能写入。b. read db做索引,write db不做索引。做索引是利用写开销来换取读开销。 服务器资源配置最优化。 批量写入,减少数据库连接。 配合mysql proxy连接池功能,解决连接数超限的问题。平均分摊连接数。 读写分离的实现: 为了向请求端屏蔽db实现的复杂度,避免增减db服务器时修改请求端代码,可以在请求端和db集群间添加一个中间件:mysql proxy 来进行db请求的调度,从而在请求端完全屏蔽db实现的复杂度。 使用mysql proxy作为连接池,利用lua脚本将请求自动分发给write/read db。 3、系统变量concurrent_insert。MyISAM存储引擎有一个系统变量concurrent_insert,专门用以控制其并发插入的行为,其值分别可以为0、1或2。 0 不允许并发操作 1 如果MyISAM表中没有空洞(即表的中间没有被删除的行),MyISAM允许在一个进程读表的同时,另一个进程从表尾插入记录。这也是MySQL的默认设置。 2 无论MyISAM表中有没有空洞,都允许在表尾并发插入记录 4、调节MyISAM的调度行为。 通过指定启动参数low-priority-updates,使MyISAM引擎默认给予读请求以优先的权利。 通过执行命令SET LOW_PRIORITY_UPDATES=1,使该连接发出的更新请求优先级降低。 通过指定INSERT、UPDATE、DELETE语句的LOW_PRIORITY属性,降低该语句的优先级。 5、一张MyISAM表由.frm, .myd, myi三个文件组成。 .frm 表结构 .myd 表数据 .myi [...]

MySQL 中逗号=Cross Join=Inner Join

By Symphony - Last updated: Friday, June 12, 2009

转自:http://dev.mysql.com/doc/refman/5.0/en/join.html The syntax of table_factor is extended in comparison with the SQL Standard. The latter accepts only table_reference, not a list of them inside a pair of parentheses. This is a conservative extension if we consider each comma in a list of table_reference items as equivalent to an inner join. For example: SELECT * FROM [...]

Zabbix的一个bug

By Symphony - Last updated: Tuesday, June 9, 2009

最近公司的项目要分解zabbix。分析它的代码的时候发现其数据库类有一个bug:使用mysql_pconnect建立一个数据库连接,却用mysql_close去关闭!这样做是关不掉的!因为mysql_pconnect建立的是一个持久化的连接,使用完毕会被放回连接池的,即使脚本执行完毕,这个连接也不会关闭。 一下是php.net对mysql_close的解释: mysql_close() closes the non-persistent connection to the MySQL server that’s associated with the specified link identifier. If link_identifier isn’t specified, the last opened link is used. 一下是有问题的代码片段: $mysql_server = $DB['SERVER'].( !empty($DB['PORT']) ? ‘:’.$DB['PORT'] : ”); if (!$DB['DB']= mysql_pconnect($mysql_server,$DB['USER'],$DB['PASSWORD'])){ $error = ‘Error connecting to database ['.mysql_error().']‘; $result = false; } else{ if (!mysql_select_db($DB['DATABASE'])){ $error [...]

在 Ubuntu 上使用 apt-get 安装配置 Apache2.2 + PHP5.2 + MySQL5.0

By Symphony - Last updated: Thursday, March 19, 2009

安装以下这些包 apache2 php5-mysql libapache2-mod-php5 mysql-server libapache2-mod-auth-mysql php5-cli (中间会提示输入MySQL密码) 参考:LAMP服务器的配置

基于 Ubuntu 通过源代码安装 MySQL 5.0

By Symphony - Last updated: Tuesday, March 17, 2009

一、安装 CFLAGS=”-O3″ CXX=gcc CXXFLAGS=”-O3 -felide-constructors -fno-exceptions -fno-rtti” ./configure –prefix=/usr/local/mysql –enable-thread-safe-client –enable-assembler –enable-shared –enable-static –with-charset=utf8 –with-ssl –with-plugins=max –with-unix-socket-path=/tmp/mysql.sock –with-client-ldflags=-all-static –with-mysqld-ldflags=-all-static make make install 二、配置 cp /usr/local/mysql/bin/mysql_config /usr/bin/ (创建软连接) ln -s /usr/local/mysql/bin/mysql /usr/bin/ ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/ ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/ ln -s /usr/local/mysql/bin/mysql_conf /usr/bin/ ln -s /usr/local/mysql/share/mysql/mysql.server /usr/bin/ (创建用户组mysql) groupadd mysql (在用户组mysql下创建用户mysql) useradd -g mysql mysql [...]