一直以来都是执着于源码安装,今天终于说服自己摆脱这个“不良嗜好”了。

使用二进制包安装比源码编译安装要简单得多,时间也短得多,何乐而不为呢。。。

二进制包安装MySQL的步骤和源码编译安装的步骤差不多,只是少了编译的流程,直接解压就能使用。

一、安装步骤

创建用户和安装依赖项:

# 创建用户
useradd -s /sbin/nologin -M mysql
# 安装依赖项
yum install numactl -y

下载安装包,解压,设置的安装目录为/usr/local/

wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
ln -s /usr/local/mysql-5.6.38-linux-glibc2.12-x86_64/ /usr/local/mysql

初始化数据库,设置数据库的数据目录为/data/mysqldb(默认为安装目录下的data目录):

# 创建数据目录
mkdir /data/mysqldb
# 设置安装目录和数据目录的权限
chown -R mysql.mysql /data/mysqldb mysql-5.6.38-linux-glibc2.12-x86_64
# 初始化数据库
cd /usr/local/mysql
/usr/local/mysql/scripts/mysql_install_db \
    --basedir=/usr/local/mysql \
    --datadir=/data/mysqldb \
    --user=mysql

设置配置文件和启动脚本:

cd /usr/local/mysql
/bin/cp -f support-files/my-default.cnf /etc/my.cnf
/bin/cp -f support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

mysql默认的安装目录为/usr/local/mysql,这里的安装目录为/usr/local/mysql-5.6.38

所以启动脚本里所有的默认目录都要改过来:

> sed -i ''s#/usr/local/mysql#/usr/local/mysql-5.6.38#g'' bin/mysqld_safe /etc/init.d/mysqld
> sed -i ''s#^datadir=$#datadir=/data/mysqldb#'' /etc/init.d/mysqld

同时如果修改了数据库的数据目录,也就是初始化时指定了datadir目录,还需要在/etc/init.d/mysqld中修改datadir配置。

> vi /etc/init.d/mysqld
# 找到此行并修改为数据目录
datadir=/data/mysqldb

设置环境变量:

echo ''export MYSQL_HOME=/usr/local/mysql'' >> /etc/profile
echo ''export PATH=$MYSQL_HOME/bin:$MYSQL_HOME/lib:$PATH'' >> /etc/profile
source /etc/profile

启动mysql服务:

> service mysqld start
> mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ''help;'' or ''\h'' for help. Type ''\c'' to clear the current input statement.

mysql> 

添加到开机启动:

chkconfig --add mysqld
chkconfig mysqld on

设置root密码:

mysqladmin -u root password ''123456''

二、遇到的问题

问题一

Installing MySQL system tables.../usr/local/mysql-5.6.38/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

缺少库文件,使用以下命令安装:

yum install numactl -y
最后修改:2018 年 01 月 19 日
如果觉得我的文章对你有用,请随意赞赏