程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> MySQL的源碼裝置及應用UDFs停止數據主動更新的教程

MySQL的源碼裝置及應用UDFs停止數據主動更新的教程

編輯:MySQL綜合教程

MySQL的源碼裝置及應用UDFs停止數據主動更新的教程。本站提示廣大學習愛好者:(MySQL的源碼裝置及應用UDFs停止數據主動更新的教程)文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL的源碼裝置及應用UDFs停止數據主動更新的教程正文


MySQL的源碼裝置
1. 裝置依附組件

# yum install gcc gcc-c++ ncurses-devel perl -y

2. 裝置cmake

# 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

3. 裝置bison

# 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

4. 創立用戶的響應目次

# groupadd mysql
# useradd -g mysql mysql
# mkdir -p /data/mysql/
# mkdir -p /data/mysql/data/
# mkdir -p /data/mysql/log/

5. 獲得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

6. 修正目次權限

# 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

7. 初始化數據庫

# 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

8. 啟動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

9. 完成設置裝備擺設

# /data/mysql/bin/mysqladmin -uroot -p password 'PASSWD'
# echo "export PATH=/data/mysql/bin:$PATH" >> ~/.bash_profile 
# source ~/.bash_profile

UDFs完成Memcached與Mysql的主動更新

UDFs是User Defined Functions的縮寫,表現MYSQL的用戶界說函數,運用法式可以應用這些函數從MYSQL5.0以上版本的數據庫中拜訪Memcached寫入或許獲得的數據。另外,MYSQL從5.1版本開端支撐觸發器,從而可以在觸發器中應用UDFs直接更新Memcached的內容,這類方法下降了運用法式設計和編寫的龐雜性。
1.裝置

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

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
make && make install
mysql -uroot -pmysql < /sql/install_functions.sql
mysql -uroot -pmysql -se "select name,dl from mysql.func"

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'); 

設置MEMCACHED_BEHAVIOR_NO_BLOCK為翻開狀況,如許在memcached湧現成績時(不克不及銜接時)數據持續拔出到
mysql中,報錯提醒,假如不設置此值,假如memcached掉敗,mysql須要比及timeout才可以拔出到表中。

2.測試:

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://谷歌.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');

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved