Linux源码安装MySQL5.5.11

环境
系统版本:cenos 6.2
MySQL版本:mysql-5.5.11


一、准备环境
1.建立mysql安装目录及数据存放目录
[root@localhost local]# mkdir -p /usr/local/mysql                   //安装mysql
[root@localhost local]# mkdir -p /usr/local/mysql/data                 //存放数据库

2.创建myql用户和用户组
[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql mysql

3.赋予数据存放目录权限
[# chown -R root:mysql . //把当前目录中所有文件的所有者设为root,所属组为mysql]
[root@localhost local]# chown mysql:mysql -R /usr/local/mysql/data

4.安装cmake[mysql5.5以后是通过cmake来编译的]
可以在http://www.cmake.org网站下载cmake-2.8.4.tar.gz,上传并移动至/usr/local目录下
[root@localhost local]# tar zxvf cmake-2.8.4.tar.gz
[root@localhost local]# cd cmake-2.8.4
[root@localhost cmake-2.8.4]# ./configure  --prefix=/usr/local/cmake

CMake has bootstrapped.  Now run gmake.
[root@localhost cmake-2.8.4]# gmake
[root@localhost cmake-2.8.4]# gmake install

[root@localhost cmake-2.8.4]# ln -s /usr/local/cmake/bin/cmake /usr/local/bin/cmake  

[root@localhost cmake-2.8.4]# cmake --version 

cmake version 2.8.4

 

 

二、安装mysql
1.在mysql的网站下载mysql最新版本.地址是:http://dev.mysql.com/downloads/mysql/
上传并移动至/usr/local/mysql目录下

2.解压mysql-5.5.20
[root@localhost local]#tar zxvf mysql-5.5.20.tar.gz
[root@localhost local]# cd mysql-5.5.20
[root@localhost mysql-5.5.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

[root@localhost mysql-5.5.20]# make
[root@localhost mysql-5.5.20]# make instll

参数说明:
-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                        //允许从本地导入数据

注意事项
重新编译时,需要清除旧的对象文件和缓存信息。
[root@localhost mysql-5.5.20]# make clean
[root@localhost mysql-5.5.20]# rm -f CMakeCache.txt
[root@localhost mysql-5.5.20]# rm -rf /etc/my.cnf


4.把mysql的启动服务设置为系统服务
[root@localhost mysql-5.5.20]# cp support-files/my-medium.cnf /etc/my.cnf

5.初始化数据库
#cd /user/local/mysql
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
注:basedir:mysql安装路径  datadir:数据库文件储存路径

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


7.配置环境变量
将mysql的bin目录加到PATH中,有利于以后管理与维护,在/etc/profile中加入mysql/bin,同时增加两个别名方便操作:
# export PATH=/usr/local/mysql/bin:$PATH
# alias mysql_start="mysqld_safe&"
# alias mysql_stop="mysqladmin -u root -p shutdown"

8.启动mysql服务
# /etc/init.d/mysql start
启动之后用ps -ef|grep mysql命令查看是否启动

9.登录mysql
# mysql -u root -p

 

三、安装遇到的问题
1.没有安装 gcc 和 gcc-c++,安装MYSQL执行cmake报如下错误:

[root@ice mysql-5.5.27]# cmake .
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found.   Please set CMAKE_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.
.
-- Configuring incomplete, errors occurred!
==================================================

解决方法:安装gcc和gcc-c++

[root@localhost mysql-5.5.20]yum install gcc
[root@localhost mysql-5.5.20]yum install gcc-c++
#删除cache文件,不删除还会报错
[root@localhost mysql-5.5.20]rm CMakeCache.txt 
[root@localhost mysql-5.5.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

 

2.没有安装 ncurses-devel,安装MYSQL执行cmake报如下错误:

-- 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:257 (MYSQL_CHECK_READLINE)


-- Configuring incomplete, errors occurred!

解决方法:

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

[root@localhost mysql-5.5.20]#rm CMakeCache.txt
[root@localhost mysql-5.5.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

 

3.bash:mysql:command not find
原因是mysql命令的路径在/usr/local/mysql/bin下面,所以你直接使用mysql命令时,系统在/usr/bin下面查此命令,所以找不到了。
解决方法:做个软链接即可。
# ln -s /usr/local/mysql/bin/mysql /usr/bin

 

4.如果myql不能远程连接,出现错误mysql error number 1130,则加入下面语句试试:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '******' WITH GRANT OPTION;

                                                                                                                                                5.[root@localhost mysql]# /etc/init.d/mysql status

ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

解决方法:rm -rf /var/lock/subsys/mysql

然后启动mysql,一切正常了,这里的可能原因就是可能和log文件有关,于是将log文件给移除了,再重启MySQL终于OK了。

 

6.[root@localhost init.d]# /etc/init.d/mysql start

Starting MySQL. ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).

未解决。

 

 

posted @ 2012-11-12 15:20  阳光温暖了心情  阅读(1962)  评论(0编辑  收藏  举报