日期:2014-05-16  浏览次数:20672 次

linux下mysql源码安装
查看已经安装的mysql:rpm -qa|grep mysql
删除旧版本: rpm -e --nodeps mysql-4.1.20-2.RHEL4.1
             rpm -e --nodeps mysql-server-4.1.20-2.RHEL4.1

一、      使用源码安装
[root@band-all mysql]# cd /usr/local
[root@band-all mysql]# rz mysql-5.1.48.tar
[root@ band-all local]# groupadd mysql
[root@ band-all local]# useradd -g mysql mysql
tar -xvf mysql-5.1.48.tar
[root@band-all mysql]# cd /usr/local/mysql-5.1.48/
[root@ band-all mysql-5.1.48]# ./configure --prefix=/usr/local/mysql --with-plugins=innobase
[root@band-all mysql-5.1.48]# make && make install
[root@band-all mysql-5.1.48]# chown -R mysql:mysql /usr/local/mysql/
[root@band-all support-files]#
cp  /usr/local/mysql-5.1.48/support-files/my-medium.cnf /etc/my.cnf
创建数据目录
mkdir -p /data/mysqldata/

数据库装好后修改数据存储目录
vi  /etc/my.cnf
[mysqld]
default-character-set=utf8
lower_case_table_names=1
skip-external-locking
datadir = /data/mysqldata
default-storage-engine=INNODB

这里默认basedir是/usr/local/mysql所以不用配置

拷贝之前的数据文件
cp /usr/local/mysql/var/*  /data/mysqldata -R
chown -R mysql.mysql /data/mysqldata/

[root@band-all support-files]# cp /usr/local/mysql-5.1.48/support-files/mysql.server /etc/init.d/mysqld

[root@band-all support-files]# /usr/local/mysql/bin/mysql_install_db --user=mysql
[root@band-all support-files]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@band-all mysql]# chmod 755 /etc/init.d/mysqld
[root@band-all mysql]# chkconfig --add mysqld
[root@band-all mysql]# chkconfig mysqld on
[root@band-all mysql]# service mysqld start

/etc/profile中指定环境变量
export MYSQL_HOME=/usr/local/mysql
export PATH=$JAVA_HOME/bin:$MYSQL_HOME/bin:$PATH

source /etc/profile

创建用户
/usr/local/mysql/bin/mysqladmin -u root -h localhost password 'root'