MySQL安裝教程(mysql5.6_bundle)


1.下載軟件包

下載鏈接:https://dev.mysql.com/downloads/mysql/5.6.html#downloads

centos6--MySQL-5.6.35-1.el6.x86_64.rpm-bundle.tar

centos7--MySQL-5.6.35-1.el7.x86_64.rpm-bundle.tar

選擇對應版本,否則會出現依賴不滿足問題。

 

2.解壓安裝數據庫

說明:以-Uvh安裝是為了保險起見;測試發現依以下順序安裝是沒有問題的,但如果出現某個包無法安裝則先跳過放最后安裝。

tar -xf MySQL-5.6.36-1.el6.x86_64.rpm-bundle.tar

rpm -Uvh MySQL-client-5.6.36-1.el6.x86_64.rpm    
rpm -Uvh MySQL-shared-5.6.36-1.el6.x86_64.rpm
rpm -Uvh MySQL-devel-5.6.36-1.el6.x86_64.rpm
rpm -Uvh MySQL-shared-compat-5.6.36-1.el6.x86_64.rpm
rpm -Uvh MySQL-embedded-5.6.36-1.el6.x86_64.rpm  
rpm -Uvh MySQL-test-5.6.36-1.el6.x86_64.rpm
rpm -Uvh MySQL-server-5.6.36-1.el6.x86_64.rpm

附server包安裝后的提示:

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h ls password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

 這步安裝和yum install mysql mysql-server mysql-devel是等效的。

 

3.配置my.cnf文件

mkdir /etc/my.cnf.d

cat >/etc/my.cnf<<EOF
[mysqld]
datadir=/mysql/data
socket=/mysql/data/mysql.sock
user=mysql
symbolic-links=0

[mysqld_safe]
log-error=/mysql/log/mysql.log
pid-file=/mysql/log/mysql.pid

# include all files from the config directory
!includedir /etc/my.cnf.d
EOF

 

 

4.配置password文件

說明:如所知的一樣mysql的配置文件就是my.cnf,之所以還有下邊這幾個文件是因為my.cnf中的!includedir語句。

cat > /etc/my.cnf.d/password.cnfx<<EOF
[client]
user=root
password=abcd1234               
EOF

 

5.配置客戶端

cat >/etc/my.cnf.d/client.cnf <<EOF
[client]
socket=/mysql/data/mysql.sock
EOF

 

6.配置服務端

說明:如果要配置主備則不同主機下邊的server_id不能相同;一些內存參數的大小可能需要根據機器情況進行修改

cat >/etc/my.cnf.d/server.cnf <<EOF
[mysqld]
port=3306
bind-address=0.0.0.0
default_storage_engine=innodb
symbolic_links=0
skip_name_resolve
skip_external_locking
lower_case_table_names=1
character_set_server=utf8
init_connect='SET NAMES utf8'
collation_server=utf8_general_ci
transaction_isolation='read-committed'
 
# Avoid Warning
explicit_defaults_for_timestamp=true

server_id=1

binlog_format=row
log_bin=mysql-bin
relay_log=relay-bin
skip_slave_start
expire_logs_days=3
max_binlog_size=1G
binlog_cache_size=64M
max_binlog_cache_size=128M
log-bin-trust-function-creators=1
back_log=600
max_connections=5000
max_user_connections=4000
max_connect_errors=6000
connect_timeout=60 
query_cache_type=1
query_cache_size=256M
query_cache_limit=32M

#query_cache_min_res_unit=2k
table_open_cache=4096
sort_buffer_size=32M
join_buffer_size=32M
thread_cache_size=300
long_query_time=2
key_buffer_size=256M
read_buffer_size=4M
read_rnd_buffer_size=16M
tmp_table_size=256M
max_heap_table_size=1G
max_allowed_packet=32M
bulk_insert_buffer_size=64M
innodb_buffer_pool_size=6G
innodb_log_file_size=512M
innodb_log_buffer_size=16M
innodb_log_files_in_group=2
innodb_max_dirty_pages_pct=90
innodb_lock_wait_timeout=120
innodb_file_per_table=1
innodb_file_io_threads=4
innodb_read_io_threads=8
innodb_write_io_threads=8
innodb_thread_concurrency=4
innodb_flush_log_at_trx_commit=2

EOF

 

 7.相應修改啟動文件中相應的datadir等項的值

