CENTOS6.5 安装 mysql5.6 以及搭建双主
Posted 极其内向的帅小伙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CENTOS6.5 安装 mysql5.6 以及搭建双主相关的知识,希望对你有一定的参考价值。
一、mysql5.6.10安装
1.1、必要软件
yum -y install gcc gcc-c++ autoconf automake bison ncurses-devel libtool-ltdl-devel* cmake make
1.2、编译安装
[[email protected] src]#groupadd mysql
[[email protected] src]# useradd mysql -g mysql
[[email protected] src]# pwd
/usr/local/src
[[email protected] src]#mkdir /home/mysql/data -p
[[email protected] src]# mkdir /usr/local/mysql
[[email protected] src]# ls
mysql-5.6.10.tar.gz
Cm/pwd[[email protected] src]# tar -zvxf mysql-5.6.10.tar.gz
Cmake软件可以编译安装也可以不编译安装目前未发现不编译安装有什么问题
Rpm包cmake在centos中版本是 2.6.4-5.el6至于为什么编译安装cmake我个人认为是由于在rhel5中没有或者版本过低有些mysql的安装还是进行在rhel5之上在cmake的官网上也正是这两种版本2.6.4是始终有下载的
下载cmake-2.8.10.2版本
[[email protected] src]# tar -zvxf cmake-2.8.10.2.tar.gz
[[email protected] src]# cd cmake-2.8.10.2
[[email protected] cmake-2.8.10.2]# ./bootstrap
[[email protected] cmake-2.8.12.1]#make&&make install
[[email protected] cmake-2.8.12.1]# cmake --help |head -n1
cmake version 2.8.12.1
[[email protected] cmake-2.8.12.1]# cd /usr/local/src/mysql-5.6.10/storage
有哪些存储引擎的支持可以看一个目录
[[email protected] storage]# ls
archive csv federated innobase myisammrg perfschema
blackhole example heap myisam ndb
[[email protected] storage]# pwd
/usr/local/src/mysql-5.6.10/storage
[[email protected] storage]# cd /usr/local/src/mysql-5.6.10
[[email protected] mysql-5.6.10]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=/data/mysql/data/ \
-DSYSCONFDIR=/etc \
-DWITH_TCP_PORT=3306 \
-DMYSQL_USER=mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1
参数配置详细解释:
其实5.6版本可以所有的关于引擎的参数不填写因为默认是全部给安装的
而5.5则不同关于-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \ 这三个是必须要自己填写的否则的话只能编译出6个引擎;
# /* -DWITH_READLINE=1 # 快捷键功能
# /* -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysqld.sock # 连接数据库socket路径
# /* -DMYSQL_TCP_PORT=3306 # 端口
# /* -DENABLED_LOCAL_INFILE=1 # 允许从本地导入数据
[[email protected] src]#make && make install
[[email protected] src]#cd /usr/local/mysql/scripts/
[[email protected]]#./mysql_install_db --user=mysql --datadir=/data/mysql/data --basedir=/usr/local/mysql
[[email protected] src]#cd /usr/local/mysql/support-files/
[[email protected] src]#cp mysql.server /etc/init.d/mysqld
[[email protected] src]#chmod 755 /etc/init.d/mysqld
[[email protected] src]#cat >>/etc/profile <<EOF
export PATH=$PATH:/usr/local/mysql/bin
EOF
[[email protected] src]#source /etc/profile
[[email protected] src]#cd /usr/local/mysql/support-files/
[[email protected] support-files]#cp -f my-default.cnf /etc/my.cnf
[[email protected] support-files]#cat >> /etc/my.cnf <<EOF
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
log-bin=mysql-bin
server_id=1
expire_logs_days=10
binlog_format=mixed
table_definition_cache=10000
max_connections=5000
key_buffer_size=2G
tmp_table_size=2G
read_buffer_size=4M
read_rnd_buffer_size=16M
sort_buffer_size=4M
join_buffer_size = 8M
thread_cache_size=64
wait_timeout=1800
query_cache_size=64M
innodb_buffer_pool_size=32G
innodb_additional_mem_pool_size=200M
innodb_sort_buffer_size=4M
innodb_log_buffer_size=4M
innodb_thread_concurrency=0
#innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_status_file = 1
open_files_limit = 60000
innodb_open_files=60000
long_query_time=0.1
slow_query_log=1
slow_query_log_file=/home/mysql/data/slow-query.log
[[email protected] support-files]#chown mysql.mysql /etc/my.cnf
更改系统参数
Vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
# 将安装目录属主改为mysql[上面更改,到这里又变成root属主了,所以可以选择更改为mysql]
[[email protected] support-files]#chkconfig --add mysqld
[[email protected] support-files]#chkconfig mysqld on
[[email protected] support-files]# chkconfig --list |grep mysql --234必须为on
[[email protected] support-files]#service mysqld start
[[email protected] support-files]#echo "drop user ‘root‘@‘::1‘;drop user ‘‘@‘localhost‘;drop user ‘root‘@‘localhost.localdomain‘;"|mysql
[[email protected] support-files]#mysqladmin -u root password ‘haowu123‘
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
如果起数据库报错多半不外乎两种可能
第一种是你[[email protected]]#./mysql_install_db --user=mysql --datadir=/data/mysql/data --basedir=/usr/local/mysql路径不对那么重新执行这句
第二种则是你有老的数据库没有关闭或者你多次service mysqld start导致的。解决办法如下
[[email protected] support-files]# service mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL.. ERROR! The server quit without updating PID file (/data/mysql/data/localhost.localdomain.pid).
[[email protected] support-files]# ps -ef |grep mysql
root 47388 1 0 17:03 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/data/mysql/data/localhost.localdomain.pid
mysql 47503 47388 0 17:03 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/data/localhost.localdomain.err --pid-file=/data/mysql/data/localhost.localdomain.pid
root 62679 11100 0 22:06 pts/0 00:00:00 grep mysql
[[email protected] support-files]# kill -9 47503
[[email protected] support-files]# service mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL.. SUCCESS!
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
二、MYSQL5.5.34编译安装
Mysql5.5.34的安装步骤与上面基本一致编译的地方需要编译完全点另外模板复制方面也有些许不同
[[email protected] mysql-5.6.10]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=/data/mysql/data/ \
-DSYSCONFDIR=/etc \
-DWITH_TCP_PORT=3306 \
-DMYSQL_USER=mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=all \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1
[[email protected] support-files]# cp my-medium.cnf /etc/my.cnf
vim /etc/my.cnf
将上面的参数加到mysqld中存在的改变参数
ARCHIVE : ARCHIVE存储引擎被用来无索引地,非常小地覆盖存储的大量数据
BLACKHOLE :存储引擎接受但不存储数据,并且检索总是返回一个空集但是会记录到日志里。
FEDERATED :储引擎把数据存在远程数据库中
InnoDB and BDB :InnoDB和BDB存储引擎提供事务安全表
MEMORY :MEMORY存储引擎提供“内存中”表,MEMORY存储引擎正式地被确定为HEAP引擎。
MyISAM :MyISAM管理非事务表。它提供高速存储和检索,以及全文搜索能力。
EXAMPLE :EXAMPLE存储引擎是一个“存根”引擎,它不做什么。
NDB Cluster : 是被MySQL Cluster用来实现分割到多台计算机上的表的存储引擎。它在MySQL-Max 5.1二进制分发版里提供。这个存储引擎当前只被Linux, Solaris, 和Mac OS X 支持。
CSV : 存储引擎把数据以逗号分隔的格式存储在文本文件中。
MERGE : 存储引擎允许集合将被处理同样的MyISAM表作为一个单独的表。就像MyISAM一样,MEMORY和MERGE存储引擎处理非事务表,这两个引擎也都被默认包含在MySQL中。在5.6中等同于MRG_MYISAM
最后如果你的存储引擎少安装了或者多安装了都没有关系你可以安装也可以卸载
1,查看一下,mysql配置是不是支持动态添加插件
mysql> show variables like "have_%";
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| have_compress | YES |
| have_crypt | YES |
| have_csv | YES |
| have_dynamic_loading | YES | //在这里是YES表示是支持的
如果是no呢,就不太好办,因为have_dynamic_loading是只读变量,
mysql> set have_dynamic_loading=1;
mysql> install plugin INNODB soname "ha_innodb.so";
mysql> install plugin INNODB_TRX soname "ha_innodb.so";
mysql> install plugin INNODB_LOCKS soname "ha_innodb.so";
mysql> install plugin INNODB_LOCK_WAITS soname "ha_innodb.so";
mysql> install plugin INNODB_CMP soname "ha_innodb.so";
mysql> install plugin INNODB_CMP_RESET soname "ha_innodb.so";
mysql> install plugin INNODB_CMPMEM soname "ha_innodb.so";
mysql> install plugin INNODB_CMPMEM_RESET soname "ha_innodb.so"
mysql> install plugin ARCHIVE soname "ha_archive.so";
安装好后,在用 show engines;或者show plugins;来查看
)
2: 搭建双主
(1): 在2台服务器上将mysql装好后修改2边的配置文件
vi /etc/my.cnf
master1开启日志模式:log_bin=mysql_bin
server_id=1
master2开启日志模式:log_bin=mysql_log
server_id=2
在master1上登入mysql: mysql –phaowu123
授权:grant replication slave on *.* to [email protected]‘%’ identified by ‘[email protected]’;
刷新授权:flush privileges;
(2): master1上show master status; 查看master状态
reset master;
在master2上用slave用户登入master1测试授权是否成功
mysql –u –p –h
在master2上登入mysql做changer master to (注;先stop slave;)
CHANGE MASTER TO
MASTER_HOST=‘’,
MASTER_USER=‘’,
MASTER_PASSWORD=‘’,
MASTER_PORT=3306,
MASTER_LOG_FILE=‘’,
MASTER_LOG_POS=
MASTER_CONNECT_RETRY=10;
start slave;
show slave status\G
看到:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes 说明OK
(3): 2台上做法一样
到此 mysql互为主从搭建完成
以上是关于CENTOS6.5 安装 mysql5.6 以及搭建双主的主要内容,如果未能解决你的问题,请参考以下文章