MySQL5.6的Linux安装之二进制安装(一)

最近在写一个MySQL的shell安装脚本

说明一点着里面的所有路径都是绝对路径

下面来总结一下安装 遇到的一些问题,以及安装的过程

这个是自带的安装过程

shell> groupadd mysql
shell> useradd -r -g mysql 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> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

安装之前首先检查有没有mysql的进程,如果有我们还安装个啥

mysqlProcessNum=`/bin/ps aux | /bin/grep mysql | /usr/bin/wc -l | /bin/awk ‘{ print $1 }‘`;
if [ $mysqlProcessNum -gt 3 ]; then
    echo "已经安装MySQL"    exitfi

然后下载(可以从官网下载,但是个人感觉太慢了,于是就搭建了一个简单的ftp服务器,当然也可以本地上传嘛,在这里我就不细说了)

# download mysql package
yum install libaio   #MySQL的一个依赖包
/usr/bin/yum install awk wget -y
mysqlDownloadURL=ftp://。。。。。。。。。/pub/mysql/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz;
cd /tmp;
/bin/rm -rf mysql*.tar.gz
/usr/bin/wget $mysqlDownloadURL;

好我们已经下载好了

下面开始进入正题

解压,建立软连接

packageName=`/bin/ls | /bin/grep mysql*.tar.gz`;
# unpakcage mysql
/bin/tar zxvf $packageName -C /usr/local
mysqlAllNameDir=`/bin/ls -l /usr/local | grep mysql | /bin/awk ‘{ print $9 }‘`
/bin/ln -s $mysqlAllNameDir /usr/local/mysql

添加用户和用户组(判断一下,如果没添加就添加一下)

userNum=`/bin/cat /etc/passwd | /bin/grep mysql | /bin/awk -F ‘:‘ ‘{ print $1 }‘ | /usr/bin/wc -l`
if [ $userNum -lt 1 ];then
    /usr/sbin/groupadd mysql
    /usr/sbin/useradd -d /usr/local/mysql -s /sbin/nologin -g mysql mysql
    echo "成功添加"
fi

检查/etc下面是否有my.cnf文件,有的话就干掉,或者备份

/bin/mv /etc/my.cnf /etc/my.cnf.bak

下面初始化

/usr/local/mysql/scripts/mysql_install_db --datadir=/usr/local/mysql/data --user=mysql --basedir=/usr/local/mysql

说明一点!!!修改权限一定要在初始化之后,否则初始化之后的data目录不一定被附有权限

/bin/chown -R root.mysql /usr/local/mysql

/bin/chown -R mysql.mysql /usr/local/mysql/data/

现在可以自己写一个配置文件放在/etc下面

/etc/my.cnf (这里也说明一点,MySQL配置文件有参数替换原则)

顺序是这样的

/etc/my.cnf      /etc/mysql/my.cnf        /usr/local/mysql/etc/my.cnf         ~/.my.cnf

[client]
socket=/usr/local/mysql/mysql-files/mysql.sock
[mysqld]
explicit_defaults_for_timestamp=true
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql-files/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# LOG
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/mysql-files/mysql-slow.log
long_query_time = 2
# GENERAL LOG
#general_log = 1
#general_log_file = /usr/local/mysql/mysql-files/mysql-general.log
# BINARY LOG
server_id=101
log_bin=/usr/local/mysql/mysql-files/mysql-bin.log
binlog_format=ROW
sync_binlog=1
expire_logs_days=7
# ERROR LOG
log_error=/usr/local/mysql/mysql-files/mysql.err

# OTHER
character_set_server = utf8mb4
transaction-isolation = READ-COMMITTED
max_connections = 1000
log-queries-not-using-indexes
log_throttle_queries_not_using_indexes = 10

# INNODB
innodb_strict_mode=1
innodb_file_format=Barracuda
innodb_file_format_max=Barracuda
innodb_read_io_threads=4
innodb_write_io_threads=8 # 8 ~ 12
innodb_io_capacity=1000 # HDD:800 ~ 1200 SSD: 10000+
innodb_adaptive_flushing=1 # SSD: 0
innodb_flush_log_at_trx_commit=1
innodb_max_dirty_pages_pct=75
innodb_buffer_pool_dump_at_shutdown=1
innodb_buffer_pool_load_at_startup=1
innodb_flush_neighbors=1 # SSD:0
innodb_log_file_size=1024M # SSD:4G~8G HDD:1G~2G
innodb_purge_threads=1 # SSD:4
innodb_lock_wait_timeout=3
innodb_print_all_deadlocks=1
pid-file=/usr/local/mysql/data/mysqld/mysqld.pid

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld/mysqld.pid

下面以mysql_safe方式启动

/usr/local/mysql/bin/mysqld_safe &

好下面启动mysqld

/usr/local/mysql/bin/mysqld restart

[[email protected] mysql]# ./bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.25-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

说明几点:

1.删除重新安装的时候一定要看看是不是mysqld 的进程全部杀死了(ps -ef|grep mysqld),如果有使用“kill -9  进程号”杀死不然会严重影响下次安装

2.可能是第二次在机器上安装mysql,有残余数据影响了服务的启动。去mysql的数据目录/data看看,如果存在mysql-bin.index,就删除掉

其他要说明的我在之前的安装过程中已经说明了

下面就是安装脚本的基本过程

#!/bin/bash
# mysql install script, the home directory is /usr/local/mysql-VERSION and the soft link is /usr/local/mysql
yum install libaio
/usr/bin/yum install awk wget -y
config=`/bin/pwd`
mysqlProcessNum=`/bin/ps aux | /bin/grep mysql | /usr/bin/wc -l | /bin/awk ‘{ print $1 }‘`;
if [ $mysqlProcessNum -gt 3 ]; then
    echo "已经安装MySQL"
