单实例参考上一篇:
单机部署多实例是遇到很多坑,主要是my.cnf配置文件要配对;
这是我的服务器mysql的安装目录,我是压缩包安装的,所以是这个样子,
最后附上配置我的文件,从以前的单实例部署的服务器上拷贝过来,做了一些改动,可以根据适当调整,安装可以参考上一篇:
[client]
no-beep
socket =/home/mysql/mysql80/tmp/mysql.sock
# pipe
# socket=0.0
port=3307
[mysql]
#原文的utf8指向UTF8MB3,后续版本要改为UTF8MB4,一步到位吧
character-set-server = utf8mb4
#socket =/home/mysql/mysql80/mysql.sock
socket =/home/mysql/mysql80/tmp/mysql.sock
no-auto-rehash
[mysqld]
basedir=/home/mysql/mysql80/
datadir=/home/mysql/mysql80/data/
socket =/home/mysql/mysql80/tmp/mysql.sock
mysqlx_socket=/home/mysql/mysql80/tmp/mysqlx.sock
#innodb_directories=/home/mysql/mysql80/
# 修改端口
port=3307
mysqlx_port = 33070
# 时间格式
log_timestamps = SYSTEM
log-error=/home/mysql/mysql80/logs/mysqld.log
log-bin=/home/mysql/mysql80/logs/mysql-bin.log
pid-file=/home/mysql/mysql80/mysqld.pid
#skip-grant-tables
#skip-name-resolve
character-set-server=UTF8MB4
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=2
max_connections=200
#query_cache_size在8.0版本已经移除,故注释
#query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
#innodb_data_home_dir = /home/mysql/mysql80/innodb/
#innodb_data_file_path = /home/mysql/mysql80/innodb/ibdata1:10M:autoexten
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
#query_cache_type在8.0版本已经移除,故注释
#query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
user=mysql
#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d
注意:首次登录更改密码时,因为是压缩包安装,所有的执行脚本都在mysql的bin目录下:
./mysql -uroot -p -h127.0.0.1 -P3307
启动脚本:
1./home/mysql/mysql80/bin/mysqld_safe --defaults-file=/home/mysql/mysql80/conf/my.cnf --user=mysql >/dev/null &
2. 启动,重启,停止
#!/bin/sh
. /etc/init.d/functions
[ $# -ne 1 ] && {
echo "USAGE:{start|stop|restart}"
exit 1
}
start(){
/home/mysql/mysql80/bin/mysqld_safe --defaults-file=/home/mysql/mysql80/conf/my.cnf --skip-slave-start >/dev/null &
action "MySQL3306 is starting" /bin/true
exit 0
}
stop(){
port= ps -ef | grep mysql80 | grep -v grep | awk '{print $2}';
if test -z "$port"
then
/home/mysql/mysql80/bin/mysqladmin -uroot -p123456 -S /home/mysql/mysql80/mysql.sock shutdown &>/dev/null
action "MySQL is stoping" /bin/true
else
action "MySQL is stoping" /bin/false
exit 1
fi
}
restart(){
stop
sleep 2
start
}
if [ "$1" == "start" ]
then
start
elif [ "$1" == "stop" ]
then
stop
elif [ "$1" == "restart" ]
then
restart
else
echo "USAGE:{start|stop|restart}"
fi
参考地址: