> 数据库 > MySQL >

Centos 6.2(x64)下编译安装MySQL-5.5.22

001.========================Centos 6.2(x64)下编译安装<a href="http://www.it165.net/database/dbmy/" target="_blank"class="keylink">MySQL</a>-5.5.22========================
002.软件源码包存放位置  /usr/local
003.源码包编译安装位置  /usr/local/mysql
004.###########################################################################################
005.#                                                                                         #
006.#  现在的5.5以后的<a href="http://www.it165.net/database/dbmy/" target="_blank" class="keylink">MySQL</a>都使用Cmake进行编译安装,所以在安装MySQL之前我们首先要把Cmake装在我们的系统。#
007.#                                                                                         # 
008.###########################################################################################
009.我们所需要的软件源码包有以下:
010.cmake-2.8.7.tar.gz
011.mysql-5.5.22.tar.gz(mysql版本可以更新)
012.1、安装Cmake
013.#安装所需依赖关系
014.yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel 
015.ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel 
016.libXpm-devel gettext-devel  pam-devel libtool libtool-ltdl openssl openssl-devel 
017.fontconfig-devel libxml2-devel curl-devel  libicu libicu-devel libmcrypt libmcrypt-devel
018.libmhash libmhash-devel
019.安装 mcrypt时如果提示libmcrypt没有找到 运行 
020.export LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/mhash/lib
021.export LDFLAGS="-L/usr/local/mhash/lib/ -I/usr/local/mhash/include"
022.export CFLAGS="-I/usr/local/mash/include/"
023../configure --prefix=/usr/local/mcrypt --with-libmcrypt --prefix=/usr/local/libmcrypt
024.#下载Cmake的源码包
025.#编译安装
026.tar zxvf cmake-2.8.7.tar.gz
027.cd cmake-2.8.7
028../configure && make && make install
029.2、编译安装配置MySQL#
030.创建所需目录   mkdir -pv /usr/local/mysql/data //同时创建mysql和data两个目录并输出创建信息
031.创建mysql组      groupadd mysql 
032.创建mysql用户    useradd -g mysql -s /sbin/nologin mysql
033. 
034.#解压源码包tar -zxvf 源码包路径 -C /usr/src/   本人常解压在此目录下面
035.cd /usr/src/mysql目录
036.#cmake编译
037. 
038.cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5 -DMYSQL_UNIX_ADDR=/usr/local/mysql5/mysql.sock
039.-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all 
040.-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1
041.-DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql5/data 
042.-DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306
043. 
044.==============================================================================
045.参数说明:
046.-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
047.-DMYSQL_DATADIR=/usr/local/mysql/data //数据库存放目录
048.-DWITH_MYISAM_STORAGE_ENGINE=1 //安装myisam存储引擎
049.-DWITH_INNOBASE_STORAGE_ENGINE=1 //安装innodb存储引擎
050.-DWITH_ARCHIVE_STORAGE_ENGINE=1 //安装archive存储引擎
051.-DWITH_BLACKHOLE_STORAGE_ENGINE=1 //安装blackhole存储引擎
052.-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
053.-DDEFAULT_CHARSET=utf8   //使用utf8字符
054.-DDEFAULT_COLLATION=utf8_general_ci //校验字符
055.-DEXTRA_CHARSETS=all   //安装所有扩展字符集
056.-DMYSQL_TCP_PORT=3306 //MySQL监听端口
057.-DMYSQL_USER=mysql //MySQL用户名
058.-DWITH-EMBEDDED_SERVER=1 //编译成embedded MySQL library (libmysqld.a)
059.-DSYSCONFDIR=/etc //MySQL配辑文件
060.-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock //Unix socket 文件路径
061.-DWITH_READLINE=1 //快捷键功能
062.-DWITH_SSL=yes //SSL
063.-DWITH_MEMORY_STORAGE_ENGINE=1 //安装memory存储引擎
064.-DWITH_FEDERATED_STORAGE_ENGINE=1 //安装frderated存储引擎
065.-DWITH_PARTITION_STORAGE_ENGINE=1 //安装数据库分区
066.-DINSTALL_PLUGINDIR=/usr/local/mysql/plugin //插件文件及配置路径
067.=========================================================================================
068.#安装
069.make && make install
070. 
071.#复制配置文件(源码目录下面)
072.cp support-files/my-medium.cnf /etc/my.cnf
073.#设置权限
074.chmod +x /usr/local/mysql
075.chown -R mysql:mysql /usr/local/mysql
076.chown -R mysql:mysql /usr/local/mysql/data
077.#配置开机自动启动
078.cp support-files/mysql.server /etc/init.d/mysqld
079.chmod +x /etc/init.d/mysqld
080.chkconfig --add mysqld
081.chkconfig mysqld on
082.#修改配置文件
083.vim /etc/my.cnf
084.#在[mysqld]中添加:
085.datadir = /usr/local/mysql/data
086.log-error = /usr/local/mysql/data/error.log
087.pid-file = /usr/local/mysql/data/www.pid     //(此处的pid文件名称要与主机名称一致)
088.user = mysql
089.tmpdir = /tmp
090.#保存退出
091. 
092.#初始化数据库
093./usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql 
094.--datadir=/usr/local/mysql/data
095. 
096.#手动启动MySQL
097.service mysqld start
098.加入环境变量,在/etc/profile文件中最后加入:
099. 
100.export PATH=/usr/local/mysql/bin:$PATH
101.修改默认的mysql最大连接数(默认只有151),打开/etc/my.cnf文件,在[mysqld]的下面加入:
102.max_connections=1000,然后重启mysql即可生效,查看最大连接数:
103. 
104.mysql&gt;show VARIABLES LIKE '%conn%';
105.###############################################################################
106.#                                                                             #
107.#此时如果启动失败,查看日志,如果提示字符集无效,修改my.cnf配置文件,添加下面设置          #
108.#[client]                                                                     #
109.#linux环境下面设置此值                                                          #
110.#default-character-set=utf8                                                   #
111.#                                                                             #
112.#[mysqld]                                                                     #
113.#character-set-server=utf8                                                    #
114.#保存退出后重新初始化数据库                                                       #
115.#                                                                             #
116.#/usr/local/mysql/scripts/mysql_install_db --user=mysql                       #
117.#--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data                   #
118.#                                                                             #
119.###############################################################################
120. 
121.#测试MySQL是否启动
122.#查看是否有mysql进程
123.ps -ef | grep mysql
124.#查看是否有mysql端口
125.netstat -tnlp | grep 3306
126.如果提示[ERROR] Plugin 'InnoDB' init function returned error,把安装目录下面的ib_logfile0
127.和ib_logfile1删除或者重命名
128.重启Mysqld服务
129.设置Mysql程序执行路径
130.export PATH=$PATH:/usr/local/mysql/bin
131.echo "PATH=$PATH:/usr/local/mysql/bin" &gt;&gt; /etc/profile
132.#读取MySQL的版本信息mysqladmin version
133. 
134.===========================到此MySQL编译安装完成=========================================
135.#######################################################
136.#                                                     #
137.#     第一次登录默认为空密码                             #
138.#                                                     #
139.#      mysql -u root                                  #
140.#                                                     #
141.#      修改root登录数据库的密码                          #
142.#                                                     #
143.#     mysqladmin -u root pass<a href="http://www.it165.net/edu/ebg/" target="_blank" class="keylink">word</a> "自定义的密码"        #
144.#                                                     #
145.#######################################################
146. 
(责任编辑:IT)