useradd mysql -s /sbin/nologin -M
mkdir /data/{3307,3308}/{data,log,binlog} -p
cd /data/3307
chown -R mysql.mysql ./{binlog,data,log}
cd /usr/local/mysql/scripts/
注意:初始化mysql时一定要把一开始的/etc/my.cnf文件移走或者是修改名称,然后在初始化多实例mysql。
./mysql_install_db --datadir=/data/3307/data --basedir=/usr/local/mysql --user=mysql --explicit_defaults_for_timestamp
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf &
ps -ef|grep mysql
mysqladmin -uroot password ‘[email protected]‘ -S /data/3307/log/mysql.sock
mysql的配置文件:
[[email protected] log]# cat /data/3307/my.cnf
[client]
#password = your_password
port = 3307
socket = /data/3307/log/mysql.sock
[mysqld]
port = 3307
socket = /data/3307/log/mysql.sock
datadir = /data/3307/data/
long_query_time = 1
slow_query_log=1
slow-query-log-file = /data/3307/log/mysql-slow.log
log-error = /data/3307/log/error.log
pid-file = /data/3307/log/mysql3307.pid
character_set_server = utf8
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 4M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 64M
thread_cache_size = 128
query_cache_size = 0
tmp_table_size = 128M
secure_file_priv = /tmp
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin= /data/3307/binlog/mysql-bin
binlog_format=row
server-id = 37307
expire_logs_days = 2
log_bin_trust_function_creators=1
default_storage_engine = InnoDB
innodb_data_home_dir = /data/3307/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/3307/data
innodb_buffer_pool_size = 3072M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 256M
[mysql]
#prompt=‘\\[email protected]\\h : \\d:\\D>‘
no-auto-rehash
#prompt="\\[email protected]\\h [\\d]>"
[myisamchk]
key_buffer_size = 16M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
开启mysql实例3308
cd /data/3308
chown -R mysql.mysql ./{binlog,data,log}
./mysql_install_db --datadir=/data/3307/data --basedir=/usr/local/mysql --user=mysql --explicit_defaults_for_timestamp
/usr/local/mysql5.6/bin/mysqld_safe --defaults-file=/data/3307/my.cnf &
mysqladmin -uroot password ‘[email protected]‘ -S /data/3307/log/mysql.sock
单机多实例mysql的启动脚本:
[[email protected] log]# cat /data/3307/mysql.sh
#!/bin/sh
################################################
################################################
#init
port=3307
mysql_user="root"
mysql_pwd="[email protected]"
CmdPath="/usr/local/mysql/bin"
mysql_sock="/data/$port/log/mysql.sock"
#startup function
function_start_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "Starting MySQL...\n"
${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 /data/${port}/log/mysql.sock shutdown & > /dev/null
fi
}
#restart function
function_restart_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...\n"
else
printf "Stoping MySQL...\n"
${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/log/mysql.sock shutdown & > /dev/null
fi
sleep 1
function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /data/${port}/mysql.sh {start|stop|restart}\n"
esac