首页 > 代码库 > 两个版本mysql的安装

两个版本mysql的安装

安装mysql方式有:源码包、RPM包(比较老)和二进制包。

安装mysql 5.1.50:

1、安装依赖包

#yum -y install gccgcc-c++ ncurses ncurses-devel openssl openssl-devel libtool*


2、创建用户:

# groupadd mysql

# useradd mysql –g mysql –s /sbin/nologin


3、安装Mysql 

# tar –xvf mysql-5.1.50.tar.gz

#cd mysql-5.1.50

# ./configure  ‘--prefix=/usr/local/services/mysql‘ ‘--localstatedir=/data/dbdata/‘ ‘--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock‘ ‘--with-charset=utf8‘ ‘--with-extra-charsets=complex‘ ‘--with-pthread‘ ‘--enable-thread-safe-client‘ ‘--with-ssl‘ ‘--with-client-ldflags=-all-static‘ ‘--with-mysqld-ldflags=-all-static‘ ‘--with-plugins=partition,federated,ndbcluster,innobase,csv,blackhole,myisam,innodb_plugin,heap,archive‘ ‘--enable-shared‘ ‘--enable-assembler‘

# make && make install

解释

--prefix 指定 Mysql 安装目录 (必须)

--localstatedir 指定Mysql数据存储目录(必须)

--with-unix-socket-path 执行socke存放位置(必须) 

--with-charset 指定默认字符集

--with-extra-charsets 可以扩展复杂字符集

--with-pthread 强制使用pthread类库

--enable-thread-safe-client 使用编译客户端;(让客户端支持线程的意思)

--with-ssl  启用SSL的支持

--with-client-ldflags=-all-static 静态编译MySQL客户端;(静态链接提高13%性能)

--with-mysqld-ldflags=-all-static 静态编译MySQL服务器端;(静态链接提高13%性能)

--with-plugins MySQL服务器端支持的存储引擎

--enable-shared 共享变异模块

--enable-assembler 使用汇编模式提高效率


4、初始化

# mkdir /data/dbdata/

# chown -R mysql:mysql /usr/local/ services/mysql

# chown -R mysql:mysql /data/dbdata/

/usr/local/services/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/services/mysql --datadir=/data/dbdata/

# cp /usr/local/services/mysql/share/mysql/mysql.server /etc/init.d/mysqld

# chmod 755 /etc/init.d/mysqld

# vim /etc/init.d/mysqld

basedir=/usr/local/services/mysql

datadir=/data/dbdata/


5、配置文件

#cp support-files/my-medium.cnf /etc/my.cnf

# vim /etc/my.cnf


6、启动服务和设置环境变量

#:vim /etc/profile

MYSQL=/usr/local/services/mysql/bin

PATH=$PATH:$MYSQL

export PATH

#source /etc/profile

启动服务

# /etc/init.d/mysqld start



Mysql5.6源码包安装:

yum install vim-enhanced cmake gcc gcc-c++ ncurses-devel bison make -y

groupadd -g 27 mysql

useradd -u 27 -g mysql -s /sbin/nologin  -M mysql 

mkdir /database

cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql5.6 -DMYSQL_DATADIR:PATH=/database/ -DSYSCONFDIR:PATH=/usr/local/mysql5.6/etc -DWITH_DEBUG:BOOL=on

cmake (-LH)生成 CMakeCache.txt  然后服务于make

编译错误删除CMakeCache.txt后重新编译

man make cmake 的选项-L -D

mysqld d即为组

[root@localhost mysql5.6]#mkdir  etc ;cp /etc/my.cnf etc/my.cnf

[mysqld]

basedir=/usr/local/mysql5.6

datadir=/database

socket=/var/run/mysqld/mysql5.6.sock

pid-file=/var/run/mysqld/mysql5.6.pid

user=mysql

port=3307 一般是3306、设置3307为了与rpm等包共存(此次是编译安装)

上面存储地自定义最好不要与其他包目录杂揉

[mysqld_safe]

log-error=/var/log/mysqld/mysqld.log

手工创建不存在的文件夹 /var/run/mysqld  /var/log/mysqld

[root@localhost mysql5.6]#chown -R mysql:mysql /usr/local/mysql5.6 /database /var/run/mysqld /var/log/mysqld

[root@localhost mysql5.6]# pwd

/usr/local/mysql5.6

[root@localhost mysql5.6]# vim scripts/mysql_install_db (启动)

[root@localhost scripts]# #./mysql_install_db --basedir=/usr/local/mysql5.6/ --datadir=/database --user=mysql 

-bash: ./mysql_install_db: 权限不够 (chmod +x mysql_install_db)

(上面生成下面文件)

[root@localhost scripts]# ls /database/  

ibdata1  ib_logfile0  ib_logfile1  mysql  performance_schema  test

[root@localhost support-files]# cp -v mysql.server /etc/rc.d/init.d/mysql5.6

"mysql.server" -> "/etc/rc.d/init.d/mysql5.6"

[root@localhost support-files]# vim /etc/init.d/mysql5.6 

conf=/usr/local/mysql5.6/etc/my.cnf  修改

[root@localhost support-files]# chkconfig  --add mysql5.6

[root@localhost support-files]# service mysql5.6 restart

ps aux |grep mysql   #(有root和mysql用户启动分别文件)

[root@localhost wan]# ls /var/run/mysqld/   #(服务启动才有)

mysql5.6.pid  mysql5.6.sock

[root@localhost ~]# /usr/local/mysql5.6/bin/mysql

ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)    # /tmp下面没有

[root@localhost ~]# mysql -S /var/run/mysqld/mysql5.6.sock   # 指定,与rpm包不同

# #5.1客户端登录

# /usr/local/mysql5.6/bin/mysql -S /var/lib/mysqld/mysql.sock   # 5.6客户端访问5.1的rpm包   yum install mysql mysql-devel mysql-server php-mysql # service mysqld restart


贴上安装mysql脚本:

#!/bin/bash
#./mysql.sh mysql-5.6.17.tar.gz
name1="$1"
name2=${name1/.tar.gz/}
if ! grep -qi "^mysql" /etc/group; then
groupadd -g 27 mysql
fi
if ! id mysql >/dev/null 2>&1; then
useradd -u 27 -g mysql -s /sbin/nologin -M mysql
fi
yum install -y cmake make gcc gcc-c++ ncurses-devel bison >/dev/null 2>&1
[ -d /usr/local/mysql5.6 ] && rm -rf /usr/local/mysql5.6
[ -d /database ] && rm -rf /database/* || mkdir /database
if [ -d "$name2" ]; then
[ -e "$name2/CMakeCache.txt" ] && rm -f "$name2/CMakeCache.txt"
else
tar xf "$name1"
fi
cd $name2
#cmake -LH 产生CMakeCache.txt, make就按这个cache文件来编译
#man cmake
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql5.6 -DMYSQL_DATADIR:PATH=/database -DSYSCONFDIR:PATH=/usr/local/mysql5.6/etc -DWITH_DEBUG:BOOL=on
make
make install
mkdir /usr/local/mysql5.6/etc
cat <<! >/usr/local/mysql5.6/etc/my.cnf
[mysqld]
basedir=/usr/local/mysql5.6
datadir=/database
socket=/var/run/mysqld/mysql5.6.sock
pid-file=/var/run/mysqld/mysql5.6.pid
port=3307
user=mysql
[mysqld_safe]
log-error=/var/log/mysqld/mysql5.6-error.log
!
[ -d /var/run/mysqld ] && rm -rf /var/run/mysqld/* || mkdir /var/run/mysqld
[ -d /var/log/mysqld ] && rm -rf /var/log/mysqld/* || mkdir /var/log/mysqld
chown -R mysql.mysql /usr/local/mysql5.6 /database /var/run/mysqld /var/log/mysqld
/usr/local/mysql5.6/scripts/mysql_install_db --basedir=/usr/local/mysql5.6 --datadir=/database --user=mysql
cp /usr/local/mysql5.6/support-files/mysql.server /etc/rc.d/init.d/mysql5.6
sed -i ‘/conf=/c conf=/usr/local/mysql5.6/etc/my.cnf‘ /etc/rc.d/init.d/mysql5.6
chkconfig --add mysql5.6
service mysql5.6 start


本文出自 “8430296” 博客,请务必保留此出处http://8440296.blog.51cto.com/8430296/1582118

两个版本mysql的安装