tar zxf cmake-2.8.8.tar.gz
cd cmake-2.8.8
./configure
gmake
gmake install
cd ..
rpm -qa | grep ncurses
ncurses-5.7-4.20090207.el6.x86_64
ncurses-base-5.7-4.20090207.el6.x86_64
ncurses-term-5.7-4.20090207.el6.x86_64
ncurses-libs-5.7-4.20090207.el6.x86_64
ncurses-devel-5.7-4.20090207.el6.x86_64
如没有安装,则安装之
yum install ncurses-devel -y
tar xf mysql-5.5.32.tar.gz
cd mysql-5.5.32
useradd mysql -s /sbin/nologin -M
id mysql
a、不指定字符集,使用默认拉丁字符集
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
b、指定字符集为utf8
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
make && make install
ln -s /application/mysql-5.5.32/ /application/mysql
echo 'export PATH=/application/mysql/bin/:$PATH' >>/etc/profile
a、查看profile
tail -1 /etc/profile
export PATH=/application/mysql/bin/:$PATH
b、让 配置生效
source /etc/profile
c、查看PATH
echo $PATH
/application/mysql/bin/:/application/nginx/sbin:/application/nginx/sbin:/usr/lib64/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
ll -d /application/mysql/data/
drwxr-xr-x 3 root root 4096 Mar 26 22:10 /application/mysql/data/
chown -R mysql.mysql /application/mysql/data/
chmod 1777 /tmp/
cp mysql-5.5.32/support-files/my-small.cnf /etc/my.cnf
cd /application/mysql/scripts/
./mysql_install_db --user=mysql --basedir=/application/mysql/--datadir=/application/mysql/data/
cp/application/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
/application/mysql/bin/mysqladmin -u rootpassword '123456'
mysql -uroot -p
delete from mysql.user where host='::1'or user='';
drop database test;
grant all privileges on *.* tosystem@'localhost' identified by '123456' with grant option
chkconfig mysqld on
chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
就是一台服务器上开启多个不同的服务端口,来运行多个MySQL服务里程,通过不用同socket 监听不同的服务端口提供各自的服务。
这些MySQL多实例,共用一套MySQL安装程序,使用不同(也可相同)的my.conf配置文件、启动程序、数据文件。在提供服务时,多实例的MySQL在逻辑上看起来是各自独立的,多个实例根据配置文件对应的设定值,获取相应的服务器资源。
a、有效利用服务器资源
b、节约服务器资源
c、节省IDC机柜
a、资源互相抢占
b、当某个服务实例并发很高或有慢查询时导致其它实例性能下降
a、资金紧张的公司
b、并发访问不是特别大的业务
c、门户网站应用较多
百度搜索引擎的数据库是多实例,一般是从库(48核,96G,3-4个实例)
sina网也是多实例(内存48G)
tree data
/data
├── 3306
│ ├── data #3306实例的数据文件
│ ├── my.cnf #3306实例的配置文件
│ └── mysql #3306实例的启动文件
└── 3307
├── data
├── my.cnf
└── mysql
a、my.cnf配置文件样例(mysql手册中提到的方法)
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = mysql
[mysqld1]
socket =/var/lib/mysql/mysql.sock
port =3306
pid-file = /var/lib/mysql/mysql.pid
datadir =/var/lib/mysql/
user =mysql
[mysqld2]
socket =/mnt/data/db2/mysql.sock
port =3303
pid-file = /mnt/data/db2/mysql.pid
datadir =/mnt/data/db2/
user =mysql
skip-name-resolve
server-id = 11
master-connect-retry = 60
default-storage-engine = innodb
innodb_buffer_pool_size = 512M
innodb_additional_mem_pool = 10M
default_character_set = utf8
character_set_server = utf8
#read-only
relay-log-space-limit =3G
expire_logs_day =20
[mysqld3]
socket =/mnt/data/db1/mysql.sock
port =3302
pid-file = /mnt/data/db1/mysql.pid
datadir =/mnt/data/db1/
user =mysql
skip-name-resolve
server-id = 10
default-storage-engine = innodb
innodb_buffer_pool_size = 512M
innodb_additional_mem_pool = 10M
default_character_set = utf8
character_set_server = utf8
#read-only
relay-log-space-limit =3G
expire_logs_day =20
b、启动方法
mysqld_multi--config-file=/data/mysql/my_multi.cnf start 1,2,3
c、停止方法
mysqld_multi stop 1,3
d、存在的问题
耦合性太强
yum install ncurses-devel -y
yum install libaio-devel -y
整个安装过程只到make install和建立软链接就停止,后面的步骤不用操作,多实例方式需重新配置。
pkill mysqld
ps -ef | grep mysql
rm -f /etc/init.d/mysqld
mkdir -p /data/{3306,3307}/data
vi /data/3306/my.cnf
[client]
port = 3306
socket =/data/3306/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket =/data/3306/mysql.sock
basedir = /application/mysql
datadir = /data/3306/data
open_files_limit = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
#log_long_format
#log-error = /data/3306/error.log
#log-slow-queries = /data/3306/slow.log
pid-file = /data/3306/mysql.pid
log-bin = /data/3306/mysql-bin
relay-log = /data/3306/relay-bin
relay-log-info-file = /data/3306/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 1
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
log-error=/data/3306/mysql_oldboy3306.err
pid-file=/data/3306/mysqld.pid
vi /data/3307/my.cnf
[client]
port = 3307
socket =/data/3307/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3307
socket =/data/3307/mysql.sock
basedir = /application/mysql
datadir = /data/3307/data
open_files_limit = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_cache = 614
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
#default_table_type = InnoDB
thread_stack = 192K
#transaction_isolation = READ-COMMITTED
tmp_table_size = 2M
max_heap_table_size = 2M
#long_query_time = 1
#log_long_format
#log-error = /data/3307/error.log
#log-slow-queries = /data/3307/slow.log
pid-file = /data/3307/mysql.pid
#log-bin = /data/3307/mysql-bin
relay-log = /data/3307/relay-bin
relay-log-info-file = /data/3307/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
#myisam_sort_buffer_size = 1M
#myisam_max_sort_file_size = 10G
#myisam_max_extra_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 3
innodb_additional_mem_pool_size = 4M
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 2M
[mysqld_safe]
log-error=/data/3307/mysql_oldboy3307.err
pid-file=/data/3307/mysqld.pid
当启动MySQL时,如果配置文件不在/etc下的话,在启动时,必须通过--defaults-file参数来指定MySQL的配置文件my.cnf的路径
启动:
mysqld_safe--default-file=/data/3306/my.cnf 2>&1 >/dev/null &
mysqld_safe--default-file=/data/3307/my.cnf 2>&1 >/dev/null &
停止(平滑停止MySQL):
mysqladmin -uroot -p 123456 -S /data/3306/mysql.sock shutdown
mysqladmin -uroot -p 123456 -S /data/3307/mysql.sock shutdown
vi /data/3306/mysql
#!/bin/sh
#init
port=3306
mysql_user="root"
mysql_pwd="oldboy"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
if [ ! -e"$mysql_sock" ];then
printf "StartingMySQL...\n"
/bin/sh${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &
else
printf "MySQL isrunning...\n"
exit
fi
}
#stop function
function_stop_mysql()
{
if [ ! -e"$mysql_sock" ];then
printf "MySQL isstopped...\n"
exit
else
printf "StopingMySQL...\n"
${CmdPath}/mysqladmin-u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql()
{
printf "RestartingMySQL...\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
vi /data/3307/mysql
#!/bin/sh
#init
port=3307
mysql_user="root"
mysql_pwd="oldboy"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
if [ ! -e"$mysql_sock" ];then
printf "StartingMySQL...\n"
/bin/sh${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &
else
printf "MySQL isrunning...\n"
exit
fi
}
#stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock"];then
printf "MySQL isstopped...\n"
exit
else
printf "StopingMySQL...\n"
${CmdPath}/mysqladmin-u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql()
{
printf "RestartingMySQL...\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
chown -R mysql.mysql /data
find /data -type f -name mysql | xargs chmod +x
echo 'export PATH=/application/mysql/bin/:$PATH' >>/etc/profile
#命令在mysql/bin目录下
mysql_install_db --basedir=/application/mysql--datadir=/data/3306/data --user=mysql
mysql_install_db --basedir=/application/mysql--datadir=/data/3307/data --user=mysql
#命令在mysql/scripts目录下
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
mysql_install_db