Mysql应用MySQL的源码安装及使用UDFs进行数据自动更新的教程

前端之家收集整理的这篇文章主要介绍了Mysql应用MySQL的源码安装及使用UDFs进行数据自动更新的教程前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

MysqL应用MysqL的源码安装及使用UDFs进行数据自动更新的教程》要点:
本文介绍了MysqL应用MysqL的源码安装及使用UDFs进行数据自动更新的教程,希望对您有用。如果有疑问,可以联系我们。

MysqL必读MysqL的源码安装
1. 安装依赖组件

MysqL必读
# yum install gcc gcc-c++ ncurses-devel perl -y

MysqL必读2. 安装cmake

MysqL必读
# wget http://www.cmake.org/files/v2.8/cmake-2.8.12.tar.gz
# tar zxvf cmake-2.8.12.tar.gz
# cd cmake-2.8.12
# ./bootstrap 
# make && make install

MysqL必读3. 安装bison

MysqL必读
# wget http://ftp.gnu.org/gnu/bison/bison-3.0.2.tar.gz
# tar zxvf bison-3.0.2.tar.gz
# cd bison-3.0.2
# ./configure
# make && make install

MysqL必读4. 创建用户的相应目录

MysqL必读
# groupadd MysqL
# useradd -g MysqL MysqL
# mkdir -p /data/MysqL/
# mkdir -p /data/MysqL/data/
# mkdir -p /data/MysqL/log/

MysqL必读5. 获取MysqL安装包并安装

MysqL必读
# wget http://downloads.MysqL.com/archives/MysqL-5.5/MysqL-5.5.24.tar.gz
# tar zxvf MysqL-5.5.24.tar.gz
# cd MysqL-5.5.24
# cmake \
-DCMAKE_INSTALL_PREFIX=/data/MysqL \
-DMysqL_UNIX_ADDR=/data/MysqL/MysqL.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DMysqL_DATADIR=/data/MysqL/data \
-DMysqL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
# make && make install

MysqL必读6. 修改目录权限

MysqL必读
# chmod +w /data/MysqL/
# chown -R MysqL:MysqL /data/MysqL/
# ln -s /data/MysqL/lib/libMysqLclient.so.18 /usr/lib/libMysqLclient.so.18
# ln -s /data/MysqL/MysqL.sock /tmp/MysqL.sock

MysqL必读7. 初始化数据库

MysqL必读
# cp -rp /data/MysqL/support-files/my-medium.cnf /etc/my.cnf
# cp -rp /data/MysqL/support-files/MysqL.server /etc/rc.d/init.d/MysqLd
# /data/MysqL/scripts/MysqL_install_db --user=MysqL --defaults-file=/etc/my.cnf --basedir=/data/MysqL --datadir=/data/MysqL/data

MysqL必读8. 启动MysqL服务

MysqL必读
# chmod +x /etc/init.d/MysqLd
# vi /etc/init.d/MysqLd -->
basedir=/data/MysqL
datadir=/data/MysqL/data
# chkconfig --add MysqLd
# service MysqLd start

MysqL必读9. 完成配置

MysqL必读
# /data/MysqL/bin/MysqLadmin -uroot -p password 'PASSWD'
# echo "export PATH=/data/MysqL/bin:$PATH" >> ~/.bash_profile 
# source ~/.bash_profile

MysqL必读UDFs实现Memcached与MysqL自动更新

MysqL必读UDFs是User Defined Functions的缩写,表示MysqL用户定义函数,应用程序可以利用这些函数MysqL5.0以上版本的数据库中访问Memcached写入或者获取的数据.此外,MysqL从5.1版本开始支持触发器,从而可以在触发器中使用UDFs直接更新Memcached的内容,这种方式降低了应用程序设计和编写的复杂性.
1.安装

MysqL必读
wget https://launchpad.net/libmemcached/1.0/0.34/+download/libmemcached-0.34.tar.gz
yum install gcc44 gcc44-c++ libstdc++44-devel
export CC=/usr/bin/gcc44
export CXX=/usr/bin/g++44
./configure --prefix=/soft/libmemcached -disable-64bit CFLAGS="-O3 -march=i686" \
--with-memcached=/root/libmemcached-1.0.7/memcached
make && make install
MysqL必读
wget https://launchpad.net/memcached-udfs/trunk/1.1/+download/memcached_functions_MysqL-1.1.tar.gz
./configure --prefix=/soft/UDFS/memcache_MysqL \
--with-MysqL=/soft/MysqL/bin/MysqL_config \
--libdir=/soft/MysqL/lib/plugin \
--with-libmemcached=/soft/UDFS/libmemcached
MysqL必读
make && make install
MysqL -uroot -pMysqL < /sql/install_functions.sql
MysqL -uroot -pMysqL -se "select name,dl from MysqL.func"
MysqL必读
select memc_servers_set('127.0.0.1:11211');//如果MysqL restart,需要重新运行这句以建立与memcached之间的关系
select memc_server_count();
select memc_set('urls:sequence',0);
select memc_list_behaviors()\G//修改memcached参数的行为
select memc_servers_behavior_set('MEMCACHED_BEHAVIOR_NO_BLOCK','1');
select
memc_servers_behavior_set('MEMCACHED_BEHAVIOR_TCP_NODELAY','1'); 

MysqL必读设置MEMCACHED_BEHAVIOR_NO_BLOCK为打开状态,这样在memcached出现问题时(不能连接时)数据继续插入到
MysqL中,报错提示,如果不设置此值,如果memcached失败,MysqL需要等到timeout才可以插入到表中.

MysqL必读2.测试:

MysqL必读
drop table if exists urls;
create table urls (
 id int(3) not null auto_increment,url varchar(64) not null default '',primary key (id)
 );
select memc_servers_set('localhost:11211');
select memc_set('urls:sequence',0);
DELIMITER |
DROP TRIGGER IF EXISTS url_mem_insert |
CREATE TRIGGER url_mem_insert
BEFORE INSERT ON urls
FOR EACH ROW BEGIN
  SET NEW.id= memc_increment('urls:sequence'); 
  SET @mm= memc_set(NEW.id,NEW.url);
END |
DROP TRIGGER IF EXISTS url_mem_update |
CREATE TRIGGER url_mem_update
BEFORE UPDATE ON urls
FOR EACH ROW BEGIN
  SET @mm= memc_replace(OLD.id,NEW.url);
END |
DROP TRIGGER IF EXISTS url_mem_delete |
CREATE TRIGGER url_mem_delete
BEFORE DELETE ON urls
FOR EACH ROW BEGIN
  SET @mm= memc_delete(OLD.id);
END |
DELIMITER ;
insert into urls (url) value ('http://google.com');
insert into urls (url) value ('http://lycos.com/');
insert into urls (url) value ('http://tripod.com/');
insert into urls (url) value ('http://microsoft.com/');
insert into urls (url) value('http://slashdot.org');
insert into urls (url) value ('http://MysqL.com');
select * from urls;
select memc_get('urls:1');
select memc_get('urls:2');
select memc_get('urls:3');
select memc_get('urls:4');
select memc_get('urls:5');
select memc_get('urls:6');
update urls set url= 'http://MysqL.com/sun' where url = 'http://MysqL.com';
select url from urls where url = 'http://MysqL.com/sun';
select memc_get('urls:6');
delete from urls where url = 'http://microsoft.com/';
select * from urls where url='http://microsoft.com/';
select memc_get('urls:4');

猜你在找的MySQL相关文章