从零开始的MYSQL02 --- MySQL启动方式及故障排查,多实例搭建

1. MySQL的方式及区别

    在MySQL启动遇到故障怎么排查

/etc/init/d/mysql start | restart | stop 这个脚本是一般安装后由mysql.server 自动生成,如果是直接解压使用的需要手动添加。

设置mysql自动启动:chkconfig mysql on,如果线上库,我建议关闭自动启动,线上库本着一个原则,出错了就停下来。或者脚本来控制批量的启动与停止。

/etc/init.d/mysql  ( mysql.server)

/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &

/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf &

启动:mysql -S /tmp/mysql3302.sock

关闭:mysqladmin -S /tmp/mysql3376.sock shutdown

 mysql.server 调用的mysqld_safe,mysqld_safe调用的mysqld,一组MySQL用一个唯一个端口号,所有组之间的端口号最好不要重复。

2.新建一组服务器上多实例:

mkdir -p /data/mysql/mysql3377/{data,logs,tmp}

cp /data/mysql/mysql3376/my3376.cnf /data/mysql/mysql3377/my3377.cnf

cd /data/mysql/mysql3377

chown -R mysql:mysql mysql3377

sed -i ‘s/3376/3377/g‘ my3377.cnf

准备工作做完开始初始化操作:

cd /usr/local/mysql/

./script/mysql_db_install --defaults-file=/data/mysql/mysql3377/my3377.cnf OR /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3377/my3377.cnf  &

启动:mysql -S /tmp/mysql3302.sock

关闭:mysqladmin -S /tmp/mysql3377.sock shutdown

创建多实例的基本思路:创建基础目录并修改权限,拷贝配置文件,替换端口号,初始化,启动,关闭。

多实例是可以写在同一个my.cnf里面,但是为了后续管理维护方便尽量单独一个实例使用单独的my.cnf

3.mysqld_mutli 的启动方式:

mysqld_multi 可以调用mysqld_safe,也可以调用mysqld,但是如果mysqld_multi,建议调用mysqld_safe,mysqld_multi的配置文件必须是 /etc/my.cnf。

[mysqld_multi]

mysqld=/usr/local/mysql/bin/mysqld_safe

mysqladmin = /usr/local/mysql/bin/mysqladmin

#用来做关闭mysql使用

user = root

log=/usr/local/mysql/m.log

[mysqld3376]

port=3376

socket=/tmp/mysql3376.sock

datadir=/data/mysql/mysql3376/data

server-id=1003376

log-bin=/data/mysql/mysql3376/logs/mysql-bin

tmpdir=/data/mysql/mysql3376/tmp

innodb_log_group_home_dir = /data/mysql/mysql3376/logs

innodb_buffer_pool_size=200M

    单机多实例在配置文件应该注意什么问题:

port                     port=3377

datadir                 socket=/tmp/mysql3377.sock

socket                datadir=/data/mysql/mysql3377/data

server-id             server-id=1003377

log-bin=/data/mysql/mysql3377/logs/mysql-bin

tmpdir=/data/mysql/mysql3377/tmp

innodb_log_group_home_dir = /data/mysql/mysql3377/logs

mysqld配置文件的加载顺序:/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

帮助文档:msqyld --verbose --help

安装有错误的时候要会看error log,就是错误日志,所有的问题都会记录在这里

selinux一定要禁,在生产环境中也要这样,如果公司有硬件防火墙的话最好也将iptables关掉,如果没有的话就控制好iptables开放的端口

ibdata1 大小算法:6400*16/1024,如果你的ibdata1变得很庞大很有可能是启用了共享表空间,共享表空间,即使把数据清理掉后,也不会回收空间,这种怎么处理:

1. dump出来

2. 启用独立表空间导入

如果改小了能启动吗    可以auto_extend

双实例my.cnf实际配置:

上传二进制文件到/usr/local/ && mkdir -p /software/mysql

