> CentOS > CentOS教程 >

CentOS6.5安装MySQL5.5

注:下载 MySQL Community Server下的Source Code包  否则会出现错误

1.安装准备

配置防火墙,开启3306端口:

[root@localhost src]# vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

注:这条规则应该添加到默认22端口的后面。(如上所示)

重启防火墙,使其配置生效:

[root@localhost src]# /etc/init.d/iptables restart

关闭SELINUX:

[root@localhost src]# vi /etc/selinux/config

在最后面添加如下信息:

SELINUX=disabled

:x        ←保存退出

重启系统,使其生效:

[root@localhost src]# shutdown -r now


查看当前版本信息:

[feng@localhost Tools]$ rpm -qa|grep mysql

mysql-libs-5.1.61-4.el6.x86_64

卸载当前较低版本:(需要root权限)

[root@localhost Tools]# yum -y remove mysql-libs-5.1.61-4.el6.x86_64


2.安装Cmake,为MySQL编译工具(版本:cmake-2.8.9.tar.gz,在/usr/local/src目录中)

安装gcc-c++,如果没有当执行./bootstrap时报错如下:

---------------------------------------------

CMake 2.8.9, Copyright 2000-2011 Kitware, Inc.

C compiler on this system is: cc

---------------------------------------------

Error when bootstrapping CMake:

Cannot find appropriate C++ compiler on this system.

Please specify one using environment variable CXX.

See cmake_bootstrap.log for compilers attempted.

---------------------------------------------

Log of errors: /usr/local/src/cmake-2.8.9/Bootstrap.cmk/cmake_bootstrap.log

---------------------------------------------

报错:缺少gcc-C++编译器

解决办法:安装gcc-c++编译器

[root@localhost src]# yum install gcc-c++        ←安装,选择y安装完成

[root@localhost src]# tar zxvf cmake-2.8.9.tar.gz    ←解压

[root@localhost src]# cd cmake-2.8.9

[root@localhost cmake-2.8.9]# ./bootstrap        ←同执行./configure

[root@localhost cmake-2.8.9]# gmake            ←编译

[root@localhost cmake-2.8.9]# gmake install        ←安装


3.正式安装

[root@localhost src]# tar zxvf mysql-5.5.27.tar.gz

[root@localhost src]# cd mysql-5.5.27

安装ncurses-devel包和bison包,否则执行cmake .时会出错

缺少ncurses-devel包信息如下:

-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)

CMake Error at cmake/readline.cmake:83 (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:127 (FIND_CURSES)

  cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)

  CMakeLists.txt:268 (MYSQL_CHECK_READLINE)

-- Configuring incomplete, errors occurred!

原因:缺少ncurses-devel包,需要先删除CMakeCache.txt,再进行安装

缺少bison包信息如下:

Warning: Bison executable not found in PATH

-- Configuring done

-- Generating done

-- Build files have been written to: /usr/local/src/mysql-5.5.27

原因:缺少bison包


为了避免出错,所以先安装ncurses-devel包和bison包

[root@localhost mysql-5.5.27]# yum install ncurses-devel

[root@localhost mysql-5.5.27]# yum install bison

配置用户和用户组:

[root@localhost mysql-5.5.27]# groupadd mysql                ←添加mysql用户组

[root@localhost mysql-5.5.27]# useradd -g mysql mysql -s /bin/false    ←创建mysql用户,并加入到mysql组,不允许mysql用户直接登录系统

[root@localhost mysql-5.5.27]# mkdir -p /data/mysql            ←创建数据库存放目录

[root@localhost mysql-5.5.27]# chown -R mysql:mysql /data/mysql/    ←设置数据库目录权限

[root@localhost mysql-5.5.27]# mkdir -p /usr/local/mysql        ←设置安装目录

[root@localhost mysql-5.5.27]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc    ←别漏了有个点。

[root@localhost mysql-5.5.27]# make && make install            ←时间较长


4.配置

[root@localhost mysql-5.5.27]# cd /usr/local/mysql/

[root@localhost mysql]# cp ./support-files/my-huge.cnf /etc/my.cnf    ←拷贝配置文件,若存在则覆盖

[root@localhost mysql]# vi /etc/my.cnf                    ←编辑,在[mysqld]下增加一行

datadir = /data/mysql

:x        ←保存退出

[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql        ←生成mysql系统数据库

[root@localhost mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld        ←把mysql加入系统启动

[root@localhost mysql]# chmod 755 /etc/init.d/mysqld        ←增加执行权限

[root@localhost init.d]# chkconfig mysqld on            ←加入开机启动

[root@localhost init.d]# vi /etc/rc.d/init.d/mysqld         ←编辑

basedir=/usr/local/mysql    ←mysql程序安装路径

datadir=/data/mysql        ←mysql数据存放vi 路径                  

[root@localhost mysql]# service mysqld start            ←启动

成功则提示:Starting MySQL..... SUCCESS!

将mysql服务加入系统环境变量

[root@localhost mysql]# vi /etc/profile                ←编辑

export PATH=$PATH:$JAVA_HOME/bin:/usr/local/mysql/bin        ←在最后加上:/usr/local/mysql/bin

[root@localhost mysql]# source /etc/profile            ←使其配置生效


5.设置密码

[root@localhost bin]# ./mysqladmin -u root password 123456    ←设置成功

设置成功后重新启动!

[root@localhost mysql]# service mysqld restart

6.删除匿名用户

[feng@localhost ~]$ mysql -u root -p            ←通过密码登录

Enter password:     ←输入密码

mysql> select user,host,password from mysql.user;    ←查看用户信息

mysql> delete from mysql.user where user="";        ←删除匿名用户





(责任编辑:IT)