安装MysqL
useradd MysqL //已经有的不需要创建
卸载原来的MysqLrpm包
yum -y remove *MysqL*//我这里用yum卸载的
service iptables stop //个人习惯性关闭防火墙
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config
setenforce 0
安装所需依赖包
yum -y install make gcc gcc-c++ gcc-gfortran flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof
安装cmake
MysqL5.6版本后需要cmake来配置编译
tar -zxvf cmake-2.8.5.tar.gz
cd cmake-2.8.5
./configure
gmake && gmake install
开始安装MysqL
tar -zxvf MysqL-5.6.4-m7.tar.gz
cd MysqL-5.6.4-m7
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \
-DMysqL_DATADIR=/usr/local/MysqL/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMysqL_UNIX_ADDR=/var/lib/MysqL/MysqL.sock \
-DMysqL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DWITH_SSL=system
make && make install
============================================******************************************============================================================
单实例的的安装操作
安装完相关操作
chmod +w /usr/local/msyql
chown -R MysqL.MysqL /usr/local/MysqL
//在启动MysqL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索”$basedir/my.cnf” 就是安装目录下/usr/local/MysqL/my.cnf,这是新版MysqL的配置文件的默认位置! 注意:在CentOS 6.x版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字。 如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MysqL的正确配置,造成无法启动。 由于我们已经卸载了最小安装完成后的mysq库所以,就没必要操作了。
cd support-files/
如果还有my.cnf请备份
mv /etc/my.cnf /etc/my.cnf.bak
复制配置文件到etc下
cp my-medium.cnf /etc/my.cnf
//执行初始化配置脚本,创建系统自带的数据库和表,注意配置文件的路径
/usr/local/MysqL/scripts/MysqL_install_db �defaults-file=/etc/my.cnf �basedir=/usr/local/MysqL �datadir=/usr/local/MysqL/data �user=MysqL
//拷贝MysqL安装目录下support-files服务脚本到init.d目录
#拷贝脚本
cp support-files/MysqL.server /etc/init.d/MysqLd
#赋予权限
chmod +x /etc/init.d/MysqLd
#设置开机启动
chkconfig MysqLd on
#启动MysqL
service MysqLd start 或者 /etc/init.d/MysqL start
MysqL5.6.x启动成功后,root默认没有密码,我们需要设置root密码。 设置之前,我们需要先设置PATH,要不,不能直接调用MysqL
vim /etc/profile
PATH=/usr/local/MysqL/bin:$PATH
#让配置立即生效
source /etc/profile
#登陆测试,默认是没有密码,直接回车就可进入
MysqL -uroot -p
MysqLadmin -u root password “newpass”
#如果root已经设置过密码,采用如下方法
MysqLadmin -uroot -ppassword password “newpass”
#验证MysqL安装路径
ls -ld /usr/local/MysqL/
============================================******************************************============================================================
多实例的的安装操作
接着上面源码包安装完成开始
mkdir -pv /usr/local/MysqL/data/{3306,3307,3308}
chown -R MysqL.MysqL /usr/local/MysqL/data/
2,初始化数据库
cd /usr/local/MysqL
scripts/MysqL_install_db �user=MysqL �basedir=/usr/local/MysqL �datadir=/usr/local/MysqL/data/3306/
scripts/MysqL_install_db �user=MysqL �basedir=/usr/local/MysqL �datadir=/usr/local/MysqL/data/3307/
scripts/MysqL_install_db �user=MysqL �basedir=/usr/local/MysqL �datadir=/usr/local/MysqL/data/3308/
cd bin
./MysqLd_multi �example > /usr/local/MysqL/data/multi.cnf
vim /usr/local/MysqL/data/multi.cnf
[MysqLd_multi]cd
MysqLd = /usr/local/MysqL/bin/MysqLd_safe
MysqLadmin = /usr/local/MysqL/bin/MysqLadmin
user = root
#password = root #设置了密码后一定要开启,不然命令停止会有问题 (三个实例数据库密码一样)
[MysqLd1]
socket = /tmp/MysqL.sock1
port = 3306
pid-file = /usr/local/MysqL/data/3306/MysqL.pid
datadir = /usr/local/MysqL/data/3306/
[MysqLd2]
socket = /tmp/MysqL.sock2
port = 3307
pid-file = /usr/local/MysqL/data/3307/MysqL.pid
datadir = /usr/local/MysqL/data/3307/
#language = /usr/local/MysqL/share/MysqL/english
#user = unix_user1
[MysqLd3]
#MysqLd = /path/to/MysqLd_safe
#ledir = /path/to/MysqLd-binary/
#MysqLadmin = /path/to/MysqLadmin
socket = /tmp/MysqL.sock3
port = 3308
pid-file = /usr/local/MysqL/data/3308/MysqL.pid
datadir = /usr/local/MysqL/data/3308/
#language = /usr/local/MysqL/share/MysqL/swedish
#user = unix_user2
vim /etc/profile
PATH=/usr/local/MysqL/bin:$PATH
#让配置立即生效
source /etc/profile
6,启动msyql数据库
MysqLd_multi �defaults-file=/usr/local/MysqL/data/multi.cnf start 1,2,3
查看端口状态
netstat -anpt |grep MysqLd
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 25470/MysqLd
tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN 25476/MysqLd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 25453/MysqLd
7,设置MysqL密码
MysqLadmin -uroot -S /tmp/MysqL.sock1 password “root”
MysqLadmin -uroot -S /tmp/MysqL.sock2 password “root”
MysqLadmin -uroot -S /tmp/MysqL.sock3 password “root”
8,进入数据库
MysqL -S /tmp/MysqL.sock1 -proot
MysqLadmin -S /tmp/MysqL.sock1 shutdown -proot
MysqLd_multi �defaults-file=/usr/local/MysqL/data/multi.cnf stop 1,3