CentOS6.3源码安装mysql5.5(多方法)

1.下载MySQL
我下载的版本:mysql-5.5.22.tar.gz

2.安装之前先卸载CentOS自带的MySQL
[root@localhost ~]# yum remove mysql

3.编译安装Cmake
下载cmake源码包:http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz

从共享目录移至usr目录
[root@localhost ~]# mv /mnt/hgfs/Share-CentOS/cmake-2.8.4.tar.gz /usr/cmake-2.8.4.tar.gz
[root@localhost ~]# cd /usr

解压并安装cmake
[root@localhost usr]# tar xzvf cmake-2.8.4.tar.gz
[root@localhost usr]# cd cmake-2.8.4
[root@localhost cmake-2.8.4]# ./bootstrap

---------------------------------------------
CMake 2.8.4, Copyright 2000-2009 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: /usr/local/src/cmake-2.8.4/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
报错:缺少C的编译器
解决办法:安装gcc编译器
[root@localhost ~]# yum install gcc

继续安装Cmake
[root@localhost cmake-2.8.4]# ./bootstrap

---------------------------------------------
CMake 2.8.4, Copyright 2000-2009 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.4/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
报错:缺少C++编译器 
解决办法:安装gcc-c++编译器
[root@localhost ~]# yum install gcc-c++

再次安装
[root@localhost cmake-2.8.4]# ./bootstrap 
没有报错,编译安装
[root@localhost cmake-2.8.4]# gmake
[root@localhost cmake-2.8.4]# gmake install

4.正式开始安装MySQL
添加MySQL用户和用户组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql

MySQL源码包从共享文件夹移至/usr并解压
[root@localhost ~]mv /mnt/hgfs/Share-CentOS/mysql-5.5.22.tar.gz /usr/mysql-5.5.22.tar.gz
[root@localhost usr]# tar xzvf mysql-5.5.22.tar.gz
[root@localhost usr]# cd mysql-5.5.22

Cmake运行
[root@localhost mysql-5.5.22]# cmake .

开始编译安装
[root@localhost mysql-5.5.22]# make && make install

进入安装目录,将程序二进制的所有权改为root,数据目录的说有权改为mysql用户,更新授权表
[root@localhost mysql-5.5.22]# cd /usr/local/mysql/
[root@localhost mysql]# chown -R root .
[root@localhost mysql]# chown -R mysql .
[root@localhost mysql]# chgrp -R mysql .
[root@localhost mysql]# scripts/mysql_install_db --user=mysql

安全启动MySQL(默认密码为空)
[root@localhost mysql]#./bin/mysqld_safe --user=mysql&

报错:

120908 00:16:25 mysqld_safe Logging to '/usr/local/mysql/data/CentOS.err'.
120908 00:16:26 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

解决方法:
[root@CentOS ~]# cd /usr/local/mysql/data

[root@CentOS data]# ls -l
总用量 29744
-rw-rw----  1 mysql root      1585 9月   8 00:16 CentOS.err
-rw-rw----  1 mysql mysql        6 9月   8 00:16 CentOS.pid
-rw-rw----  1 mysql mysql 18874368 9月   8 00:16 ibdata1
-rw-rw----  1 mysql mysql  5242880 9月   8 00:16 ib_logfile0
-rw-rw----  1 mysql mysql  5242880 9月   8 00:16 ib_logfile1
drwxr-xr-x  2 mysql mysql     4096 9月   8 00:14 mysql
-rw-rw----  1 mysql mysql    27293 9月   8 00:14 mysql-bin.000001
-rw-rw----  1 mysql mysql  1031892 9月   8 00:14 mysql-bin.000002
-rw-rw----  1 mysql mysql      107 9月   8 00:16 mysql-bin.000003
-rw-rw----  1 mysql mysql       57 9月   8 00:16 mysql-bin.index
drwx------  2 mysql mysql     4096 9月   8 00:14 performance_schema
drwxr-xr-x  2 mysql mysql     4096 9月   8 00:08 test
[root@CentOS data]# chgrp -R mysql CentOS.err
[root@CentOS data]# ls -l
总用量 29736
-rw-rw---- 1 mysql mysql     1585 9月   8 00:16 CentOS.err
-rw-rw---- 1 mysql mysql        6 9月   8 00:16 CentOS.pid
-rw-rw---- 1 mysql mysql 18874368 9月   8 00:16 ibdata1
-rw-rw---- 1 mysql mysql  5242880 9月   8 00:16 ib_logfile0
-rw-rw---- 1 mysql mysql  5242880 9月   8 00:16 ib_logfile1
drwxr-xr-x 2 mysql mysql     4096 9月   8 00:14 mysql
-rw-rw---- 1 mysql mysql    27293 9月   8 00:14 mysql-bin.000001
-rw-rw---- 1 mysql mysql  1031892 9月   8 00:14 mysql-bin.000002
-rw-rw---- 1 mysql mysql      107 9月   8 00:16 mysql-bin.000003
-rw-rw---- 1 mysql mysql       57 9月   8 00:16 mysql-bin.index
drwx------ 2 mysql mysql     4096 9月   8 00:14 performance_schema
drwxr-xr-x 2 mysql mysql     4096 9月   8 00:08 test

连接本机MySQL
[root@localhost mysql]#mysql –u root –p
提示输入password,默认为空,按Enter即可

