首页 > 代码库 > 安装mysql

安装mysql

0、安装gcc:yum install gcc
1、下载源码包(注意是源码包)
2、上传并解压:tar -zxvf mysql-5.x.xx.tar.gz
3、建立目标文件夹:mkdir /usr/local/mysql
4、mysql5.5以后用cmake安装,老版本还是用./configure
5、安装cmake,源码包下载地址:http://www.cmake.org/download/

1)tar zxvf cmake-2.8.4.tar.gz
2)cd cmake-2.8.4
3)./configure --prefix=/usr/local/cmake
4)make && make install

6、创建mysql用户和组
groupadd mysql //建一个msyql的用户和组
useradd -g mysql mysql -s /usr/sbin/nologin
7、创建目录
mkdir /usr/local/mysql //创建目录
mkdir /usr/local/mysql/data
8、进入mysql源码目录顺序执行:cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql && make && make install
注意:如果cmake这一步出现:cmake :command not found,执行:export PATH=/usr/local/cmake/bin:$PATH
9、出现错误: Could NOT find Curses,安装:yum install ncurses-devel
10、移除CMakecache.txt并再次执行cmake&make&makeinstall
11、安装完成以后进入mysql安装目录:
1)初始化mysql数据库:scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
2)复制配置文件:cp support-files/my-medium.cnf /usr/local/mysql/my.cnf
3)更改权限:chown -R mysql:mysql /usr/local/mysql
4)编辑my.cnf,添加以下内容:
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
log-error = /usr/local/mysql/mysql_error.log
pid-file = /usr/local/mysql/mysql.pid
user = mysql
tmpdir = /tmp
5)启动mysql bin/mysqld_safe --user=mysql &
或使用下列命令把mysql添加为系统服务。
cd /usr/local/mysql/support-files/
cp ./mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld start
12)执行mysql命令时 出错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘
由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,但linux系统总是去/tmp/mysql.sock查找,所以会报错,有两种方法:
1.直接指定mysql通道: mysql --socket=/var/lib/mysql/mysql.sock
2. 创建符号连接:ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

 

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

参考和引用:

isqlw:《使用cmake安装mysql5.5.13 》http://blog.chinaunix.net/uid-10435474-id-2957157.html
CodeWall:《Linux下配置安装PHP环境》 http://www.cnblogs.com/lufangtao/archive/2012/12/30/2839679.html

安装mysql