1.安装cmake
[root@localhost ~]# yum install cmake
2.添加系统mysql组和mysql用户:
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
3.解压源码安装包
[root@localhost ~]# tar -zvxf mysql-5.5.32.tar.gz
[root@localhost ~]# cd mysql-5.5.32
4.编译MySQL5.5.32
[root@localhost mysql-5.5.32]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
> -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_MEMORY_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DMYSQL_DATADIR=/var/mysql/data \
> -DMYSQL_USER=mysql
以上参数等说明:
DCMAKE_INSTALL_PREFIX=/usr/local/mysql # mysql安装的主目录,默认为/usr/local/mysql
DMYSQL_DATADIR=/usr/local/mysql/data # mysql数据库文件的存放目录,可以自定义
DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock # 系统Socket文件(.sock)设置,基于该文件路径进行Socket链接,必须为绝对路径
DSYSCONFDIR=/etc # mysql配置文件 my.cnf的存放地址,默认为/etc下
DMYSQL_TCP_PORT=3306 # 数据库服务器监听端口,默认为3306
DENABLED_LOCAL_INFILE=1 # 允许从本地导入数据
DWITH_READLINE=1 # 快捷键功能
DWITH_SSL=yes # 支持 SSL
DMYSQL_USER=mysql # 默认为mysql
//下面3个是数据库编码设置
DEXTRA_CHARSETS=all # 安装所有扩展字符集,默认为all
DDEFAULT_CHARSET=utf8 # 使用 utf8 字符
DDEFAULT_COLLATION=utf8_general_ci # 校验字符
//下面5个是数据库存储引擎设在
DWITH_MYISAM_STORAGE_ENGINE=1 # 安装 myisam 存储引擎
DWITH_INNOBASE_STORAGE_ENGINE=1 # 安装 innodb 存储引擎
DWITH_ARCHIVE_STORAGE_ENGINE=1 # 安装 archive 存储引擎
DWITH_BLACKHOLE_STORAGE_ENGINE=1 # 安装 blackhole 存储引擎
DWITH_PARTITION_STORAGE_ENGINE=1 # 安装数据库分区
遇到错误:
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAK
E_C_COMPILER to a valid compiler path or name.CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set
CMAKE_CXX_COMPILER to a valid compiler path or name.
这是因为缺少相关库文件,依赖
解决方法:root@localhost ~]# yum install -y gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel*
如果继续报错,只能删除原来的mysql-5.5.23目录,重新解压缩tar.gz包
5.执行安装
[root@localhost mysql-5.5.32]# make
[root@localhost mysql-5.5.32]# make install
[root@localhost ~]# chmod +w /usr/local/mysql
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql #改变目录拥有者与所属组
[root@localhost ~]# ln -s /usr/local/mysql/lib/libmysqlclient.so.16 /usr/lib/libmysqlclient.so.16
[root@localhost ~]# cd support-files/
[root@localhost ~]# cp my-large.cnf /etc/my.cnf # 选择默认 配置文件 适合大型服务器
[root@localhost ~]# cp mysql.server /etc/init.d/mysqld # 复制启动文件
6. 配置启动MySQL
1. 若有需要请先修改 mysql 的配置 my.cnf
[root@localhost ~]# vi /etc/my.cnf
在[mysqld]下面添加
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/data/mysql.pid
default-storage-engine=MyISAM
user = mysql
2. mysql 初始化安装 执行以下命令
[root@localhost ~]# /usr/local/mysql/scripts/mysql_install_db \
--basedir=/usr/local/mysql \
--datadir=/var/mysql/data \
--user=mysql
3. 将 mysql 加入开机启动
[root@localhost ~]# chmod +x /etc/init.d/mysqld
[root@localhost ~]# vi /etc/init.d/mysqld (编辑此文件,查找并修改以下变量内容:)
basedir=/usr/local/mysql
datadir=/var/mysql/data
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --level 345 mysqld on
为MySQL配置环境变量,以后使用起来方便
# export PATH=/usr/local/mysql/bin:$PATH
4. 启动 mysql
[root@localhost ~]# service mysqld start
设置密码
[root@localhost ~]# mysql_secure_installation
注意:如果出现 Starting MySQL...The server quit without updating PID file
报错:
Starting MySQL...The server quit without updating PID file
查看错误日志
情景1:
110206 12:58:35 [ERROR] Can't start server : Bind on unix socket: No such file or directory
110206 12:58:35 [ERROR] Do you already have another mysqld server running on socket: /mysql/mysqldir/data/mysql.sock ?
110206 12:58:35 [ERROR] Aborting
[root@localhost ~]# ps -ef | grep mysql # 未发现有mysqld.
[root@localhost ~]# netstat -an | grep 3306 也未发现异常.
最后从mysql安装目录下重新复制一个配置文件到/etc/my.cnf
修改相应参数.于是问题解决
情景2:
/mysql/mysqldir/bin/mysqld: Table 'mysql.plugin' doesn't exist
[ERROR] Can't open the mysql.plugin table. Please run my sql_upgrade to create it.
原因:编译安装后忘记初始化表.
解决:运行mysql_install_db
其他情况,查看日志文件(我的是localhost.localdomain.err,具体因人而异),然后具体分析;