相比较于MySQL的源代码安装来说。免编译二进制包的速度实在是快了太多,而且性能损失也不是很大,同时具有一定的定制性。所以,如果没有特殊的 需求,尽量用MySQL免编译二进制包来安装MySQL。
1.下载软件包
# 5.6版本应该都是可以的。具体版本自己选
# http://mirrors.163.com/mysql/Downloads/MySQL-5.6/
用的mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
2.依赖包安装
yum -y install libaio
3.进入/usr/local/src
cd /usr/local/src/
4.解压软件包
tar -xvf mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
5.将解压后的软件包移动到/usr/local并改名为mysql
mv mysql-5.6.38-linux-glibc2.12-x86_64 /usr/local/mysql
6.进入/usr/local/mysql
cd /usr/local/mysql
7.新建用户和数据目录
useradd -M -s /sbin/nologin mysql
id mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
8.初始化mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
9.修改配置文件
mv /etc/my.cnf /etc/my.mariadb.cnf.bak
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
sed -i 's@# basedir =@basedir = /usr/local/mysql@' /etc/my.cnf
sed -i 's@# datadir =@datadir = /data/mysql@' /etc/my.cnf
sed -i 's@# socket =@socket = /tmp/mysql.sock@' /etc/my.cnf
10.拷贝/usr/local/mysql/suppsupport-files/mysql.server启动脚本到/etc/init.d下
#需在/usc/local/mysql目录下
cp ./support-files/mysql.server /etc/init.d/mysqld
11.编辑 mysqld脚本
#修改如下内容
sed -i 's@basedir=$@basedir=/usr/local/mysql@' /etc/init.d/mysqld
sed -i 's@datadir=$@datadir=/data/mysql@' /etc/init.d/mysqld
12.将mysql设置为开机启动
# cd /etc/init.d/
chkconfig --add mysqld
chkconfig --list
13.设置PATH,否则不能直接调用mysql,修改/etc/profile文件,在文件末尾添加
echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
#添加环境变量后,source或 . 生效
source /etc/profile
验证
/etc/init.d/mysqld start netstat -nltup | grep :3306 ps aux | grep mysqld lsof -i :3306
QA
Error: Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 解决: yum -y install libaio