软件源码包存放位置 /usr/local
源码包编译安装位置 /usr/local/mysql
现在的MySQL都使用Cmake进行编译安装,所以在安装MySQL之前我们首先要把Cmake装在我们的系统上。
我们所需要的软件源码包有以下:
cmake-2.8.9.tar.gz
mysql-5.5.27.tar.gz
mysql-5.5.27下载地址:http://cdn.mysql.com/Downloads/MySQL-5.5/MySQL-server-5.5.27-1.linux2.6.x86_64.rpm
1、安装Cmake
#安装所需依赖关系
yum -y install ntp vim-enhanced gcc gcc-c++ flex bison autoconf automake bzip2-devel ncurses-devel zlib-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel libxml2-devel curl-devel libicu libicu-devel libmcrypt libmcrypt-devel libmhash libmhash-devel
#下载Cmake的源码包
#编译安装
tar zxvf cmake-2.8.9.tar.gz
cd cmake-2.8.9
./configure
make && make install
2、编译安装配置MySQL
#创建所需目录
mkdir -pv /usr/local/mysql/data
#创建mysql用户和mysql组
groupadd mysql
useradd -g mysql -s /usr/sbin/nologin mysql
#解压源码包
mysql-5.5.27.tar.gz
cd mysql-5.5.27
#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
#安装
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 -R mysql:mysql /usr/local/mysql/data
#配置开机自动启动
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
#修改配置文件
vim /etc/my.cnf
#在[mysqld]中添加:
datadir = /usr/local/mysql/data
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
service mysqld start
#测试MySQL是否启动
#查看是否有mysql进程
ps -ef | grep mysql
#查看是否有mysql端口
netstat -tnlp | grep 3306
ln -sv /usr/local/mysql/bin/mysql mysql
ln -sv /usr/local/mysql/bin/mysqladmin mysqladmin
ln -sv /usr/local/mysql/bin/mysqldump mysqldump
或者编辑/etc/profile在最后添加 #如果添加软连接还是找不到命令,就写到环境变量中。
PATH=$PATH:/usr/local/mysql/bin
#重读/etc/profile文件
source /etc/profile
#读取MySQL的版本信息
mysqladmin version
#测试登录mysql
mysql -u root -p
mysql> #可以登录,mysql编译安装成功
到此MySQL编译安装完成