Mysql5.5安装配置在Centos上,由于以后有项目要进行几个架构的探讨,所以先自己在虚拟机上测试一套主从,读写分离的集群来测试环境!
虚拟机采用的是,vmware workstation8.0,linux:centos5.5版本的!
虚拟机装系统很简短就不再截图出来,网络采用桥接方式,并且要求能联网ping通。为了以后更新RPM包使用yum命令,减少依赖包的障碍!
一、安装cmake
# 安装所需依赖包
yum -y install gcc libxml2-dev curl screen \
libpng12-dev autoconf libpcre3-dev make bzip2 \
libevent-dev patch libjpeg62-dev libcurl4-openssl-dev \
libfreetype6-dev g++ libtool libncurses5-dev psmisc lrzsz
同时也要更更新以下的包;
Yum –y install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel*libgcrypt* libtool*
# 下载文件
wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
# 编译安装
tar zxvf cmake-2.8.5.tar.gz
cd cmake-2.8.5
./boostarp
make
make install
cmake –version
这里我把所有的包都存放到/usr/local/这个目录下,包括下面下载的mysql安装包;
[root@slave01 local]# ls
bin cmake-2.8.5.tar.gz etc games include lib libexec sbin share src
[root@slave01 cmake-2.8.5]# cmake -version
cmake version 2.8.5
二、 安装配置mysql
# 下载源文件
wgethttp://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.17.tar.gz/from/ftp://ftp.ntu.edu.tw/pub/MySQL/
# 或
wget ftp://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.5/mysql-5.5.17.tar.gz
以上连个链接有问题,大家随便到网上搜搜,就有很多mysql5.5的安装包,这个不难。
# 创建用户和组
groupadd mysql
useradd -g mysql -s /usr/sbin/nologin mysql
# 创建安装目录
mkdir /usr/local/ mysql
# 创建数据库目录
mkdir /usr/local/ mysql/data
# 解压
tar -zxvf mysql-5.5.17.tar.gz
cd mysql-5.5.17
# 编译及安装mysql
# cmake编译:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_unicode_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0
运行以后出现以下错误;
-- Check size of wchar_t - done
-- Check size of wctype_t
-- Check size of wctype_t - done
-- Check size of wint_t
-- Check size of wint_t - done
-- Found Curses: /usr/lib/libcurses.so
-- Looking for tputs in/usr/lib/libcurses.so
-- Looking for tputs in/usr/lib/libcurses.so - found
-- Looking for include files HAVE_LIBAIO_H
-- Looking for include files HAVE_LIBAIO_H- not found.
-- Looking for io_queue_init in aio
-- Looking for io_queue_init in aio - notfound
-- Performing TestHAVE_IB_GCC_ATOMIC_BUILTINS
-- Performing TestHAVE_IB_GCC_ATOMIC_BUILTINS - Failed
-- Performing TestHAVE_IB_ATOMIC_PTHREAD_T_GCC
-- Performing TestHAVE_IB_ATOMIC_PTHREAD_T_GCC - Failed
-- Check size of pthread_t
-- Check size of pthread_t - done
-- Performing Test HAVE_PEERCRED
-- Performing Test HAVE_PEERCRED - Success
Warning: Bisonexecutable not found in PATH
-- Configuring incomplete, errors occurred!
You have mail in /var/spool/mail/root
安装下bison包,
Yum –y install bison*
再次运行出现新错误,不要着急,遇到错误,应该是很欣慰,现在知道了,以后就有把握自己处理,不必再百度,谷歌,满世界询问了
[root@slave01 mysql-5.5.13]# cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_READLINE=1-DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1-DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0
-- MySQL 5.5.13
-- checking for module 'openssl'
-- package 'openssl' notfound
-- Could NOT find OpenSSL, try to set thepath to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR(missing: OPENSSL_LIBRARIESOPENSSL_INCLUDE_DIR)
CMake Error at cmake/ssl.cmake:83(MESSAGE):
Cannot find appropriate system libraries for SSL. Use WITH_SSL=bundled to
enable SSL support
Call Stack (most recent call first):
CMakeLists.txt:248 (MYSQL_CHECK_SSL)
-- Configuring incomplete, errors occurred!
此错误提示很清楚,有个包缺少,yum下即可。遇错误一定仔细看错误信息,这是你成为牛人的关键一步;
[root@slave01 mysql-5.5.13]# cmake-DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_unicode_ci -DWITH_READLINE=1-DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1-DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0
-- MySQL 5.5.13
-- checking for module 'openssl'
-- found openssl, version 0.9.8e-rhel5
-- Found OpenSSL:/usr/lib/libssl.so;/usr/lib/libcrypto.so (found version "0.9.8")
CMake Error at cmake/ssl.cmake:83(MESSAGE):
Cannot find appropriate system libraries for SSL. Use WITH_SSL=bundled to
enable SSL support
Call Stack (most recent call first):
CMakeLists.txt:248 (MYSQL_CHECK_SSL)
我装好包以后再次运行,依然有err出现,这里是因为,我们在多次运行的时候cmake有个文件我们需要删除,需要在安装新包的情况下,重新应用下相关的文件;
删除当前目录CMakeCache.txt并重新运行:
Cmake .
看清楚有个点,并且有个空格;
再次运行cmake命令就会正常;
# 安装mysql
make && make install
# 复制配置文件
cp support-files/my-medium.cnf /etc/my.cnf
# 设置权限
chmod +x /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
chown -Rmysql:mysql /usr/local/mysql/data
# 配置开机自启动
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig –add mysqld
chkconfig mysqldon
# 修改my.cnf配置
vim /etc/my.cnf
# [mysqld] 添加:
datadir=/usr/local/mysql/data
default-storage-engine=MyISAM
# 以下可选:
log-error =/usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
user = mysql
tmpdir = /tmp
# 初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data &
# 启动MySQL
/usr/local/mysql/bin/mysqld_safe –defaults-file=/etc/my.cnf &
或者:
/etc/init.d/mysql start (service mysql start)
# 测试MySQL是否启动
# 1)查看是否有进程mysql
ps -ef | grep mysql
# 2)查看端口是否运行
netstat -tnl | grep 3306
# 3)读取mysql版本信息
/usr/local/mysql/bin/mysqladmin version
# 至此,MySQL安装完成
安装的mysql的root密码一般都是空,我们可以设置它为我们指定的密码;
首先登陆mysql,然后执行下面命令即可;
SET PASSWORD FOR 'root'@'localhost' =PASSWORD('your new password');
flush privileges;