IT教程 | 加入收藏 | 简体 | 繁体
Linux&Unix服务器:IIS服务器Apache服务器Tomcat服务器其它整合Windows服务器Linux&Unix...
当前位置: 首页 > 服务器 > Linux&Unix服务器

CentOS6通过源码编译安装MySQL5.5教程

2014-07-14来源:[www.121ask.com]热度:0℃ 【字体:

CentOS6通过源码编译安装MySQL5.5教程:

1.到chinaunix下载MySQL
下载地址:http://download.chinaunix.net/download/0008000/7159.shtml
我下载的版本: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&

报错:
090408 21:19:24 mysqld_safe Logging to '/var/log/mysqld.log'.
090408 21:19:24 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
090408 21:19:24 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

原因:
打开/var/log/mysqld.log文件得到Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)
Can't start server: can't create PID file: No such file or directory
解决方法:
进入/var/run目录,发现没有mysqld目录,建立mysqld目录,进入该目录再建立mysqld.pid文件,修改文件属性 chown -R mysql mysqld .从而解决该问题

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

断开连接
mysql>exit;

关闭MySQL
[root@localhost mysql]# ./bin/mysqladmin -u root shutdown –p

报错:
bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

原因:
进入/var/lib/mysql目录,发现mysql.sock文件
解决方法:
建立连接 ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock 解决该问题

方便调用,为mysql设置一个软链接
[root@localhost ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

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

设置选项文件,将配置文件拷贝到/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 shutdown

报错:启动mysql报错
Starting MySQL…The server quit without updating PID file (/usr/local/mysql/data/CentOS.pid). [失败]

解决方法:
在 my.cnf 中
#The MySQL server
[mysqld]
port        = 3306
socket        = /tmp/mysql.sock
……
下面增加
datadir=/var/lib/mysql
[safe_mysqld]
err-log=/var/log/mysqld.log
pid-file=/var/lib/mysql/CentOS.pid

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 进程号


 

以上IT文章《CentOS6通过源码编译安装MySQL5.5教程》由名客技术网[www.121ask.com]提供阅读!
名客技术网是一个免费为广大IT技术人员提供IT教程,绿色软件,asp/php/jsp/java/net等实例视频教程,CMS教程,破解软件下载以及学习相关源码、知识的IT网站。
名客技术网如果无意之中侵犯了您的版权,请来电告知,本站将在3个工作日内删除 QQ:175352796
Copyright 2011-2017 Powered by 121ASK.COM, All Rights Reserved.
备案号:鄂ICP备11013833号-3