MySQL 5.7.16 centos下自动化安装

本文提供MySQL5.7版本的下载链接,并详细介绍了自动化安装脚本的编写及执行过程,包括基本库的安装、环境配置、数据库初始化及自定义参数设置,最后验证了安装效果。

1,安装包下载地址

官方下载地址:http://dev.mysql.com/downloads/mysql/,只保留最新的version,所以,需要的不一定有,我这里在百度云盘保留了下来,版本是5.7.16,可以随时去下载使用,分享地址:链接:http://pan.baidu.com/s/1jIhqSXw 密码:ifx5

 

2,查看mysqld安装参数

默认的官方文档安装是有初始化root密码的,而且那个密码很诡异,源码编译生成的还可以用,二进制或者rpm的不行,大家看如下官方的介绍:

http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 750 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql# MySQL 5.7.0 to 5.7.4
shell> bin/mysql_install_db --user=mysql    # MySQL 5.7.5
shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data mysql-files
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

Note

This procedure assumes that you have root (administrator)access to your system. Alternatively, you can prefix each command using the sudo (Linux)or pfexec (OpenSolaris)command.

Note

Before MySQL 5.7.4, the procedure does not assign passwords toMySQL accounts. To do so, use the instructions in Section 2.10.4, “Securing the Initial MySQLAccounts”.

 

 

但是这个初始化密码是可以去掉的,只是官方doc文档没有描述,大家可以通过mysqld --berbose –help来查找,如下所示:

[root@02_sdw ~]# /usr/local/mysql/bin/mysqld --verbose --help |grep initialize

mysqld: Can't change dir to '/usr/local/mysql/data/' (Errcode: 2 - No such file or directory)

                      GLOBAL.GTID_PURGED may be initialized wrongly in two

  --initialize        Create the default database and exit. Create a super user

  --initialize-insecure

initialize                                                   FALSE

initialize-insecure                                          FALSE

[root@02_sdw ~]#

 

原blog地址:http://blog.youkuaiyun.com/mchdba/article/details/53889781,作者mchdba,谢绝转载。

 

3,自动化安装脚本

编写自动化脚本auto_install_mysql5.7.end.sh来一键式安装,有个前提安装脚步、my.cnf和安装包mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz需要在同一个目录下,

#!/bin/bash

# install the basie lib

useradd mysql

yum install cmake -y

yum install -y libtoolize

yum install gcc gcc-c++ -y

yum install -y ncurses-devel.x86_64

yum install -y cmake.x86_64

yum install -y libaio.x86_64

yum install -y bison.x86_64

yum install -y gcc-c++.x86_64

 

# unzip

#cp mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz /usr/local/

tar -xvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz -C /usr/local

mv /usr/local/mysql-5.7.16-linux-glibc2.5-x86_64 /usr/local/mysql

cp my.cnf /tmp/

cp /tmp/my.cnf /usr/local/mysql/my.cnf

 

# add mysql account,create the basic directory

mkdir -p /data/mysql/data

cd /data/mysql/data

chown -R mysql:mysql /data

chown -R mysql:mysql /usr/local/mysql

mkdir -p /data/mysql/binlog/

chown -R mysql:mysql /data/mysql/binlog/

 

# init databases

rm -rf /data/mysql/data/*

cd /usr/local/mysql/

time bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize-insecure --user=mysql

 

# set the auto start on linux server started

cp support-files/mysql.server /etc/init.d/mysqld

chmod 700 /etc/init.d/mysqld

echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile

#source /etc/profile

chkconfig --add mysqld

 

source /etc/profile

 

# do a soft link to start mysql

cd /usr/local/

#ln -s mysql mysql

 

# remove default my.cnf

mv /etc/my.cnf /tmp/

 

# start the mysql server

service mysqld start

 

 

4,执行脚本安装

执行脚步bash -x auto_install_mysql5.7.end.sh安装完成,安装完成后,mysql登陆测试。

[root@00_mdw soft]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

[root@00_mdw soft]# ln -s /usr/local/mysql/mysql.sock /var/lib/mysql/mysql.sock

[root@00_mdw soft]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.16-log MySQL Community Server (GPL)

 

Copyright (c) 2000, 2012, 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>

 

 

参考文档地址:

https://docs.google.com/document/pub?id=1qgOspAux65N0HnOzEWPs7IpccU1i3bHg1EYedyCxmVQ

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值