Mysql源码安装

#!/bin/bash

installdir=/usr/local/webserver

mysqldatadir=/data/mysql

mysqlrootpwd=weiphone



#install  depend  packages

yum  -y  install  gcc  make  cmake  ncurses-devel  libxm12-devel  libtool-ltdl-devel  gcc-c++  autoconf  automake  bison  zlib-devel


#create   user and  group

groupadd  mysql

useradd  -r -s  /sbin/nologin   -g  mysql  mysql

mkdir -p   $installdir

mkdir -p   $mysqldatadir

chown    mysql.mysql -R   $mysqldatadir



#download  and  install    mysql

wget http://editor.weiphone.com/tar/lnmp.tar.gz

tar -xzf lnmp.tar.gz

cd     data0/software/source/

tar  -xzf  mysql-5.6.13.tar.gz

cd  mysql-5.6.13

cmake  .  -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql/   -DMYSQL_DATADIR=$mysqldatadir     -DMYSQL_UNIX_ADDR=$mysqldatadir/mysqld_sock      -DSYSCONFDR=/etc/          -DEXTRA_CHARSETS=all         -DDEFAULT_CHARSET=utf8            -DDEFAULT_CONLIATION=utf8_general_ci      -DWITH_INNOBASE_STORAGE_ENGINE=1         -DWITH_MYISAM_STORAGE_ENGINE=1        -DWITH_BLACKHOLE_STORAGE_ENGINE=1       -DENABLED_LOCAL_INFILE=1         -DMYSQL_TCP_PORT=3306      -DWITH_DEBUG=0                         

make  &&  make install

#   mysql5.5以后就要使用cmake来编译了
#  -DCMAKE_INSTALL_PREFIX=   存放安装路径
#  -DMYSQL_DATADIR=  数据文件存放位置
#  -DMYSQL_UNIX_ADDR= 连接数据库socket路径  数据库一启动就会有这个文件
#  -DSYSCONFDR=     my.cnf路径
#  -DEXTRA_CHARSETS=all    安装所有的扩展字符集
#  -DDEFAULT_CHARSET=utf8  默认 utf8 字符
#  -DDEFAULT_CONLIATION=utf8_general_ci    校验字符
#  -DWITH_INNOBASE_STORAGE_ENGINE=1        支持InnoDB引擎
#  -DWITH_MYISAM_STORAGE_ENGINE=1          支持MyIASM引擎
#  -DWITH_BLACKHOLE_STORAGE_ENGINE=1       支持Blackhole引擎
#  -DENABLED_LOCAL_INFILE=1                允许从本地导入数据
#  -DMYSQL_TCP_PORT=3306                    端口


#change    mysql  service   PATH 

chown  -R  mysql.mysql  /usr/local/webserver/mysql

/bin/cp  support-files/my-default.cnf    /etc/my.cnf

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

chmod +x /etc/init.d/mysqld

chkconfig  --add mysqld

chkconfig   mysqld  on

PATH=$PATH:/usr/local/webserver/mysql/bin/

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



# change  my.cnf  configure

cat > /etc/my.cnf << EOF
[mysqld]
basedir = /usr/local/webserver/mysql
datadir = $mysqldatadir
character-set-server=utf8
collation-server=utf8_general_ci
user=mysql
port = 3306
default_storage_engine = InnoDB
server_id = 1
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 7

bind-address = 0.0.0.0


# name-resolve
skip-name-resolve

skip-host-cache


#lower_case_table_names = 1
ft_min_word_len = 1
query_cache_size = 64M
query_cache_type = 1

skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K

# LOG
log_error = $mysqldatadir/mysql-error.log
long_query_time = 1
slow_query_log
slow_query_log_file = $mysqldatadir/mysql-slow.log

# Oher
explicit_defaults_for_timestamp=true
#max_connections = 1000
open_files_limit = 65535
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[client]
port = 3306
password = weiphone
EOF


# Initalization  Mysql   Service

/usr/local/webserver/mysql/scripts/mysql_install_db   --user=mysql  --datadir=$mysqldatadir      --basedir=/usr/local/webserver/mysql                    


# start  mysql  service

/sbin/service mysqld restart


/usr/local/webserver/mysql/bin/mysql -e"grant all privileges on *.* to root@'127.0.0.1' identified by\"$mysqlrootpwd\" with grant option;"

/usr/local/webserver/mysql/bin/mysql -e"grant all privileges on *.* to root@'localhost' identified by\"$mysqlrootpwd\" with grant option;"

/usr/local/webserver/mysql/bin/mysql -uroot-p$mysqlrootpwd -e "delete from mysql.user where Password='';"

/usr/local/webserver/mysql/bin/mysql -uroot-p$mysqlrootpwd -e "drop database test;"

/sbin/servicemysqld restart


后台启动mysql服务、指定那个端口的mysql的配置文件,就启动那个端口的mysql服务

/bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/etc/myweapp.cnf &  


一个服务器上安装了3306和3307端口mysql,想关掉3307端口的mysql进程,就要指定3307端口的mysql.sock

mysqladmin   shutdown  关掉mysql服务

mysqladmin -S /data/mysql_weapp/mysql/mysql.sock -uroot -p shutdown 

你可能感兴趣的:(Mysql源码安装)