二进制安装MySQL数据库

Posted 春天的风情

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二进制安装MySQL数据库相关的知识,希望对你有一定的参考价值。

今天安装的是二进制的mysql包5.7.21的包,在配置文件的时候采了好多坑,左后还是搞定了,来和大家分享一下

 

 

 

二进制msyql5.7.21版本的主从复制安装

 

新建/picclife目录

mkdir  /picclife

新建/picclife/data 目录

mkdir  /picclife/data

创建用户和组 为mysql

groupadd  mysql

useradd   -g   mysql  mysql

将二进制mysql的包传到/picclife的目录下

解压软件包

 tar  -zxf 二进制包

改名

mv   解压出来的包  mysql

加属组属主

chown  -R mysql:mysql  mysql

 

配置环境变量

vim  /etc/profile

 

mysql_home=/picclife/mysql

export PATH=$PATH:$mysql_home/bin

 

生效

source /etc/profile

 

编辑配置文件

vim /etc/my.cnf

[client]

port                           = 3306

socket                         = /tmp/mysql.sock

##default-character-set         = utf8

[mysql]

port                           = 3306

socket                         = /tmp/mysql.sock

#default-character-set          = utf8

[mysqld]

# GENERAL #

default_storage_engine         = InnoDB

#character-set-server           = utf8

#collation-server               = utf8_unicode_ci

basedir                        = /picclife/mysql

datadir                        = /picclife/data

socket                         = /tmp/mysql.sock

pid-file                       = /picclife/data/mysql.pid

port=3306

# SAFETY #

skip_name_resolve

max_allowed_packet             = 16M

max_connect_errors             = 100000

lower-case-table-names         = 1

# BINARY LOGGING #

server-id                      = 1             #server id

log_bin                        = mysql-bin   #开启二进制日志

relay_log                       = relay-bin    #开启中级日志

expire_logs_days               = 14

sync_binlog                    = 1

binlog_format                   = ROW

transaction_isolation           = READ-COMMITTED

relay_log_info_repository       = TABLE

master_info_repository          = TABLE

# REPLICATION #

gtid_mode                      = ON

enforce_gtid_consistency       = ON

log_slave_updates              = 1

#SEMI_SYNC

#rpl_semi_sync_master_enabled=1

#rpl_semi_sync_master_timeout=10000 # 1 second

# CACHES AND LIMITS #

tmp_table_size                 = 256M

max_heap_table_size            = 256M

query_cache_type               = 0

query_cache_size               = 0

max_connections                = 5000

thread_cache_size              = 1000

open_files_limit               = 65535

table_definition_cache         = 2048

table_open_cache               = 2048

sort_buffer_size               = 2M

sql_mode                       = NO_ENGINE_SUBSTITUTION

# INNODB #

innodb_flush_method            = O_DIRECT

innodb_log_files_in_group      = 2

innodb_log_file_size           = 256M

innodb_flush_log_at_trx_commit = 1

innodb_file_per_table          = 1

innodb_buffer_pool_size        = 10G

innodb_stats_on_metadata       = 0

innodb_buffer_pool_instances   = 4

# LOGGING #

log_error                      = /picclife/data/mysql-error.log

#log_queries_not_using_indexes  = 1

slow_query_log                 = 1

slow_query_log_file            = /picclife/data/mysql-slow.log

long_query_time                = 2

log_error_verbosity=2

wait_timeout = 7200

[mysqldump]

user=root

password=123456

 

安装数据库

./bin/mysqld --initialize --user=mysql --basedir=/picclfie/mysql --datadir=/picclife/data --innodb_undo_tablespaces=3 --explicit_defaults_for_timestamp

 

创建启动文件

cp  /picclife/mysql/support-files/mysql.server /etc/init.d/mysqld

 

修改/etc/init.d/mysql

 

 

 

 加入到开机启动项

chkconfig --add mysqld

设置开机启动

chkconfig mysqld on

开启mysql

service mysqld start

启动也可以

(

数据库常规启停

mysqladmin -uroot -proot shutdown

mysqld_safe --defaults-file=/etc/my.cnf &

ps -ef|grep mysql

)

 

 

查看默认密码

grep -i password /picclife/data/mysql-error.log

用初始化密码登陆数据库修改密码

mysql -uroot -p查到的密码

修改密码

SET PASSWORD=PASSWORD(‘密码‘);

flush privileges;

然后推出可以用新改的密码登陆了

主的配置文件 已经修改好了,进入数据库授权

给从服务器slave复制的权限:

grant  replication  slave  on *.* to  tom@”从的ip”  identified  by  “123”;

刷新权限:

glush    privileges;

查看主服务器master的状态已得到二进制的名和位置:

show   master  status;

 

主就配置好了开始配置从:

从的二进制安装mysql和住的一样