/etc/init.d/mysqld中修改datadir/errlogfile/mypidfile三項的值(不同版本賦值形式可能不一樣)

/usr/bin/mysqld_safe中修改DATADIR的值(此操作似乎只是CentOS需要)

 

8.mysql家目錄下創建基本目錄

mkdir /mysql
cd /mysql
mkdir adm
mkdir data
mkdir log
ln -s /etc/my.cnf.d/ /mysql/conf
ln -s /var/data/mysql/data/mysql.sock /mysql/data/mysql.sock

 

9.將配置文件賦權給mysql用戶

chown -R mysql:mysql /mysql
chown mysql:mysql /etc/my.cnf
chown -R mysql:mysql /etc/my.cnf.d

 

10.配置mysqlsudo

cat >/etc/sudoers.d/mysql <<EOF
mysql ALL=NOPASSWD: /sbin/service mysql *
EOF

 

11.安裝數據庫

說明:

在最后一個命令中要求的root初始密碼在/root/.mysql_secret文件中

如果是5.1等舊版本root為空密碼要求輸入密碼時直接回車即可

在Set root password和Reload privilege tables選擇Y將密碼修改為為password.cnf中配置的密碼。

setenforce 0               #關閉selinux,不然可能service無法啟動mysql(mysqld_safe可以)
mysql_install_db #依配置文件初始化數據庫data,並創建系統表 service mysql start #啟動mysql
ln -s /mysql/data/mysql.sock /var/lib/mysql/mysql.sock #mysql_secure_installation中的sock文件位置未修改所以要創軟鏈接包過去 mysql_secure_installation #增刪用戶和修改密碼等

 

12.password文件名字改.cnf以使配置生效

mv /etc/my.cnf.d/password.cnfx /etc/my.cnf.d/password.cnf

到此單個數據庫的安裝已經安裝完成啟動后即可修用password文件中的用戶名密碼登錄。

其實由於我們在password.cnf中設了用戶名密碼所以直接執行mysql命令即可登錄,mysql會自動使用password.cnf中的用戶名和密碼去登錄。

如果配置主從,則主從都按以上步驟完成安裝后繼續執行以下步驟。

 

13.安裝半同步組件

登錄數據庫后都執行:

INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';(主)

INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';(從)

SHOW PLUGINS;

 

14.創建用於同步的REPLICATION用戶

grant replication slave, replication client on *.* to 'repl'@'91.2.9.21' identified by 'rEp^1@3#';(主)

grant replication slave, replication client on *.* to 'repl'@'91.2.9.22' identified by 'rEp^1@3#';(從)

flush privileges;

select * from mysql.user\G;

 

15.主庫查看同步信息

 show master status \G;

 

16.從庫指向主庫

CHANGE MASTER TO MASTER_HOST='192.168.220.136',

-> MASTER_USER='ls',--之前在主中添加的用以同步的用戶      

-> MASTER_PASSWORD='ls',--之前添加的用戶的密碼       

-> MASTER_LOG_FILE='mysql-bin.000001',--值為主中查詢到的File

-> MASTER_LOG_POS=1210; --值為從主中查詢到的Position

 

17.從庫啟動slave

start slave;

show slave status\G;

 

18.啟動半同步

動態修改(即登錄數據庫后執行,主備都要):

set global rpl_semi_sync_master_enabled =1;(主)

set global rpl_semi_sync_master_timeout = 10000;(主)

set global rpl_semi_sync_slave_enabled =1;(從)

 

靜態修改(即在6中的server.cnf文件中加入,主從都要):

rpl_semi_sync_master_enabled=1

rpl_semi_sync_slave_enabled=1

rpl_semi_sync_master_timeout=10000

 

19.設置從庫只讀

即在從庫的server.cnf中再加:

read_only=1

 

20.從查看是否成功啟動同步

show slave status \G;

如果Slave_IO_RunningSlave_SQL_Running的值為yes表示啟動成功

 

 

啟動報錯: log file ./ib_logfile0 is of different size 0 5242880 bytes InnoDB: than specified in the .cnf file 0 536870912 bytes!

find / -name ib_logfile0                   #定位文件位置
mv ib_logfile0 ib_logfile0.bak
mv ib_logfile1 ib_logfile1.bak
service mysqld start #再次啟動即可

 參考:http://www.cnblogs.com/sysk/p/5801934.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM