Mysql source code installation and the use of UDFs for automatic data updates tutorial _mysql

Source: Internet
Author: User

MySQL installation of the source code
1. Installing Dependent components

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

2. Install 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. Install 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. Create the appropriate directory for the user

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

5. Get MySQL Install package and install

# 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. Modify Directory Permissions

# chmod +w/data/mysql/
# chown-r mysql:mysql/data/mysql/

# ln-s/data/mysql/lib/libmysqlclient.so.18/usr/l ib/libmysqlclient.so.18
# ln-s/data/mysql/mysql.sock/tmp/mysql.sock

7. Initializing the database

# 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. Start MySQL Service

# 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. Complete the configuration

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

UDFs realizes automatic update of memcached and MySQL

UDFs is the abbreviation for user Defined functions, which represents MySQL's users-defined functions that can be used by applications to access memcached write or fetch data from a database that is above the MYSQL5.0 version. In addition, MySQL supports triggers from version 5.1 so that you can use UDFs directly to update memcached content in triggers, which reduces the complexity of application design and authoring.
1. Installation

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 "Selec T name,dl from Mysql.func "

Select Memc_servers_set (' 127.0.0.1:11211 '); if the MySQL restart, you need to rerun this sentence to establish a relationship with memcached
Select Memc_server_ Count ();
Select Memc_set (' Urls:sequence ', 0);

Select Memc_list_behaviors () \g//Modify the behavior of the MEMCACHED parameter

select Memc_servers_behavior_set (' Memcached_behavior_no_ Block ', ' 1 ');
Select
memc_servers_behavior_set (' Memcached_behavior_tcp_nodelay ', ' 1 '); 

Set Memcached_behavior_no_block to open so that data continues to be inserted into the memcached when a problem occurs (when not connected)
MySQL, the error prompts, if you do not set this value, if memcached failed, MySQL needs to wait until timeout can be inserted into the table.

2. Test:

Drop table if exists URLs;

CREATE TABLE URLs (ID int (3) Not NULL auto_increment, url varchar (+) 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 URL 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 the 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 URL 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 URL (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 URL where url= ' http://microsoft.com/';
 Select Memc_get (' urls:4 ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.