安装mysql
创建mysql用户
useradd mysql //已经有的不需要创建
卸载原来的mysql rpm包
rpm -qa|grep mysql //查询是否有相关包
yum -y remove *mysql* //我这里用yum卸载的
关闭防火墙,关闭selinux
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 \
-DMYSQL_USER=mysql \
-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
============================================******************************************============================================================
单实例的的安装操作
安装完相关操作
修改mysql安装目录权限
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
修改/etc/profile文件
vim /etc/profile
在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
#让配置立即生效
source /etc/profile
#登陆测试,默认是没有密码,直接回车就可进入
mysql -uroot -p
设置mysqlroot用户密码
mysqladmin -u root password “newpass”
#如果root已经设置过密码,采用如下方法
mysqladmin -uroot -ppassword password “newpass”
#验证mysql安装路径
ls -ld /usr/local/mysql/
============================================******************************************============================================================
多实例的的安装操作
接着上面源码包安装完成开始
1,创建多实例数据库文件夹
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/
3,准备配置文件#提供多配置文件模板
cd bin
./mysqld_multi –example > /usr/local/mysql/data/multi.cnf
4,修改模板文件 (不用的注释掉)
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
5, 修改/etc/profile文件
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
9,关闭数据库3种方法。
mysqladmin -S /tmp/mysql.sock1 shutdown -proot
mysqld_multi –defaults-file=/usr/local/mysql/data/multi.cnf stop 1,2,3