就是配置文件里的server  id  不能冲突  可以开启二进制日志也可以不开启,但必须开启中继日志relay_log = mysql-relay

vim /etc/my.cnf

[client]

port                           = 3306

socket                         = /tmp/mysql.sock

##default-character-set         = utf8

[mysql]

port                           = 3306

socket                         = /tmp/mysql.sock

#default-character-set          = utf8

[mysqld]

# GENERAL #

default_storage_engine         = InnoDB

#character-set-server           = utf8

#collation-server               = utf8_unicode_ci

basedir                        = /picclife/mysql

datadir                        = /picclife/data

socket                         = /tmp/mysql.sock

pid-file                       = /picclife/data/mysql.pid

port=3306

# SAFETY #

skip_name_resolve

max_allowed_packet             = 16M

max_connect_errors             = 100000

lower-case-table-names         = 1

# BINARY LOGGING #

server-id                      = 2            #server id

log_bin                        = mysql-bin   #开启二进制日志

relay_log                       = relay-bin    #开启中级日志

expire_logs_days               = 14

sync_binlog                    = 1

binlog_format                   = ROW

transaction_isolation           = READ-COMMITTED

relay_log_info_repository       = TABLE

master_info_repository          = TABLE

# REPLICATION #

gtid_mode                      = ON

enforce_gtid_consistency       = ON

log_slave_updates              = 1

#SEMI_SYNC

#rpl_semi_sync_master_enabled=1

#rpl_semi_sync_master_timeout=10000 # 1 second

# CACHES AND LIMITS #

tmp_table_size                 = 256M

max_heap_table_size            = 256M

query_cache_type               = 0

query_cache_size               = 0

max_connections                = 5000

thread_cache_size              = 1000

open_files_limit               = 65535

table_definition_cache         = 2048

table_open_cache               = 2048

sort_buffer_size               = 2M

sql_mode                       = NO_ENGINE_SUBSTITUTION

# INNODB #

innodb_flush_method            = O_DIRECT

innodb_log_files_in_group      = 2

innodb_log_file_size           = 256M

innodb_flush_log_at_trx_commit = 1

innodb_file_per_table          = 1

innodb_buffer_pool_size        = 10G

innodb_stats_on_metadata       = 0

innodb_buffer_pool_instances   = 4

# LOGGING #

log_error                      = /picclife/data/mysql-error.log

#log_queries_not_using_indexes  = 1

slow_query_log                 = 1

slow_query_log_file            = /picclife/data/mysql-slow.log

long_query_time                = 2

log_error_verbosity=2

wait_timeout = 7200

其余的按爪功你安装和主的一样

进入数据库

进入数据库:

关闭slave:

stop   slave;

设置master的host   user  二进制的名字位置等:

change   master  to  master_host=”主的ip”,master_user=”tom”,mster_password=”123”,

master_log_file=”mysql-bin.000002”,master_log_pos=106;

开启slave

 start  slave;

查看slave的状态:

 

 

现在主从复制完成,可以在主上创建库。从上查看

 

注意:如果以上配置文件启动报错,就使用最下面的配置

 

 

 

 

 

 

 

二进制mysql安装5.7.20的配置文件

vim /etc/my.cnf

 

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

server_id=1

port = 3306

user = mysql

character-set-server = utf8mb4

default_storage_engine = innodb

log_timestamps = SYSTEM

socket = /tmp/mysql.sock

basedir = /picclife/mysql

datadir = /picclife/data

pid-file = /picclife/data/mysql.pid

max_connections = 5000

max_connect_errors = 10000

table_open_cache = 2048

max_allowed_packet = 16M

open_files_limit = 65535

####====================================[innodb]==============================

innodb_buffer_pool_size = 10G

innodb_file_per_table = 1

innodb_write_io_threads = 4

innodb_read_io_threads = 4

innodb_purge_threads = 2

innodb_flush_log_at_trx_commit = 1

innodb_log_file_size = 512M

innodb_log_files_in_group = 2

innodb_log_buffer_size = 16M

innodb_max_dirty_pages_pct = 80

innodb_lock_wait_timeout = 30

innodb_data_file_path=ibdata1:1024M:autoextend

innodb_undo_tablespaces=3

#####====================================[log]==============================

log_error = /picclife/data/mysql-error.log

slow_query_log = 1

long_query_time = 2

slow_query_log_file = /picclife/data/mysql-slow.log

sql_mode=NO_ENGINE_SUBSTITUTION

 

以上是关于二进制安装MySQL数据库的主要内容,如果未能解决你的问题,请参考以下文章

Mysql的二进制安装和基础入门操作

linux中怎么查看mysql数据库版本

部分代码片段

mysql分析源代码安装及简单调试

centos MySQL 5.5 源代码 cmake 安装

Mysql8 NDB集群二进制方式免安装配置图解