MySQL二进制包安装并自定义basedir

前言: MySQL二进制包,定死了basedir为/usr/local/mysql/,但是很多人喜欢自定义目录,比如我就喜欢放/opt/app/mysql 数据目录喜欢自定义为/data/mydata/,以前必须把basedir必须做个软链接到/usr/local/mysql,本人有轻微的强迫症,就不想这么做,下面就来看实现过程。

1创建组,创建用户

groupadd -g3306 mysql

useradd -u3306 -M -s /sbin/nologin mysql

2.解压二进制包,创建数据存放目录

mkdir -p /opt/app/

mkdir -p /data/mydata

cp  mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz/opt/app

cd /opt/app

tar xvf mysql-5.6.20-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.6.20-linux-glibc2.5-x86_64 mysql

chown -Rmysql.mysql /opt/app/mysql /data/mydata

3.定义环境变量

vim /etc/profile.d/mysql.sh

export MYSQL_HOME=/opt/app/mysql

export PATH=$MYSQL_HOME/bin:$PATH

su -

4.准备启动脚本和添加服务,确保启动脚本是755权限

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

ll /etc/init.d/mysql

-rwxr-xr-x 1 mysql mysql 10880 07-19 00:24/etc/init.d/mysql

5.准备配置文件,我喜欢放basedir目录,你也可以放/etc/my.cnf

vim/opt/app/mysql/my.cnf

[client]

socket=/opt/app/mysql/mysql.socket

[mysqld]

basedir = /opt/app/mysql

datadir = /data/mydata

port = 3306

user = mysql

server_id = 11

socket = /opt/app/mysql/mysql.socket

skip-name-resolve

skip_external_locking = 1

explicit_defaults_for_timestamp

log-error = /opt/app/mysql/mysql-error.log

slow_query_log = 1

slow_query_log_file =/opt/app/mysql/mysql-slow.log

character_set_server = gbk

innodb_file_per_table = 1

innodb_data_home_dir = /data/mydata

innodb_data_file_path =ibdata1:1024M:autoextend

innodb_buffer_pool_size = 1024M

innodb_additional_mem_pool = 32M

innodb_log_buffer_size = 32M

innodb_flush_log_at_trx_commit = 2

innodb_open_files = 10000

innodb_thread_concurrency = 32

innodb_read_io_threads = 8

innodb_write_io_threads =8

innodb_log_file_size = 256M

innodb_log_files_in_group = 3

innodb_log_group_home_dir = /opt/app/mysql

innodb_flush_method = O_DIRECT

innodb_io_capacity = 2000

innodb_undo_tablespaces = 2

innodb_undo_logs = 128

innodb_undo_directory = /opt/app/mysql

max_connections = 5000

max_connect_errors = 100000

read_buffer_size = 2M

sort_buffer_size = 2M

query_cache_type = on

query_cache_size = 64M

tmp_table_size = 512M

max_heap_table_size = 512M

join_buffer_size = 2M

open_files_limit= 65535

thread_cache_size= 128

thread_concurrency= 12

back_log= 65535

max_allowed_packet = 64M

wait_timeout=2147483

key_buffer_size= 512M

bulk_insert_buffer_size = 16M

[myisamchk]

key_buffer_size= 64M

read_buffer_size = 2M

sort_buffer_size = 2M

write_buffer_size = 2M

[mysqld_safe]

pid-file=/opt/app/mysql/mysqld.pid

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

6.初始化MySQL

./mysql_install_db --basedir=/opt/app/mysql--datadir=/data/mydata --defaults-file=/opt/app/mysql/my.cnf

7.检查能否读取到配置文件

mysqld --verbose --help | grep cnf
2014-09-12 11:20:21 13784 [Warning] Using unique option prefix innodb_additional_mem_pool instead of innodb-additional-mem-pool-size is deprecated and will be removed in a future release. Please use the full name instead.
2014-09-12 11:20:21 13784 [Note] Plugin ‘FEDERATED‘ is disabled.
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf /opt/app/mysql/my.cnf ~/.my.cnf
                      my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default
2014-09-12 11:20:21 13784 [Note] Binlog end
2014-09-12 11:20:21 13784 [Note] Shutting down plugin ‘CSV‘
2014-09-12 11:20:21 13784 [Note] Shutting down plugin ‘MyISAM

