CentOS6.5编译安装Mysql5.5.32(多实例)


1. 网络配置

[root@mysql ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:b8:ed:81
TYPE=Ethernet
UUID=e70002ef-8582-4e24-bf8a-76f34cf7ad3f
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=10.0.0.12
NETMASK=255.255.255.0
GATEWAY=10.0.0.1

[root@mysql ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
HWADDR=08:00:27:80:af:45
TYPE=Ethernet
UUID=3f89d03c-fcf9-465c-806b-bc5d3dd33b58
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.0.12
NETMASK=255.255.255.0

service network restart
route add default gw 10.0.0.1 ##重启网卡后失效 ##永久方式 网卡添加GATEWAY=10.0.0.1
##DNS配置
[root@mysql ~]# cat /etc/resolv.conf
nameserver 10.0.0.1

2. 防火墙设置

[root@mysql ~]#chkconfig iptables off
[root@mysql ~]#service iptables stop
[root@mysql ~]#service iptables status
[root@mysql ~]#sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config
[root@mysql ~]#setenforce 0

3. 安装环境

[root@mysql ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)
[root@mysql ~]# uname -r
2.6.32-431.el6.x86_64 [root@mysql ~]# uname -m
x86_64
[root@mysql ~]# uname -a Linux mysql 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09
UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

4.yum源配置

##网络yum源
[root@mysql ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@mysql ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[root@mysql ~]# yum makecache

##本地yum源
[root@mysql repodata]# cd /etc/yum.repos.d/
[root@mysql yum.repos.d]# vi CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=file:///mnt/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

[root@mysql yum.repos.d]# yum clean all

http://mirrors.aliyun.com/help/centos

5.软件包安装

**选择最小化安装CentOS**
http://blog.csdn.net/lt53130640688/article/details/49638381

##上传下载软件包
[root@mysql yum.repos.d]# yum install lrzsz -y
##tree命令包
[root@mysql yum.repos.d]# yum install tree -y
##Mysql依赖包(重要)
[root@mysql yum.repos.d]# yum install ncurses-devel -y

6.上传cmake-2.8.8.tar.gz 和mysql-5.5.32.tar.gz

[root@mysql tools]# rz -y
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring cmake-2.8.8.tar.gz...
100% 5558 KB 5558 KB/sec 00:00:01 0 Errors
Transferring mysql-5.5.32.tar.gz...
100% 24019 KB 12009 KB/sec 00:00:02 0 Errors

7.安装Cmake 编译工具

[root@mysql tools]# tar xf cmake-2.8.8.tar.gz 
[root@mysql tools]# cd cmake-2.8.8
[root@mysql tools]# ./configure
[root@mysql tools]# gmake
[root@mysql tools]# gmake install

8.安装MySQL

[root@mysql tools]# groupadd mysql
[root@mysql tools]# useradd mysql -s /sbin/nologin -M -g mysql
[root@mysql tools]# tar zxf mysql-5.5.32.tar.gz
[root@mysql tools]# cd mysql-5.5.32

[root@mysql mysql-5.5.32]# cmake -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0

##-DDEFAULT_CHARSET=utf8 \
##-DDEFAULT_COLLATION=utf8_general_ci \
[root@mysql mysql-5.5.32]# make && make install

9.配置MySQL

[root@mysql tools]# ln -s /application/mysql-5.5.32 /application/mysql
[root@mysql tools]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
[root@mysql tools]# tail -1 /etc/profile
[root@mysql tools]# source /etc/profile
[root@mysql tools]# echo $PATH

10.脚本参数文件

[root@mysql /]# cd /
[root@mysql /]# rz -y
[root@mysql /]# unzip -o data.zip
Archive: data.zip
creating: data/
creating: data/3306/
creating: data/3306/data/
inflating: data/3306/my.cnf
inflating: data/3306/mysql
creating: data/3307/
creating: data/3307/data/
inflating: data/3307/my.cnf
inflating: data/3307/mysql
[root@mysql /]# chmod -R 1777 /tmp
[root@mysql /]# chown -R mysql.mysql /data
[root@mysql67 /]# find /data/ -type f -name "mysql"|xargs ls -l
-rw-r--r-- 1 mysql mysql 1140 Nov 3 18:19 /data/3306/mysql
-rw-r--r-- 1 mysql mysql 1140 Nov 3 18:19 /data/3307/mysql
[root@mysql /]# find /data/ -type f -name "mysql"|xargs chmod +x
[root@mysql /]# find /data/ -type f -name "mysql"|xargs ls -l
-rwxr-xr-x. 1 mysql mysql 1202 Nov 4 11:13 /data/3306/mysql
-rwxr-xr-x. 1 mysql mysql 1202 Nov 4 11:12 /data/3307/mysql
[root@mysql 3306]# find /data/ -type f -name "mysql"|xargs dos2unix
dos2unix: converting file /data/3307/mysql to UNIX format ...
dos2unix: converting file /data/3306/mysql to UNIX format ..

10.初始化MySQL

[root@mysql /]# cd /application/mysql/scripts/
[root@mysql scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data/ --user=mysql
WARNING: The host 'mysql' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/application/mysql/bin/mysqladmin -u root password 'new-password'
/application/mysql/bin/mysqladmin -u root -h mysql password 'new-password'

Alternatively you can run:
/application/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /application/mysql ; /application/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /application/mysql/scripts/mysqlbug script!

[root@mysql scripts]# ./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data/ --user=mysql
WARNING: The host 'mysql' could not be looked up with resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges !
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/application/mysql/bin/mysqladmin -u root password 'new-password'
/application/mysql/bin/mysqladmin -u root -h mysql password 'new-password'

Alternatively you can run:
/application/mysql/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /application/mysql ; /application/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /application/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /application/mysql/scripts/mysqlbug script!

11.启动MySQL

[root@mysql 3306]# cd /data/3306
[root@mysql 3306]# ./mysql start
Starting MySQL ...
[root@mysql 3306]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6363/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6459/master
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7502/mysqld
tcp 0 0 :::22 :::* LISTEN 6363/sshd
tcp 0 0 ::1:25 :::* LISTEN 6459/master
[root@mysql 3307]# cd /data/3307/
[root@mysql 3307]# ./mysql start
Starting MySQL ...
[root@mysql 3307]# netstat -lntnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 8373/mysqld
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6363/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6459/master
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7502/mysqld
tcp 0 0 :::22 :::* LISTEN 6363/sshd
tcp 0 0 ::1:25 :::* LISTEN 6459/master

##密码设置
[root@mysql 3307]# /application/mysql/bin/mysqladmin -u root password '123456' -S /data/3306/mysql.sock
[root@mysql 3307]# /application/mysql/bin/mysqladmin -u root password '123456' -S /data/3307/mysql.sock

[root@mysql 3307]# ./mysql stop
Stoping MySQL...
[root@mysql 3307]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6363/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6459/master
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7502/mysqld
tcp 0 0 :::22 :::* LISTEN 6363/sshd
tcp 0 0 ::1:25 :::* LISTEN 6459/master

[root@mysql data]# cd ../3306
[root@mysql 3306]# ./mysql stop
Stoping MySQL...
[root@mysql 3306]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6363/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 6459/master
tcp 0 0 :::22 :::* LISTEN 6363/sshd
tcp 0 0 ::1:25 :::* LISTEN 6459/master

my.cnf参数文件

[client]
port = 3306
socket = /data/3306/mysql.sock

[mysqld]
datadir=/data/3306/data
port = 3306
socket = /data/3306/mysql.sock

skip-name-resolve
lower_case_table_names=1
innodb_file_per_table=1
back_log = 50
max_connections = 300
max_connect_errors = 1000
table_open_cache = 2048
max_allowed_packet = 16M
binlog_cache_size = 2M
max_heap_table_size = 64M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 64
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine = innodb
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
federated
tmp_table_size = 64M

long_query_time = 1
slow-query-log = 1
binlog_format=mixed
log-bin = /data/3306/mysql-bin
slow-query-log-file = /data/3306/slow.log
log-error = /data/3306/error.log
pid-file = /data/3306/mysql.pid
relay-log = /data/3306/relay-bin
relay-log-info-file = /data/3306/relay-log.info
binlog_cache_size = 2M
max_binlog_cache_size = 2M
max_binlog_size = 3M
expire_logs_days = 7

server-id = 1

key_buffer_size = 4M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover

innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:10M:autoextend
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 8M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120

[mysqldump]
quick
max_allowed_packet = 256M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M

[mysqlhotcopy]
interactive-timeout

[mysqld_safe]
open-files-limit = 8192
log-error = /data/3306/mysql_3306.err
pid-file = /data/3306/mysqld.pid

##3307参数文件只需将3306替换成3307即可

mysql启停脚本

#!/bin/sh
#############################################
#this scripts is created by LT
#3307起停脚本只需将3306替换成3307即可
#############################################

port=3306
mysql_user="root"
mysql_pwd="123456"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
if [ ! -e "$mysql_sock" ]; then
printf "Starting MySQL ...\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &
else
printf "MySQL is running ...\n"
exit
fi
}

#stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ]; then
printf "MySQL is stopped ...\n"
exit
else
printf "Stoping MySQL...\n"
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
fi
}

#restart function
function_restart_mysql()
{
printf "Restarting MySQL...\n"
function_stop_mysql
sleep 2
function_start_mysql
}

case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf"Usage: /data/${port}/mysql {start|stop|restart}\n"
esac

因参数设置报错

--启动错误
[root@mysql 3306]# cat mysql_3306.err
151105 10:49:10 mysqld_safe Starting mysqld daemon with databases from /data/3306/data
151105 10:49:10 [Warning] The syntax '--log-slow-queries' is deprecated and will be removed in a future release.

Please use '--slow-query-log'/'--slow-query-log-file' instead.
151105 10:49:10 InnoDB: The InnoDB memory heap is disabled
151105 10:49:10 InnoDB: Mutexes and rw_locks use GCC atomic builtins
151105 10:49:10 InnoDB: Compressed tables use zlib 1.2.3
151105 10:49:10 InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io_threads and

innodb_write_io_threads instead
151105 10:49:10 InnoDB: Initializing buffer pool, size = 32.0M
151105 10:49:10 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
151105 10:49:10 InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
151105 10:49:10 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 8 MB
InnoDB: Database physically writes the file full: wait...
151105 10:49:10 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 8 MB
InnoDB: Database physically writes the file full: wait...
151105 10:49:10 InnoDB: Log file ./ib_logfile2 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile2 size to 8 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: 127 rollback segment(s) active.
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
151105 10:49:10 InnoDB: Waiting for the background threads to start
151105 10:49:11 InnoDB: 5.5.32 started; log sequence number 0
151105 10:49:11 [ERROR] /application/mysql-5.5.32/bin/mysqld: unknown variable

'myisam_max_extra_sort_file_size=10G'
151105 10:49:11 [ERROR] Aborting

151105 10:49:11 InnoDB: Starting shutdown...
151105 10:49:12 InnoDB: Shutdown completed; log sequence number 1595675
151105 10:49:12 [Note] /application/mysql-5.5.32/bin/mysqld: Shutdown complete

151105 10:49:12 mysqld_safe mysqld from pid file /data/3306/mysqld.pid ended

**可以看出当前版本参数log-slow-queries,innodb_file_io_threads已经无效**

登陆及优化mysql详看
http://blog.csdn.net/lt53130640688/article/details/49639363


快速安装命令整合:

cat /etc/redhat-release  
uname -a
vi /etc/sysconfig/network-scripts/ifcfg-eth0
vi /etc/sysconfig/network-scripts/ifcfg-eth1
service network restart
echo 'nameserver 10.0.0.1'>> /etc/resolv.conf

chkconfig iptables off
service iptables stop
service iptables status
setenforce 0
sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum makecache
yum install lrzsz -y
yum install tree -y
yum install ncurses-devel -y

tar xf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
gmake
gmake install

groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
tar zxf mysql-5.5.32.tar.gz
cd mysql-5.5.32

cmake -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \
-DMYSQL_DATADIR=/application/mysql-5.5.32/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0

make && make install

ln -s /application/mysql-5.5.32 /application/mysql
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
tail -1 /etc/profile
source /etc/profile

cd /
rz -y
unzip -o data.zip
chmod -R 1777 /tmp
chown -R mysql.mysql /data
find /data/ -type f -name "mysql"|xargs chmod +x
find /data/ -type f -name "mysql"|xargs ls -l
find /data/ -type f -name "mysql"|xargs dos2unix

cd /application/mysql/scripts/
./mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data/ --user=mysql
./mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data/ --user=mysql

cd /data/3306/
./mysql start
netstat -lntup
cd /data/3307/
./mysql start
netstat -lntnp

/application/mysql/bin/mysqladmin -u root password '123456' -S /data/3306/mysql.sock
/application/mysql/bin/mysqladmin -u root password '123456' -S /data/3307/mysql.sock

cd /data/3306/
./mysql stop
netstat -lntup
cd /data/3307/
./mysql stop
netstat -lntup

更多相关文章

  1. MySql查询脚本,每月统计活动用户。
  2. MySQL导出和导入SQL脚本
  3. 存储过程,参数数量不正确bug?
  4. MySQL数据库 prompt参数详解
  5. MyBatis排序时使用order by 动态参数时需要注意,用$而不是# 用$传
  6. 如果发现自己的mysql没有充分利用CPU该关注那些参数?
  7. MySQL在Linux下Shell脚本操作命令
  8. 解析innodb status各项参数
  9. JavaScript中当前脚本的URL

随机推荐

  1. 转:6410下点亮led
  2. Linux常用命令汇总-速查
  3. Linux 3.4.39内核编译配置选项介绍
  4. linux shell脚本编程笔记(四): 获取字符串长
  5. linux apache安装https证书
  6. 有什么办法可以在Windows上不用使用太繁
  7. 线程同步-生产者消费者问题
  8. linux下touch命令也可以一次创建多个文件
  9. linux如何处理多连接请求?
  10. Linux下安装配置MongoDB数据库图解