#首先确定你是root用户
tar zxfv mysql-5.1.34.tar.gz
cd mysql-5.1.34
#根据体统类型选择编译方式
#i386体系结构的
#CFLAGS="-O3 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O3 -mcpu=pentiumpro -felide-constructors -fno-exceptions -fno-rtti" ./configure --with-raid --enable-thread-safe-client --enable-assembler --with-server-suffix =" for >>>MySQL Database of Zebra by Yhc<<<" --without-debug --with-extra-charsets=complex --without-isam --prefix=/usr/local/mysql --without-bench
#64位系统,x86_64
#CFLAGS="-O3 -m64" CXX=gcc CXXFLAGS="-O3 -m64 -felide-constructors -fno-exceptions -fno-rtti" ./configure --with-raid --enable-thread-safe-client --enable-assembler --with-server-suffix =" for >>>MySQL Database of Zebra by Yhc<<<" --without-debug --with-extra-charsets=complex --without-isam --without-server --prefix=/usr/local/mysql --without-bench --with-archive-storage-engine
CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" ./configure --enable-thread-safe-client --enable-assembler --with-server-suffix =" for >>>MySQL Database of Zebra by Yhc<<<" --without-debug --with-extra-charsets=complex --prefix=/usr/local/mysql
#然后根据CPU数量进行编译
make -j 8 && make install
#添加用户
groupadd mysql && useradd -g mysql mysql
#创建目录
mkdir /usr/local/mysql/data && mkdir /usr/local/mysql/run && mkdir /usr/local/mysql/log && mkdir /usr/local/mysql/var
#更改mysql目录所有者
#chgrp mysql -R /usr/local/mysql && chown mysql -R /usr/local/mysql
#增加打开文件数量
ulimit -n 2048
#添加PATH
echo "PATH=\"/usr/local/mysql/bin:\$PATH\"" >> /etc/profile && export PATH="/usr/local/mysql/bin:$PATH"
#strip可执行文件
strip /usr/local/mysql/libexec/mysqld
#添加LIB PATH
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf && ldconfig
#将my.cnf文件cp到/etc目录下
/bin/cp -r /usr/local/mysql/share/mysql/my-huge.cnf /etc/my.cnf && chown mysql:mysql /etc/my.cnf
sed -i 's/skip-federated/#skip-federated/' /etc/my.cnf
cd /usr/local/mysql/bin
ln -s ./mysql ./test_mysql
ln -s ./mysqladmin ./adminmysql
ln -s ./mysql_install_db ./install_db_mysql
ln -s ./mysqld_safe ./safe_mysqld
#初始化Mysql表
cd /usr/local/mysql/bin
./install_db_mysql --user=mysql
chown -R root /usr/local/mysql && chown -R mysql /usr/local/mysql/var && chgrp -R mysql /usr/local/mysql
pkill -9 mysql
#su - mysql -c "mysqld_safe --skip-name-resolve --open-files-limit=20480 &"
#完成后,删除空的用户名帐号。
#/usr/local/mysql/bin/mysql -uroot -e "use mysql;delete from user where "User"='';"
#为本地帐户创建密码
#/usr/local/mysql/bin/mysql -uroot -e "set password for root@"localhost" = password('123456');"
#/usr/local/mysql/bin/mysql -uroot -p123456 -e "use mysql;update user set Password=password('123456') where "Host"='localhost.localdomain';flush privileges;"
#关闭服务器
#su - mysql -c "mysqladmin -u root -pPASSWORD shutdown"
=========================================================================================
#!/bin/bash
#安装libevent
tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure --prefix=/usr/local/
make
make install
#ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib64/
cd ..
#安装memcached
tar zxvf memcached-1.2.6.tar.gz
cd memcached-1.2.6
./configure --prefix=/usr/local/ --with-libevent=/usr/local/
make
make install
#运行memcached时候用root账号运行,格式:
#./memcached -d -u root -m 2048 -l 172.17.13.253 -p 11211
=========================================================================
测试环境部署
一、服务器环境部署
1、 所需软件
mysql-5.1.34.tar.gz (数据库包)
httpd-2.2.10.tar.gz (apache包,做客户端自动更新需要,仅部署服务器环境可不装)
libevent-1.4.7-stable.tar.gz(libevent库,安装memcached需)
memcached-1.2.6.tar.gz (积分、鲜花服务器需要配置,作为积分、鲜花缓存)
2、 安装过程
1)mysql安装
首先:
以root帐号登录linux,创建mysql用户跟mysql组
shell> groupadd mysql
shell> useradd -g mysql mysql
解压文件
shell> tar zvxf mysql-4.1.18.tar.gz
shell> cd mysql-4.1.18
进行安装配置,强制使用pthread库,以及以线程方式编译客户端
shell>./configure--prefix=/usr/local/mysql --with-pthread --enable-thread-safe-client
shell >make
shell>make install
#添加PATH
echo"PATH=\"/usr/local/mysql/bin:\$PATH\"" >>/etc/profile && export PATH="/usr/local/mysql/bin:$PATH"
#增加打开文件数量
ulimit-n 4096
#打开CORE文件
ulimit-c unlimited
通过以上步骤就安装好了mysql接下来配置mysql
其次:
把support-files下的my-medium.cnf文件复制到etc目录下
shell>cpsupport-files/my-medium.cnf /etc/my.cnf
(进入/etc目录下打开my.cnf,注释掉其中的skip-federated 不然初始化数据库会失败)
切换到mysql的安装目录,在本例子中mysql安装在 /usr/local/mysql
shell >cd/usr/local/mysql
初试化数据库
shell >bin/mysql_install_db --user=mysql
(在/usr/local/mysql/bin目录下执行./mysql_install_db --user=mysql)
给相应的用户分配权限(/usr/local/mysql目录下执行)
shell >chown-R root .
shell >chown -R mysql var
shell >chgrp -R mysql . (该指令将数据目录所有属性改为mysql用户)
把启动、停止命令拷贝到/usr/sbin目录下并赋权
shell >cp mysql.-5.1.34/support-files/mysql.server/usr/sbin (/etc/init.d)
shell>chmod 777 /usr/sbin/mysql.server
通过下面的命令启动mysql
shell>bin/mysqld_safe -user=mysql &
(对root用户设置密码:
在/usr/local/mysql/bin目录下执行
./mysqladmin -u root password '123456'
用root账户登陆:
在/usr/local/mysql/bin目录下执行 ./mysql -u root -p)
通过以上步骤就可以使用mysql数据库了。
(建立一个管理员账号,用root权限登陆mysql后执行以下语句:
GRANTALL ON *.* to pzzx IDENTIFIED BY "pzzx" WITH GRANT OPTION;)
GRANT ALL PRIVILEGES ON *.* TO root@'172.17.112.21'IDENTIFIED BY '123456' WITH GRANT OPTION;