8.最重要的一步来了,启动MySQL,如果不针对启动脚本修改,不做软连接,是无法启动的

[[email protected]]# /etc/init.d/mysql start

/etc/init.d/mysql:line 256: my_print_defaults: command not found

/etc/init.d/mysql:line 276: cd: /usr/local/mysql: 没有那个文件或目录

StartingMySQLCouldn‘t find MySQL server (/usr/local/mysql/[失败]sqld_safe)

[[email protected]]# vim /etc/init.d/mysql

#################截取了一段

basedir=

datadir=

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don‘t wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir=‘/var/lock/subsys‘
lock_file_path="$lockdir/mysql"

# The following variables are only set for letting mysql.server find things.

# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
  basedir=/usr/local/mysql
  bindir=/usr/local/mysql/bin
  if test -z "$datadir"
  then
    datadir=/usr/local/mysql/data
  fi
  sbindir=/usr/local/mysql/bin
  libexecdir=/usr/local/mysql/bin
else
  bindir="$basedir/bin"
  if test -z "$datadir"
  then
    datadir="$basedir/data"
  fi
  sbindir="$basedir/sbin"
  libexecdir="$basedir/libexec"
fi

#####################################

启动脚本写死了目录

就算你给了这basedir datadir 两个变量,还是一样启动不起来

分析一下启动脚本,可以发现问题

sh -x/etc/init.d/mysql start

[[email protected] scripts]# sh -x /etc/init.d/mysql start
+ basedir=
+ /opt/app/mysql
/etc/init.d/mysql: line 46: /opt/app/mysql: is a directory
+ datadir=
+ /data/mydata
/etc/init.d/mysql: line 48: /data/mydata: is a directory
+ service_startup_timeout=900
+ lockdir=/var/lock/subsys
+ lock_file_path=/var/lock/subsys/mysql
+ mysqld_pid_file_path=
+ test -z ‘‘
+ basedir=/usr/local/mysql
+ bindir=/usr/local/mysql/bin
+ test -z ‘‘
+ datadir=/usr/local/mysql/data
+ sbindir=/usr/local/mysql/bin
+ libexecdir=/usr/local/mysql/bin
+ datadir_set=
+ lsb_functions=/lib/lsb/init-functions
+ test -f /lib/lsb/init-functions
+ . /lib/lsb/init-functions
+ PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/mysql/bin
+ export PATH
+ mode=start
+ ‘[‘ 1 -ge 1 ‘]‘
+ shift
+ other_args=
+ case `echo "testing\c"`,`echo -n testing` in
++ echo ‘testing\c‘
++ echo -n testing
+ echo_n=-n
+ echo_c=
+ test -x ./bin/my_print_defaults
+ test -x /usr/local/mysql/bin/my_print_defaults
+ test -x /usr/local/mysql/bin/mysql_print_defaults
+ conf=/etc/my.cnf
+ print_defaults=
+ test -r /etc/my.cnf
+ test -z ‘‘
+ print_defaults=my_print_defaults
+ extra_args=
+ test -r /usr/local/mysql/my.cnf
+ test -r /usr/local/mysql/data/my.cnf
++ my_print_defaults mysqld server mysql_server mysql.server
/etc/init.d/mysql: line 257: my_print_defaults: command not found
+ parse_server_arguments
+ test -z ‘‘
++ hostname
+ mysqld_pid_file_path=/usr/local/mysql/data/i-718-40065-VM.pid
+ case "$mode" in
+ cd /usr/local/mysql
/etc/init.d/mysql: line 277: cd: /usr/local/mysql: 没有那个文件或目录
+ echo -n ‘Starting MySQL‘
Starting MySQL+ test -x /usr/local/mysql/bin/mysqld_safe
+ log_failure_msg ‘Couldn‘\‘‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)‘
+ /etc/redhat-lsb/lsb_log_message failure ‘Couldn‘\‘‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)‘
Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_saf[失败]

SHELL脚本我是比较渣渣,为什么刚才给了一个变量,他还认不到了,找到PATH

