Linux下安装LAMP环境之安装MySQL
1、安装MySQL之前,需要安装cmake,因为cmake对软件源码进行编译。
前提:通过挂载把U盘中所需要的软件全部拷贝到系统的/root/soft
cmake源码包cmake-2.8.8.tar.gz,/root/soft/soft目录下
[root@localhost ~]# cd /root/soft/soft
[root@localhost /root/soft/soft]# tar -xzvf cmake-2.8.8.tar.gz
[root@localhost /root/soft/soft]# cd cmake-2.8.8
[root@localhost cmake-2.8.8]# ./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编译器
可以简单地用yum安装
[root@localhost ~]# yum install gcc
继续cmake的安装
[root@localhost cmake-2.8.8]# ./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++编译器
简单地用yum安装
[root@localhost ~]# yum install gcc-c++
[root@localhost cmake-2.8.8]# ./bootstrap
没有报错后,编译安装
[root@localhost cmake-2.8.8]# gmake
[root@localhost cmake-2.8.8]# gmake install
检查安装 which cmake看结果可知安装是否正确
2、正式安装MySQL
mysql的源码包mysql-5.5.24.tar.gz 在/root/soft/soft目录下
[root@localhost ~]# cd /root/soft/soft
[root@localhost /root/soft/soft]# tar -xzvf mysql-5.5.24.tar.gz
root@localhost /root/soft/soft]# cd mysql-5.5.24
[root@localhost mysql-5.5.24]# cmake .
报错:
-- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:82 (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:126 (FIND_CURSES) cmake/readline.cmake:216 (MYSQL_USE_BUNDLED_LIBEDIT) CMakeLists.txt:250 (MYSQL_CHECK_READLINE) -- Configuring incomplete, errors occurred!
解决办法:
[root@localhost mysql-5.5.24]# yum -y install ncurses-devel*
[root@localhost mysql-5.5.24]# rm CMakeCache.txt
[root@localhost mysql-5.5.24]# cmake .
还是有个警告:
[root@localhost mysql-5.5.24]# yum install bison
[root@localhost mysql-5.5.24]# cmake .
[root@localhost mysql-5.5.24]# make && make install(完成编译安装)
添加mysql用户和用户组
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
进入安装目录,将程序二进制的所有权改为root,数据目录的所有权改为mysql用户,更新授权表
[root@localhost mysql-5.5.24]# 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 (初始化数据库)
[root@localhost mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data (安全启动mysql )
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql(关闭mysql )
[root@localhost mysql]# ./bin/mysqladmin -u root shutdown -p
默认密码为空--方便调用,为mysql设置一个软链接
[root@localhost ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
其他设置处理:
设置选项文件,将配置文件拷贝到/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
[root@localhost mysql]# chkconfig –add mysqld
[root@localhost mysql]# chkconfg mysqld on
现在可以通过服务来启动和关闭Mysql服务器
[root@localhost ~]# service mysql start
[root@localhost ~]# service mysql shutdown
连接服务器
[root@localhost ~]# mysql -u root -p