fi

# download mysql package
mysqlDownloadURL=ftp://222.26.224.236/pub/mysql/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz;
cd /tmp;
/bin/rm -rf mysql*.tar.gz
/usr/bin/wget $mysqlDownloadURL;
packageName=`/bin/ls | /bin/grep mysql*.tar.gz`;
# unpakcage mysql
/bin/tar zxvf $packageName -C /usr/local
mysqlAllNameDir=`/bin/ls -l /usr/local | grep mysql | /bin/awk ‘{ print $9 }‘`
/bin/ln -s $mysqlAllNameDir /usr/local/mysql
userNum=`/bin/cat /etc/passwd | /bin/grep mysql | /bin/awk -F ‘:‘ ‘{ print $1 }‘ | /usr/bin/wc -l`
if [ $userNum -lt 1 ];then
    /usr/sbin/groupadd mysql
    /usr/sbin/useradd -d /usr/local/mysql -s /sbin/nologin -g mysql mysql
    echo "成功添加"
fi
#/bin/mv /etc/my.cnf /etc/my.cnf.bak
/usr/local/mysql/scripts/mysql_install_db --datadir=/usr/local/mysql/data --user=mysql --basedir=/usr/local/mysql
/bin/chown -R root.mysql /usr/local/mysql
/bin/chown -R mysql.mysql /usr/local/mysql/data/
#我的配置文件放到root目录下面了

/bin/cp $config/my.cnf /etc/    

/usr/local/mysql/bin/mysqld_safe &
#/bin/chown -R mysql.mysql /usr/local/mysql/data/#/bin/cp $config/my.cnf /etc/
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#chmod 755 /etc/init.d/mysqld

祝成功

时间: 2024-10-11 00:34:07

MySQL5.6的Linux安装之二进制安装(一)的相关文章

lnmp-----mysql安装----myql二进制安装

mysql 二进制安装,仅需要解压就可以,不需要  cmake/configure,make,make install [[email protected] tools]# pwd/home/yang/tools [[email protected] tools]# groupadd mysql[[email protected] tools]# useradd -s /sbin/nologin -g mysql -M mysql 1.采用二进制方式安装MySQL [[email protect

MySQL 安装(二进制安装模式)

上一篇:MySQL 安装(RPM安装模式)及目录结构 本篇使用二进制模式安装: 查看当前是几位系统:file/sbin/init 各下载地址: Mysql官网下载: http://dev.mysql.com/downloads/mysql/ (默认选择当前系统) http://dev.mysql.com/downloads/mirrors.html  (其他镜像地址) Oracle官方下载:https://edelivery.oracle.com/ FTP下载: http://ftp.iij.a

编译安装和二进制安装mysql

useradd -r -s /sbin/nologin -M  mysql mkdir -p /opt/data/var yum -y install make gcc-c++ cmake bison-devel  ncurses-devel /etc/init.d/iptables stop chkconfig iptables off sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config yum -y inst

MySQl编译安装与二进制安装介绍

MySQL介绍 官方站点:http://www.mysql.com/ MySQL是一个开放源码的小型关联式数据库管理系统.目前MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度快.总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库. MySQl数据库分类 1)社区版 2)商业版 3)cluster集群 编译安装 1)编译安装 MySQL 8.0 正式版 8.0.11 已发布,官方表示 MySQL 8 要比 My

rpm安装和二进制安装

rpm包安装 Tomcat RPM安装(先安装JDK + 再安装Tomcat) 1:升级系统自带的JDK(也可以使用oracle的JDK) yum install -y java-1.8.0-openjdk-devel 2:由于Java开发的程序都需要运行在Java环境,因此一般只要是Java开发的程序,在安装JDK的同时,也需要将Java虚拟机导出到环境变量JAVA_HOME中,Java的虚拟机程序:/usr/bin/java vi /etc/profile.d/java.sh 添加 expo

LAMP环境部署:Apache源码安装+MySQL二进制安装+PHP源码安装+Nginx源码安装

Apache 版本:2.2.27 MySQL 版本:5.5.54-linux2.6-x86_64PHP 版本:5.3.27一.源码安装Apache1.首先安装上传工具2.上传LAMP环境所需安装包3.解压所有安装包4.安装Apache依赖包5.创建安装目录6.配置安装文件./configure \ #./configure 是用来生成Makefile文件用于编译安装 --prefix=/application/apache-2.2.27 \ #指定安装目录--enable-deflate \ #

yum安装Mariadb,二进制安装Mariadb

yum安装Mariadb 设置Mariadb的yum源 vim /etc/yum.repos.d/mariadb.repo [mariadb] name=mariadb baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.2/centos7-amd64/ gpgcheck=0 使用清华yum源安装Mariadb,可以选择不同的版本,此处安装10.2.23 yum install mariadb-server 二进制安装Maria

mysql在linux上的安装之三(二进制安装)

安装二进制源码包: 1. 从http://www.mysql.com下载二进制版的Mysql安装包     //这个MYSQL是二进制版的,不用编译 2. 更改权限 chmod 755  mysql-5.0.41-linux-i686-glibc23.tar.gz 3. 将解压后生成的目录,复制到/usr/local/下并改名为mysql tar xfz mysql-5.0.41-linux-i686-glibc23.tar.gz 4.  创建用户组与用户 groupadd mysql  建立m

MySQL在linux上的二进制安装方法

1.建立操作系统用户和组 [[email protected] ~]# groupadd mysql [[email protected] ~]# useradd -g mysql mysql 2.解压安装文件 [[email protected] ~]# cd /usr/local/ [[email protected] local]# mkdir mysql [[email protected] mysql]# tar -zxvf /mnt/mysql-5.5.53-linux2.6-x86