题记: MYSQL 也安装了很多次,每次找上次安装的脚本,都是无头苍蝇,遂记此文。
此文参考了 http://www.cnblogs.com/fly1988happy/archive/2011/11/21/2257682.html
文中每个步骤都是边装边写,如有纰漏望指正。
一 安装版本
1.1 软件版本
cmake-3.0.1.tar.gz
mysql-5.6.20.tar.gz
系统版本:
[root@nfs-1 soft]# lsb_release LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch [root@nfs-1 soft]# lsb_release -a LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch Distributor ID: CentOS Description: CentOS release 6.6 (Final) Release: 6.6 Codename: Final
系统一般不默认带lsb_release 命令,yum install lsb
cmake,mysql下在地址
http://pan.baidu.com/s/1qWmiBhE
http://pan.baidu.com/s/1kT8Dyth
二 安装cmake 和mysql
2.1 安装cmake
[root@nfs-1 soft]# tar -zxvf cmake-3.0.1.tar.gz [root@nfs-1 soft]# cd cmake-3.0.1 [root@nfs-1 cmake-3.0.1]# ./configure
执行报错,信息如下
[root@nfs-1 cmake-3.0.1]# ./configure --------------------------------------------- CMake 3.0.1, Copyright 2000-2014 Kitware, Inc. --------------------------------------------- Error when bootstrapping CMake: Cannot find appropriate C compiler on this system. Please specify one using environment variable CC. See cmake_bootstrap.log for compilers attempted. --------------------------------------------- Log of errors: /wls/wls81/soft/cmake-3.0.1/Bootstrap.cmk/cmake_bootstrap.log ---------------------------------------------
解决方法:yum 安装gcc c++
[root@nfs-1 cmake-3.0.1]# yum install gcc-c++
然后执行
[root@nfs-1 cmake-3.0.1]# ./configure
就可以了
最后执行
[root@nfs-1 cmake-3.0.1]# make [root@nfs-1 cmake-3.0.1]# make install
至此cmake 安装完成,若版本不通请参照cmake 官网
验证
[root@nfs-1 cmake-3.0.1]# cmake -version cmake version 3.0.1 CMake suite maintained and supported by Kitware (kitware.com/cmake).
2.2 安装mysql
2.2.1 创建mysql 的安装目录和数据库存放目录
mysql 安装目录:/usr/local/mysql
mysql 数据库存放目录 :/usr/local/mysql/data
[root@nfs-1 local]# mkdir -p /usr/local/mysql [root@nfs-1 local]# mkdir -p /usr/local/mysql/data
2.2.2 创建mysql 用户和用户组
[root@nfs-1 local]# groupadd mysql [root@nfs-1 local]# useradd -r -g mysql mysql
2.2.3 解压源码包安装
[root@nfs-1 soft]# tar -zxvf mysql-5.6.20.tar.gz [root@nfs-1 soft]# cd mysql-5.6.20 [root@nfs-1 mysql-5.6.20]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
cmake 时报错
Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:85 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel. Call Stack (most recent call first): cmake/readline.cmake:128 (FIND_CURSES) cmake/readline.cmake:202 (MYSQL_USE_BUNDLED_EDITLINE) CMakeLists.txt:427 (MYSQL_CHECK_EDITLINE) -- Configuring incomplete, errors occurred! See also "/wls/wls81/soft/mysql-5.6.20/CMakeFiles/CMakeOutput.log". See also "/wls/wls81/soft/mysql-5.6.20/CMakeFiles/CMakeError.log".
解决方法 :查看错误信息,redhat 系统需要安装ncurse-devel
[root@nfs-1 soft]# yum install ncurses-devel
然后重新 执行
重新编译需要执行
# make clean
# rm -f CMakeCache.txt
# rm -rf /etc/my.cnf
我是直接删除了原先解压的包,重新解压了一份
[root@nfs-1 mysql-5.6.20]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1
就可以了
参数说明
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql //安装目录
-DINSTALL_DATADIR=/usr/local/mysql/data //数据库存放目录
-DDEFAULT_CHARSET=utf8 //使用utf8字符
-DDEFAULT_COLLATION=utf8_general_ci //校验字符
-DEXTRA_CHARSETS=all //安装所有扩展字符集
-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据
补充20150812(上次忘写了):mysql cmake 执行完需要 make && make install
2.2.4 配置
2.2.4.1 配置目录权限
mysql 安装目录改为 所有者root,组mysql
mysql 数据存放目录改为所有者mysql,组mysql
[root@nfs-1 mysql]# pwd /usr/local/mysql [root@nfs-1 mysql]# chown -R root:mysql chown: missing operand after `root:mysql' Try `chown --help' for more information. [root@nfs-1 mysql]# chown -R root:mysql . [root@nfs-1 mysql]# chown -R mysql:mysql data
2.2.4.2 将mysql配置文件复制到/etc/my.cnf
cd /usr/local/mysql/ cp support-files/my-default.cnf /etc/my.cnf
2.2.4.3 创建系统数据库表
cd /usr/local/mysql/ ./scripts/mysql_install_db --user=mysql
2.2.4.4 设置root 用户环境变量(可选)
[root@ rhel5~]# vi /root/.bash_profile #在PATH=$PATH:$HOME/bin添加参数为: PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib [root@ rhel5~]#source /root/.bash_profile
2.2.4.5 手动启动mysql
[root@ rhel5~]# cd /usr/local/mysql [root@ rhel5 mysql]# ./bin/mysqld_safe --user=mysql & //启动MySQL,但不能停止 启动日志写在此文件下:/usr/local/mysql/data/localhost.err 关闭MySQL服务 [root@ rhel5 mysql]# mysqladmin -u root -p shutdown //这里MySQL的root用户还没有配置密码,所以为空值。需要输入密码时,直接点回车键即可。
2.2.4.6 配置系统服务启动mysql
[root@nfs-1 mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@nfs-1 mysql]# service mysql start Starting MySQL.[ OK ] [root@nfs-1 mysql]#
2.2.4.7 修改root 密码
[root@ rhel5~]# mysql -u root mysql mysql>use mysql; mysql>desc user; mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //为root添加远程连接的能力。 mysql>update user set Password = password('yunwei@root') where User='root'; mysql>select Host,User,Password from user where User='root'; mysql>flush privileges; mysql>exit 重新登录:mysql -u root -p 若还不能进行远程连接,则关闭防火墙 [root@ rhel5~]# /etc/rc.d/init.d/iptables stop
好的完成。。。。。
tac 于 20150625