断开连接
mysql>exit;

为root账户设置密码
[root@localhost ~]# cd /usr/local/mysql/bin
[root@localhost mysql]# ./bin/mysqladmin -u root password 123456
Enter Password:123456

设置选项文件,将配置文件拷贝到/etc下
[root@localhost mysql]# cp support-files/my-medium.cnf /etc/mysql.cnf

设置开机自启动
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# chmod +x /etc/init.d/mysql

通过服务来启动和关闭Mysql
[root@localhost ~]# service mysql start
[root@localhost ~]# service mysql stop

5.安装设置完毕,之后使用只需启动-连接-断开-关闭,命令如下:
[root@CentOS mysql]# service mysql start
Starting MySQL..                                           [确定]
[root@CentOS mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.22 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.07 sec)

mysql> exit;
Bye
[root@CentOS mysql]# service mysql stop
Shutting down MySQL.                                       [确定]

6.其它:
查看进程命令 ps –ef|grep mysqld
kill进程命令 kill –9 进程号

 

==================================================================

 

全新以最小化包安装了64位的CentOS6.3系统,作为本地的Web服务器使用,现记录全过程
第六步,安装mysql5.5数据库v5.5.28

mysql从5.5版本开始,不再使用./configure编译,而是使用cmake编译器,具体的cmake编译参数可以参考mysql官网文档(※ 非常重要)
http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

mysql-5.5.28.tar.gz源码包下载地址:
http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz

我的mysql目录配置如下:
安装路径:/usr/local/mysql
数据库路径:/data/mysql
源码包存放位置:/usr/software

准备工作:安装基本依赖包,先用yum安装cmake、automake 、autoconf ,另MySQL 5.5.x需要最少安装的包有:bison,gcc、gcc-c++、ncurses-devel
[root@localhost ~]# yum install cmake make -y
[root@localhost ~]# yum install gcc gcc-c++ autoconf bison automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* -y
[root@localhost ~]# cp /root/mysql-5.5.28.tar.gz /usr/software/
[root@localhost ~]# cd /usr/software
开始编译安装
[root@localhost ~]# tar -zxvf mysql-5.5.28.tar.gz
[root@localhost ~]# cd mysql-5.5.28
[root@localhost ~]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
        -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
        -DDEFAULT_CHARSET=utf8 \
        -DDEFAULT_COLLATION=utf8_general_ci \
        -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
        -DWITH_INNOBASE_STORAGE_ENGINE=1 \
        -DWITH_READLINE=1 \
        -DENABLED_LOCAL_INFILE=1 \
        -DMYSQL_DATADIR=/data/mysql/ \
        -DMYSQL_USER=mysql \
        -DMYSQL_TCP_PORT=3306
[root@localhost ~]# make && make install

mysql官网英文文档简单翻译说明一下
The MyISAM, MERGE, MEMORY, and CSV engines are mandatory (always compiled into the server) and need not be installed explicitly.(说明:mysql默认支持的数据库引擎有MyISAM, MERGE, MEMORY, CSV,无需在编译时再声明)
所以上面的编译条件省掉了如下两行
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
但INNODB一定要声明式安装,所以多了这一行
-DWITH_INNOBASE_STORAGE_ENGINE=1 \

查看mysql.mysql的用户及组是否存在


 
  

==================================================================

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="";        ←删除匿名用户

 

==================================================================

 

1.安装cmake

# cd/usr/local/src/tarbag 

# wget -c http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz

# tar zxvf cmake-2.8.3.tar.gz -C ../software

# cd ../software/cmake-2.8.3

# ./bootstrap

# make

# make install

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/services/mysql5.5 -DINSTALL_DATADIR=/data/mydata  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_MYISAM_STORAGE_ENGINE=1

Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)

yum install ncurses-devel

rm CMakeCache.txt 重新cmake

编译选项说明:

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql  //安装目录

-DINSTALL_DATADIR=/www/mydata //数据库存放目录

-DDEFAULT_CHARSET=utf8 //使用utf8字符

-DDEFAULT_COLLATION=utf8_general_ci  //校验字符

-DEXTRA_CHARSETS=all  //安装所有扩展字符集

-DWITH_SSL=system //使用SSL加密

-DWITH_EMBEDDED_SERVER=1 //编译成embedded mysql library

-DENABLED_LOCAL_INFILE=1 //允许从本地导入数据

-DWITH_MYISAM_STORAGE_ENGINE=1 //安装myisam引擎

3.新建用户

# useradd mysql -d /dev/null -s /sbin/nologin

4.配置

# chown -R mysql.mysql /usr/local/services/mysql5.5/

# chown -R mysql.mysql /www/mydata

# cd /usr/local/mysql

# cp ./support-files/my-medium.cnf /etc/my.cnf

# ./scripts/mysql_install_db --user=mysql

# chown -R  mysql.mysql /www/mydata

# ./bin/mysqld_safe --user=mysql &

# cp ./support-files/mysql.server /etc/init.d/mysqld

# chmod +x /etc/init.d/mysqld

# chkconfig --add mysqld

# chkconfig mysqld on

# service mysqld restart

若提示/etc/init.d/mysqld: line 256: my_print_defaults: command not found

MySQL server PID file could not be found!  

编辑/etc/init.d/mysqld 46,47行basedir和datadir变量。

你可能感兴趣的:(mysql,centos)