居然认不到我就给他,因为刚才我已经定义了MySQL变量,所以这边我就写$PATH

PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
export PATH

修改成

PATH="$PATH:/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"

export PATH

再次启动一下

9:检查一下,启动成功

[[email protected] scripts]# netstat-lntp | grep 3306

tcp       0      0 :::3306                     :::*                        LISTEN      13699/mysqld

[[email protected] scripts]#

时间: 2024-08-05 03:50:51

MySQL二进制包安装并自定义basedir的相关文章

mysql-5.5.56版本(二进制包安装)-自定义安装路径

mysql-5.5.56版本(二进制包安装)-自定义安装路径 安装路径:/application/mysql-5.5.56 1.前期准备 mysql依赖 libaio yum install -y libaio 创建用户mysql,以该用户的身份执行mysql useradd -s /bin/false -M mysql 下载mysql二进制包并解压 cd /tools wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.56

mysql-5.7.18版本(二进制包安装)-自定义安装路径

mysql-5.7.18版本(二进制包安装)-自定义安装路径 安装路径:/application/mysql-5.7.18 1.前期准备 mysql依赖 libaio yum install -y libaio 创建用户mysql,以该用户的身份执行mysql useradd -s /bin/false -M mysql 下载mysql二进制包并解压 cd /tools wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18

mysql二进制包安装与配置实战记录

导读 一般中小型网站的开发都选择 MySQL 作为网站数据库,由于其社区版的性能卓越,搭配 PHP .Linux和 Apache 可组成良好的开发环境,经过多年的web技术发展,在业内被广泛使用的一种web服务器解决方案之一.但是mysql源码包编译时间过长,今天将采用二进制包方式安装mysql,并进行优化配置,希望对广大读者有借鉴意义. 1.安装之前,先创建mysql用户 [[email protected]_nfs ~]# useradd mysql -s /sbin/nologin -M

ubuntu下mysql二进制包安装

1.下载对应二进制包 cd /usr/local/srcsudo wget http://dev.mysql.com/downloads/file/?id=465030 2.解压并放在/usr/local目录下改名为mysql sudo tar zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gzsudo mv mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql 3.创建mysql分组和用户,更改mysq

MySQL二进制包安装简略过程

l  软件目录 [[email protected]_03 ~]# mkdir -pv /data/software [[email protected]_03 ~]# cd /data/software/ [[email protected]_03 mysql-5.6.28-linux-glibc2.5-x86_64]# tar xvf mysql-5.6.28-linux-glibc2.5-x86_64.tar.gz l  软件下载 [[email protected]_03 softwar

MySQL二进制包安装脚本及批量安装

#!/bin/bash ###需要部署数据库的IP列表####ip192.168.1.10#ip192.168.1.11#ip192.168.1.12#ip192.168.1.13#ip192.168.1.14#ip192.168.1.15 ######执行脚本前,请确认已通外网,YUM源可用####cd /rootmyb=mysql-5.6.24-linux-glibc2.5-x86_64.tar.gzml=`echo $myb|cut -d"t" -f1|cut -d".

mysql二进制包安装

./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql57/ --datadir=/mysqldata ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ ./bin/mysqld --initialize --datadir=/mysqldata dadlI<t(k1Ek 首次安

MySQL二进制包安装实例 ( 5.5 、5.6 共存 )

mysql5.5版本和5.6版本在同一服务器上开启实例,在日常工作中都会碰到,开启多版本需要注意: 1.启动初始化不能用ln -s链接的名字来初始化 2.启动需要加--ledir=basedir 3.启动填写参数的位置 在这之前,一直使用ln -s 来启动5.6 一直报错: 在这之前看着启动没错吧: 然而显示的 unknown variable 'defaults-file=/etc/my3309.cnf' 同时根据配置文件的配置信息error的路径也不对,会默认到/var/log/mysql.

二进制包安装MySQL数据库

1.1二进制包安装MySQL数据库 1.1.1 安装前准备(规范) [[email protected]_server ~]# mkdir -p /home/shangbao_zhangdc/tools  ##创建指定工具包存放路径[[email protected]_server ~]# wget http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.5/mysql-5.5.32-linux2.6-x86_64.tar.gz  ##下二进制包,这个