当前位置:主页 > 环境搭建 > 环境搭建:centos6.8安装mysql-5.7.16-linux-glibc2.5-x86_64
201706/22

环境搭建:centos6.8安装mysql-5.7.16-linux-glibc2.5-x86_64

admin 环境搭建 阅读:

安装说明:
1、系统环境:centos6.8
2、mysql版本mysql-5.7.16-linux-glibc2.5-x86_64
3、安装源码存放路径:/usr/local/src
4、mysql安装路径/usr/local/mysql
5、部分依赖包采用yum安装,部分采用源码安装
6、源码安装包存放在/usr/local/src下,安装目录均放在/usr/local下


一、添加可能需要的包
#yum安装
yum -y install gcc gcc++ gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel libtool-ltdl libtool-ltdl-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libtiff libtiff-devel gettext gettext-devel libc-client libc-client-devel readline readline-devel bison-devel

#安装cmake
cd /usr/local
tar zxf src/cmake-3.6.2.tar.gz
cd cmake-3.6.2/
./configure && make && make install


#安装jemalloc
cd /usr/local
tar zxf src/jemalloc-4.2.1.tar.bz2
cd jemalloc-4.2.1/
./configure
make && make install
cd /usr/local

#设置系统位数变量
if [ `getconf WORD_BIT` == 32 ] && [ `getconf LONG_BIT` == 64 ];then
    OS_BIT=64
else
    OS_BIT=32
fi


#由于系统版本使用的是centos 6.8 64位,根据上面变量结果得出64进行相应的设置
ln -s /usr/local/lib/libjemalloc.so.2 /usr/lib64/libjemalloc.so.1
ln -s /usr/local/lib/libjemalloc.so.2 /usr/lib64/libjemalloc.so.2
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
/sbin/ldconfig


二、检查服务器是否安装了Mysql,有则卸载
#查看是否有mysql安装包,有则卸载
# rpm -qa | grep -i mysql
mysql-devel-5.1.73-8.el6_8.x86_64
php-mysql-5.3.3-49.el6.x86_64
mysql-connector-odbc-5.1.5r1144-7.el6.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
mod_auth_mysql-3.0.0-11.el6_0.1.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
libdbi-dbd-mysql-0.8.3-5.1.el6.x86_64
#依次对mysql关联包进行卸载,命令 rpm -e 关联包
#例如:
#rpm -e mysql-devel-5.1.73-8.el6_8.x86_64

#也可使用下面命令进行卸载
#rpm -qa | grep -i mysql  | xargs rpm -e

#删除mysql用户和用户组
userdel mysql
groupdel mysql


三、MySQL安装
# 添加mysql组和mysql用户
/usr/sbin/groupadd mysql
/usr/sbin/useradd -r -g mysql -s /bin/false -M mysql

#创建MySQL数据库存放目录/data/mysqldata
mkdir -p /data/mysqldata
chmod +w /data/mysqldata
chown -R mysql:mysql /data/mysqldata

[ -e /usr/local/lib/libtcmalloc.so ] && { je_tc_malloc=2; EXE_LINKER="-DCMAKE_EXE_LINKER_FLAGS='-ltcmalloc'"; }
[ -e /usr/local/lib/libjemalloc.so ] && { je_tc_malloc=1; EXE_LINKER="-DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'"; }
echo $EXE_LINKER


#上传mysql文件mysql-5.7.16-linux-glibc2.5-x86_64.tar到/usr/local/src,并进入上传mysql源码包的目录
cd /usr/local/src
#解压源码包
tar xf mysql-5.7.16-linux-glibc2.5-x86_64.tar
#解压后会有两个文件mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz、mysql-test-5.7.16-linux-glibc2.5-x86_64.tar.gz
#解压其中一个mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
tar zxf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz
mkdir /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
mv /usr/local/src/mysql-5.7.16-linux-glibc2.5-x86_64/* /usr/local/mysql/

#执行初始化mysql,执行完后会输出初始密码,请将密码记录下来,后面将会用到
/usr/local/mysql/bin/mysqld  --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata  --initialize
图片.png
M,*2U3p):24;


#更改数据目录权限
chown -R mysql.mysql /data/mysqldata

#修改服务配置文件中的安装目录和数据目录
sed -i 's@^basedir=$@basedir=/usr/local/mysql@g'  /usr/local/mysql/support-files/mysql.server
sed -i 's@^datadir=$@datadir=/data/mysqldata@g'  /usr/local/mysql/support-files/mysql.server
#拷贝mysql配置文件到/etc/my.cnf
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

#编辑my.cnf
##--编辑开始
vi /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysqldata
socket = /tmp/mysql.sock
character_set_server=utf8
init_connect='SET NAMES utf8'
lower_case_table_names=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[client]
default-character-set=utf8
socket = /tmp/mysql.sock

[mysql]
default-character-set=utf8
socket=/tmp/mysql.sock
##--编辑结束


#启动mysql.server服务,正常情况应该可以启动
/usr/local/mysql/support-files/mysql.server start
Starting MySQL.. OK!

#将mysql.server拷贝到服务中,可作为服务启动,并添加开机启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --list mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld restart

#创建软链接
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

#初始化mysql用户root的密码

/usr/local/mysql/bin/mysqladmin -u root -p password 'mypasswd‘
Enter password: 输入刚才初始的密码

#安装结束,现可使用下面命令登录数据库。
mysql -uroot -pmypasswd

 


本文地址:
版权所有 @ 未注明“转载”的博文一律为原创,转载时必须以链接形式注明作者和原始出处!
如果你觉得文章不错,您可推荐给你的朋友哦!

上一篇:没有了 下一篇:没有了