1、Mysql5.6.10安裝mysql
1.一、必要軟件c++
yum -y install gcc gcc-c++ autoconf automake bison ncurses-devel libtool-ltdl-devel* cmake make
1.二、編譯安裝sql
[root@localhost src]#groupadd mysql數據庫
[root@localhost src]# useradd mysql -g mysqlbootstrap
[root@localhost src]# pwdvim
/usr/local/srccentos
[root@localhost src]#mkdir /home/mysql/data -p安全
[root@localhost src]# mkdir /usr/local/mysqlbash
[root@localhost src]# ls服務器
mysql-5.6.10.tar.gz
Cm/pwd[root@localhost 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版本
[root@localhost src]# tar -zvxf cmake-2.8.10.2.tar.gz
[root@localhost src]# cd cmake-2.8.10.2
[root@localhost cmake-2.8.10.2]# ./bootstrap
[root@localhost cmake-2.8.12.1]#make&&make install
[root@localhost cmake-2.8.12.1]# cmake --help |head -n1
cmake version 2.8.12.1
[root@localhost cmake-2.8.12.1]# cd /usr/local/src/mysql-5.6.10/storage
有哪些存儲引擎的支持能夠看一個目錄
[root@localhost storage]# ls
archive csv federated innobase myisammrg perfschema
blackhole example heap myisam ndb
[root@localhost storage]# pwd
/usr/local/src/mysql-5.6.10/storage
[root@localhost storage]# cd /usr/local/src/mysql-5.6.10
[root@localhost 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 # 容許從本地導入數據
[root@localhost src]#make && make install
[root@localhost src]#cd /usr/local/mysql/scripts/
[root@localhostsrc]#./mysql_install_db --user=mysql --datadir=/data/mysql/data --basedir=/usr/local/mysql
[root@localhost src]#cd /usr/local/mysql/support-files/
[root@localhost src]#cp mysql.server /etc/init.d/mysqld
[root@localhost src]#chmod 755 /etc/init.d/mysqld
[root@localhost src]#cat >>/etc/profile <<EOF
export PATH=$PATH:/usr/local/mysql/bin
EOF
[root@localhost src]#source /etc/profile
[root@localhost src]#cd /usr/local/mysql/support-files/
[root@localhost support-files]#cp -f my-default.cnf /etc/my.cnf
[root@localhost 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
[root@client100 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]
[root@client100 support-files]#chkconfig --add mysqld
[root@client100 support-files]#chkconfig mysqld on
[root@localhost support-files]# chkconfig --list |grep mysql --234必須爲on
[root@client100 support-files]#service mysqld start
[root@client100 support-files]#echo "drop user 'root'@'::1';drop user ''@'localhost';drop user 'root'@'localhost.localdomain';"|mysql
[root@client100 support-files]#mysqladmin -u root password ‘haowu123'
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
若是起數據庫報錯多半不外乎兩種可能
第一種是你[root@localhostsrc]#./mysql_install_db --user=mysql --datadir=/data/mysql/data --basedir=/usr/local/mysql路徑不對那麼從新執行這句
第二種則是你有老的數據庫沒有關閉或者你屢次service mysqld start致使的。解決辦法以下
[root@localhost 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).
[root@localhost 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
[root@localhost support-files]# kill -9 47503
[root@localhost support-files]# service mysqld restart
ERROR! MySQL server PID file could not be found!
Starting MySQL.. SUCCESS!
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2、MYSQL5.5.34編譯安裝
Mysql5.5.34的安裝步驟與上面基本一致編譯的地方須要編譯徹底點另外模板複製方面也有些許不一樣
[root@localhost 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
[root@localhost 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 slave@‘%’ identified by ‘haowu@yunwei’;
刷新受權: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互爲主從搭建完成