centos 下安装mysql5.5.30 + 配置主从同步

本文介绍如何手动编译安装 MySQL 5.5 版本,并配置相关参数以实现高效运行。包括安装前的准备、编译安装步骤、配置文件 my.cnf 的详细设置,以及如何初始化数据库、启动服务、修改 root 密码等内容。
摘要由CSDN通过智能技术生成
要用到cmake,如果没有安装,则先yum -y install cmake


yum install build-essential ncurses-libs ncurses-devel cmake libbz2-dev python-dev


mysql安装:


/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql




cd /tmp/mysql-5.5.30
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5530 \
-DMYSQL_DATADIR=/data/mysql/4095/data \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql4095.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=yes
make
make install


my.cnf


[client]
character-set-server = utf8
port    = 4095
socket  = /data/mysql/4095/mysql4095.sock
3306.sock


[mysqld]
server-id = 1


character-set-server = utf8
user    = mysql
port    = 4095
socket  = /data/mysql/4095/mysql4095.sock
basedir = /usr/local/mysql5530
datadir = /data/mysql/4095/data
log-error = /data/mysql/4095/mysql_error.log
pid-file = /data/mysql/4095/mysql.pid


log-bin = /data/mysql/4095/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /data/mysql/4095/relaylog/relaylog.index
#relay-log-info-file = /data/mysql/4095/relaylog/relaylog
relay-log = /data/mysql/4095/relaylog/relaylog
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema


slow_query_log=1
long_query_time=2
slow_query_log_file=/data/mysql/4095/mysql_slow.log #慢查询日志






open_files_limit    = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
#thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log-slave-updates
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover


interactive_timeout = 120
wait_timeout = 120


skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396


#master-host     =   192.168.1.2
#master-user     =   username
#master-password =   password
#master-port     =  3306






innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
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 = 32M








初始化数据库
bash scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5530 --datadir=/data/mysql/4095/data


启动/usr/local/mysql5530/bin/mysqld --defaults-file=/data/mysql/4095/my.cnf &


登陆:
/usr/local/mysql5530/bin/mysql -uroot -p -h127.0.0.1 -P4095 -S '/data/mysql/4095/mysql4095.sock'


修改root密码
mysql>use mysql ;
mysql> update user set password=PASSWORD("123456") where user='root';
mysql> FLUSH PRIVILEGES;






下面是一些主要的配置:
log_error=/data/mysql/4095/mysql_error.log
show_query_log=1
long_query_time=2
slow_query_log_file=/data/mysql/4095/mysql_slow.log #慢查询日志
#binlog记录文件
log-bin=/data/mysql/4095/binlog/binlog
binlog-ignore-db=mysql
binlog-ignore-db=test
binlog-ignore-db = information_schema
#从库的同步日志信息
relay-log-index=/data/mysql/4095/relaylog/relaylog.index
relay-log=/data/mysql/4095/relaylog/relaylog






主从同步配置
1.先安装mysql,分别启动主库和从库
像上面的配置,把mysql的数据及日志等信息都放在/data/mysql/4095下面
启动从库的话,直接cp -r 4095 4096
cd 4096 
修改my.cnf
把server-id设置成server-id = 2
把4095全部修改成4096
%s/4095/4096/g   把所有4095修改成4096


即可启动从加4096




2.在主库从库上创建同步用户
CREATE USER repl;
GRANT REPLICATION SLAVE ON *.* TO repl IDENTIFIED BY '123456';


3.读取主库的binlog日志文件跟位置
show master status;


4.在从库上配置同步
stop slave;
change master to master_host='192.168.1.141',master_port=3306,  
master_user='repl', 
master_password='123456', 
master_log_file='binlog.000063', 
master_log_pos=107;


start slave;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值