解压:

tar -xzvf mysql-5.6.29-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.6.29-linux-glibc2.5-x86_64 mysql

创建用户、创建mysql用户和组, 设置mysql登入密码:

groupadd mysql

useradd -g mysql -d /home/mysql mysql -d意思是指定home 可以使用man查看useradd的用法

Changing password for user mysql.

New password: mysql

创建目录:

mkdir -p /data/mysql/mysql3376/{data,logs}

mkdir -p /data/mysql/mysql3377/{data,logs}

授权:

chown -R mysql:mysql /data/mysql/mysql3376/

chown -R mysql:mysql /data/mysql/mysql3377/

分别在mysql3376和mysql3377目录下创建参数文件

vi my3376.cnf

[client]

port = 3376

socket = /tmp/mysql.sock

# The MySQL server

[mysqld]

# Basic

port = 3376

user = mysql

basedir = /usr/local/mysql ##二进制安装文件存放路径

datadir = /data/mysql/mysql3376/data ##数据文件存放路径

socket = /tmp/mysql3376.sock

log_bin = mysql3376-bin

log_error = /data/mysql/mysql3376/logs/error3376.log

slow_query_log_file = /data/mysql/mysql3306/logs/slow3376.log

skip-external-locking

skip-name-resolve

log-slave-updates

explicit_defaults_for_timestamp

relay_log=mysql3376-relay-log

relay_log_index=mysql3376relay-log-index

server-id = 337601

character_set_server = utf8 ###设置字符集

slow_query_log =1

long_query_time = 1

binlog_format = ROW ###binlog格式

max_binlog_size = 512M

binlog_cache_size = 2M

expire-logs-days = 15 ##binlog日志过期天数

lower_case_table_names=1 ##不区分大小写

back_log = 3000

max_connections=1000 ###设置最大连接数

max_user_connections=1000

max_connect_errors=900

interactive_timeout=7200

connect_timeout = 20

slave_net_timeout=60

max_relay_log_size = 512M

performance_schema=0

key_buffer_size = 16M

max_allowed_packet = 1024M

sort_buffer_size = 1M

read_buffer_size = 1M

read_rnd_buffer_size = 1M

join_buffer_size = 1M

myisam_sort_buffer_size = 16M

tmp_table_size = 16M

max_heap_table_size = 64M

query_cache_type=0

query_cache_size = 0

bulk_insert_buffer_size = 16M

thread_cache_size = 100

thread_stack = 192K

skip-slave-start

# InnoDB

innodb_data_file_path = ibdata1:200M:autoextend

innodb_buffer_pool_size = 1024M

innodb_buffer_pool_instances = 8

innodb_log_file_size = 1000M

innodb_log_buffer_size = 16M

innodb_log_files_in_group = 3

innodb_flush_log_at_trx_commit = 1 ### 阿里设置为1

innodb_lock_wait_timeout = 50

innodb_sync_spin_loops = 100

innodb_max_dirty_pages_pct = 75

innodb_thread_concurrency = 0 ####5.6.29默认值为16,阿里RDS里面设置为0,0表示不限制

innodb_thread_sleep_delay = 1000

innodb_concurrency_tickets = 1000

log_bin_trust_function_creators = 1

innodb_flush_method = O_DIRECT

innodb_file_per_table = 1 设置独立表空

innodb_read_io_threads = 4

innodb_write_io_threads = 4

innodb_io_capacity = 2000

innodb_io_capacity_max = 4000

innodb_file_format = Barracuda

innodb_purge_threads=1

innodb_change_buffering=all

innodb_stats_on_metadata=OFF

[mysqldump]

quick

max_allowed_packet = 1024M

[mysql]

no-auto-rehash

max_allowed_packet = 1024M

prompt = ‘\[email protected]\h:\p\d mysql> ‘

default_character_set = utf8

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

#malloc-lib= /usr/local/mysql/lib/mysql/libjemalloc.so

3377实例参数

以下参数需要修改为和3376不一样

port datadir socket server-id binlog命名

cd /data/mysql/mysql3377/

cp /data/mysql/mysql3376/my3376.cnf my3377.cnf

sed -i ‘s/3376/3377/g‘ my3377.cnf

最后参数为

#more my3377.cnf

[client]

port = 3377

socket = /tmp/mysql.sock

# The MySQL server

[mysqld]

# Basic

port = 3377

user = mysql

basedir = /usr/local/mysql ##二进制安装文件存放路径

datadir = /data/mysql/mysql3377/data ##数据文件存放路径

socket = /tmp/mysql3377.sock

log_bin = mysql3377-bin

log_error = /data/mysql/mysql3376/logs/error3377.log

slow_query_log_file = /data/mysql/mysql3307/logs/slow3377.log

skip-external-locking

skip-name-resolve

log-slave-updates

explicit_defaults_for_timestamp

relay_log=mysql3377-relay-log

relay_log_index=mysql3377relay-log-index

server-id = 337701

character_set_server = utf8 ###设置字符集

slow_query_log =1

long_query_time = 1

binlog_format = ROW ###binlog格式

max_binlog_size = 512M

binlog_cache_size = 2M

expire-logs-days = 15 ##binlog日志过期天数

lower_case_table_names=1 ##不区分大小写

back_log = 3000

max_connections=1000 ###设置最大连接数

max_user_connections=1000

max_connect_errors=900

interactive_timeout=7200

connect_timeout = 20

slave_net_timeout=60

max_relay_log_size = 512M

performance_schema=0

key_buffer_size = 16M

max_allowed_packet = 1024M

sort_buffer_size = 1M

read_buffer_size = 1M

read_rnd_buffer_size = 1M

join_buffer_size = 1M

myisam_sort_buffer_size = 16M

tmp_table_size = 16M

max_heap_table_size = 64M

query_cache_type=0

query_cache_size = 0

bulk_insert_buffer_size = 16M

thread_cache_size = 100

thread_stack = 192K

skip-slave-start

# InnoDB

innodb_data_file_path = ibdata1:200M:autoextend

innodb_buffer_pool_size = 1024M

innodb_buffer_pool_instances = 8

innodb_log_file_size = 1000M

innodb_log_buffer_size = 16M

innodb_log_files_in_group = 3

innodb_flush_log_at_trx_commit = 1 ### 阿里设置为1

innodb_lock_wait_timeout = 50

innodb_sync_spin_loops = 100

innodb_max_dirty_pages_pct = 75

innodb_thread_concurrency = 0 ####5.6.29默认值为16,阿里RDS里面设置为0,0表示不限制

innodb_thread_sleep_delay = 1000

innodb_concurrency_tickets = 1000

log_bin_trust_function_creators = 1

innodb_flush_method = O_DIRECT

innodb_file_per_table = 1 设置独立表空

innodb_read_io_threads = 4

innodb_write_io_threads = 4

innodb_io_capacity = 2000

innodb_io_capacity_max = 4000

innodb_file_format = Barracuda

innodb_purge_threads=1

innodb_change_buffering=all

innodb_stats_on_metadata=OFF

[mysqldump]

quick

max_allowed_packet = 1024M

[mysql]

no-auto-rehash

max_allowed_packet = 1024M

prompt = ‘\[email protected]\h:\p(\d) mysql> ‘

default_character_set = utf8

[mysqlhotcopy]

interactive-timeout

[mysqld_safe]

#malloc-lib= /usr/local/mysql/lib/mysql/libjemalloc.so

数据库初始化:

cd /usr/local/mysql/

./scripts/mysql_install_db --defaults-file=/data/mysql/mysql3376/my3376.cnf

./scripts/mysql_install_db --defaults-file=/data/mysql/mysql3377/my3377.cnf

时间: 2024-10-19 18:54:24

从零开始的MYSQL02 --- MySQL启动方式及故障排查,多实例搭建的相关文章

MySQL启动方式-LNMP安装与部署博客

第2章 mysql设置启动方式更改 1.修改启动方式 [[email protected] /application/mysql/bin]# cd /application/mysql [[email protected] /application/mysql]# cp support-files/mysql.server /etc/init.d/mysqld [[email protected] /application/mysql]# chmod +x /etc/init.d/mysqld

atitit.流程标准化--- mysql启动不起来的排查流程attilax总结

atitit.流程标准化--- mysql启动不起来的排查流程attilax总结 1. mysql的启动日志文件 1 2. console方式 1 3. 安装为服务 1 3.1. 使用默认配置文件 1 3.2. 指导配置文件 2 4. 启动服务 2 1. mysql的启动日志文件 如果直接马deflt file param 就是默认参数..mysql 不能自动 search 配置文件... mysql重启的默认log是到个系统的log黑头的.... mysqld --help是help mysq

MYSQL启动后报错故障问题的解决办法

centos系统有一次异常关机后启动mysql一直报错#/etc/init.d/mysqld startStarting MySQL.. ERROR! The server quit without updating PID file (/data/mysql/linux-01.pid).查看错误日志如下[[email protected] ~]# tail /data/mysql/linux-01.err2018-06-28 21:34:28 2726 [Note] Shutting down

MySQL启动与多实例安装

启动方式及故障排查 一.几个问题 1.1 /etc/init.d/mysql 从哪来 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql 1.2 mysql能否设置成开机启动 可以,但是没必要 # 方法1: chkconfig mysql on # 方法2: echo "/etc/init.d/mysql start" >> /etc/rc.local 1.3 开机启动? 有没有必要把MySQL设

MySQL读取配置文件的顺序、启动方式、启动原理

一.MySQL读取配置文件的顺序 读取顺序:/etc/my.cnf > /etc/mysql/my.cnf > /usr/etc/my.cnf > ~/.my.cnf 命令验证:[[email protected] ~]# mysql --verbose --help | grep my.cnf order of preference, my.cnf, $MYSQL_TCP_PORT,/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.

mysql启动分析

1.mysql启动配置文件加载路径 /etc/my.cnf/ /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 2.mysql启动方式 service mysqld start /etc/init.d/mysqld start 说明mysqld来自 cp /usr/local/mysql/support-file/mysql.server  /etc/init.d/mysqld 以下3种方式,可用启动多实例 /usr/local/my

mysql的四种启动方式

mysql的四种启动方式: 1.mysqld 启动mysql服务器:./mysqld --defaults-file=/etc/my.cnf --user=root 客户端连接: mysql --defaults-file=/etc/my.cnf or mysql -S /tmp/mysql.sock 2.mysqld_safe 启动mysql服务器:./mysqld_safe --defaults-file=/etc/my.cnf --user=root & 客户端连接: mysql --de

mysql的几种启动方式

mysql的四种启动方式: 1.mysqld 启动mysql服务器:./mysqld --defaults-file=/etc/my.cnf --user=root 客户端连接: mysql --defaults-file=/etc/my.cnf or mysql -S /tmp/mysql.sock 2.mysqld_safe 启动mysql服务器:./mysqld_safe --defaults-file=/etc/my.cnf --user=root & 客户端连接: mysql --de

mysql解压版服务启动方式

使用mysql解压版,在不安装为windows服务时,使用下面的方式启动. 1.打开命令行,首先进入mysql解压目录的bin目录下 d:\mysql\bin 2.输入mysqld --console,最后出现如下类似字符说明启动成功 Version: '5.6.22' socket: '' port: 3303 MySQL Community Server (GPL) 3.保持当前命令行窗口不要关闭,再打开另一个命令行窗口用mysql命令就可以使用mysql了. Oracle is a reg