centos7 安裝mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz的記錄

 

下載mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz安裝包

進行解壓,並對系統進行mysql安裝檢測,是否已經安裝過其他版本,如果有進行移除

[root@ccsc-12 local]# ls
bin  etc  games  include  jdk  lib  lib64  libexec  mysql-5.7.16-linux-glibc2.5-x86_64  mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz  redis  sbin  share  src
[root@ccsc-12 local]# mv mysql-5.7.16-linux-glibc2.5-x86_64  mysql-5.7.16
[root@ccsc-12 local]# ls
bin  etc  games  include  jdk  lib  lib64  libexec  mysql-5.7.16  mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz  redis  sbin  share  src
[root@ccsc-12 local]# cd mysql-5.7.16/
[root@ccsc-12 mysql-5.7.16]# ls
bin  COPYING  docs  include  lib  man  README  share  support-files

[root@ccsc-12 mysql-5.7.16]# rpm -qa | grep -i mysql
[root@ccsc-12 mysql-5.7.16]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@ccsc-12 mysql-5.7.16]# yum remove mariadb-libs-5.5.60-1.el7_5.x86_64

創建mysql工作目錄

[root@ccsc-12 mysql-5.7.16]# mkdir -p /usr/local/mysql
[root@ccsc-12 mysql-5.7.16]# mkdir -p /home/mysql/data
[root@ccsc-12 mysql-5.7.16]# 

進入mysql的bin目錄

[root@ccsc-12 mysql-5.7.16]# cd bin/
[root@ccsc-12 bin]# ls
innochecksum    myisampack         mysqlcheck                  mysqld-debug   mysql_embedded    mysql_secure_installation  mysql_tzinfo_to_sql  resolveip
lz4_decompress  my_print_defaults  mysql_client_test_embedded  mysqld_multi   mysqlimport       mysqlshow                  mysql_upgrade        resolve_stack_dump
myisamchk       mysql              mysql_config                mysqld_safe    mysql_install_db  mysqlslap                  mysqlxtest           zlib_decompress
myisam_ftdump   mysqladmin         mysql_config_editor         mysqldump      mysql_plugin      mysql_ssl_rsa_setup        perror
myisamlog       mysqlbinlog        mysqld                      mysqldumpslow  mysqlpump         mysqltest_embedded         replace
[root@ccsc-12 bin]# 

執行初始化安裝

./mysqld --initialize  --user=root   --basedir=/usr/local/mysql/ --datadir=/home/mysql/data/

[root@ccsc-12 bin]# ./mysqld --initialize  --user=root   --basedir=/usr/local/mysql/data/   --datadir=/home/mysql/data/
2019-10-18T06:46:58.303821Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-18T06:46:58.304035Z 0 [Warning] Using pre 5.5 semantics to load error messages from /usr/local/mysql/data/share/.
2019-10-18T06:46:58.304044Z 0 [Warning] If this is not intended, refer to the documentation for valid usage of --lc-messages-dir and --language parameters.
2019-10-18T06:46:58.451207Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-10-18T06:46:58.484326Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-10-18T06:46:58.539385Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 14e1ea31-f173-11e9-b042-801844e4867c.
2019-10-18T06:46:58.539878Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-10-18T06:46:58.540581Z 1 [Note] A temporary password is generated for root@localhost: ,Nfzd_I6PNOg

 

--user:表示創建mysql的系統用戶,我這裏直接使用root

如果沒有error錯誤,就是已經初始化成功

然後執行啓動

[root@ccsc-12 bin]# ./mysqld   --user=root   --basedir=/usr/local/mysql/data/   --datadir=/home/mysql/data/
2019-10-18T06:49:04.623957Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-18T06:49:04.624082Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2019-10-18T06:49:04.624119Z 0 [Note] ./mysqld (mysqld 5.7.16) starting as process 156713 ...
2019-10-18T06:49:04.625658Z 0 [Warning] Using pre 5.5 semantics to load error messages from /usr/local/mysql/data/share/.
2019-10-18T06:49:04.625663Z 0 [Warning] If this is not intended, refer to the documentation for valid usage of --lc-messages-dir and --language parameters.
2019-10-18T06:49:04.628865Z 0 [Note] InnoDB: PUNCH HOLE support not available
2019-10-18T06:49:04.628911Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-10-18T06:49:04.628923Z 0 [Note] InnoDB: Uses event mutexes
2019-10-18T06:49:04.628936Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2019-10-18T06:49:04.628946Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2019-10-18T06:49:04.628956Z 0 [Note] InnoDB: Using Linux native AIO
2019-10-18T06:49:04.629268Z 0 [Note] InnoDB: Number of pools: 1
2019-10-18T06:49:04.629408Z 0 [Note] InnoDB: Using CPU crc32 instructions
2019-10-18T06:49:04.631296Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-10-18T06:49:04.641229Z 0 [Note] InnoDB: Completed initialization of buffer pool
2019-10-18T06:49:04.643477Z 0 [Note] InnoDB: page_cleaner coordinator priority: -20
2019-10-18T06:49:04.655634Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2019-10-18T06:49:04.663574Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-10-18T06:49:04.663695Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-10-18T06:49:04.674449Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-10-18T06:49:04.675629Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2019-10-18T06:49:04.675652Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2019-10-18T06:49:04.676177Z 0 [Note] InnoDB: Waiting for purge to start
2019-10-18T06:49:04.726296Z 0 [Note] InnoDB: 5.7.16 started; log sequence number 2532034
2019-10-18T06:49:04.726446Z 0 [Note] InnoDB: Loading buffer pool(s) from /home/mysql/data/ib_buffer_pool
2019-10-18T06:49:04.726588Z 0 [Note] Plugin 'FEDERATED' is disabled.
2019-10-18T06:49:04.727728Z 0 [Note] InnoDB: Buffer pool(s) load completed at 191018 14:49:04
2019-10-18T06:49:04.731318Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2019-10-18T06:49:04.731930Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2019-10-18T06:49:04.732814Z 0 [Note] IPv6 is available.
2019-10-18T06:49:04.732836Z 0 [Note]   - '::' resolves to '::';
2019-10-18T06:49:04.732869Z 0 [Note] Server socket created on IP: '::'.
2019-10-18T06:49:04.743417Z 0 [Note] Event Scheduler: Loaded 0 events
2019-10-18T06:49:04.743573Z 0 [Note] ./mysqld: ready for connections.
Version: '5.7.16'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)

./ mysqld  --user=root --basedir=/usr/local/mysql/ --datadir=/home/mysql/data/

如果沒有error,則啓動成功,安裝完成

可以進行mysql登錄操作,第一次登錄需要一個臨時密碼

2019-10-18T06:46:58.540581Z 1 [Note] A temporary password is generated for root@localhost: ,Nfzd_I6PNOg

這個密碼在上面的初始化日誌中可以找到

[root@ccsc-12 mysql]# cd bin/
[root@ccsc-12 bin]# ./mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password=password('root');

配置mysql的my.cnf配置文件

[root@ccsc-12 bin]# cd ../support-files/
[root@ccsc-12 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@ccsc-12 support-files]# mv  my-default.cnf /etc/my.cnf
[root@ccsc-12 support-files]# 

將目錄support-files中的 my-default.cnf執行復制到/etc/my.cnf中

vi my.cnf

[root@ccsc-12 etc]# cat my.cnf 
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = ..


basedir=/usr/local/mysql

datadir=/home/mysql/data

port = 3306
socket = /tmp/mysql.sock

character_set_server=utf8

[client]

default-character-set=utf8
socket = /tmp/mysql.sock

[mysql]

default-character-set=utf8
socket = /tmp/mysql.sock


[mysqld_safe]

log-error = /home/mysql/data/logs/error.log

# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

 

[root@ccsc-12 etc]# vi my.cnf 
# socket = .....
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = ..


basedir=/usr/local/mysql/data

datadir=/home/mysql/data

character_set_server=utf8

[client]

default-character-set=utf8





# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

以下整理了參數的一些說明


[client]
port = 3309
socket =  /usr/local/mysql/tmp/mysql.sock
[mysqld]
!include  /usr/local/mysql/etc/mysqld.cnf 
#包含的配置文件 ,把用戶名,密碼文件單獨存放
 
port = 3309
bind-address = 0.0.0.0
server-id = 1 
#表示是本機的序號爲1,唯一
 
socket =  /usr/local/mysql/tmp/mysql.sock
pid-file =  /usr/local/mysql/var/mysql.pid
basedir =  /usr/local/mysql/
datadir =  /usr/local/mysql/var/
tmpdir =  /usr/local/mysql/tmp/ 
#此目錄被 MySQL用來保存臨時文件.例如,它被用來處理基於磁盤的大型排序,和內部排序一樣,以及簡單的臨時表.如果你不創建非常大的臨時文件,將其放置到 swapfs/tmpfs 文件系統上也許比較好。另一種選擇是你也可以將其放置在獨立的磁盤上.你可以使用”;”來放置多個路徑,他們會按照 roud-robin 方法被輪詢使用.
 
slave-load-tmpdir =  /usr/local/mysql/tmp/ 
#當 slave 執行 load data infile 時用
 
 
#*** skip options 相關選項 ***#
skip-name-resolve 
#禁止 MySQL 對外部連接進行 DNS 解析,使用這一選項可以消除 MySQL 進行 DNS 解析的時間。但需要注意,如果開啓該選項,則所有遠程主機連接授權都要使用 IP 地址方式,否則 MySQL 將無法正常處理連接請求!
 
skip-symbolic-links 
#不能使用連接文件,多個客戶可能會訪問同一個數據庫,因此這防止外部客戶鎖定 MySQL 服務器。 該選項默認開啓
 
skip-external-locking 
#不使用系統鎖定,要使用 myisamchk,必須關閉服務器 ,避免 MySQL的外部鎖定,減少出錯機率增強穩定性。
 
skip-slave-start 
#啓動 mysql,不啓動複製
 
skip-networking 
#開啓該選項可以徹底關閉 MySQL 的 TCP/IP 連接方式,如果 WEB 服務器是以遠程連接的方式訪問 MySQL 數據庫服務器則不要開啓該選項!否則將無法正常連接! 如果所有的進程都是在同一臺服務器連接到本地的 mysqld, 這樣設置將是增強安全的方法
 
sysdate-is-now = 1 
#把SYSDATE 函數編程爲 NOW的別名
 
#*** 系統資源相關選項 ***#
back_log = 50 
#接受隊列,對於沒建立 tcp 連接的請求隊列放入緩存中,隊列大小爲 back_log,受限制與 OS 參數,試圖設定 back_log 高於你的操作系統的限制將是無效的。默認值爲 50。對於 Linux 系統推薦設置爲小於512的整數。如果系統在一個短時間內有很多連接,則需要增大該參數的值
 
max_connections = 1000 
#指定MySQL允許的最大連接進程數。如果在訪問數據庫時經常出現"Too Many Connections"的錯誤提 示,則需要增大該參數值。
 
max_connect_errors = 10000 
#如果某個用戶發起的連接 error 超過該數值,則該用戶的下次連接將被阻塞,直到管理員執行 flush hosts ; 命令或者服務重啓, 防止黑客 , 非法的密碼以及其他在鏈接時的錯誤會增加此值
 
open_files_limit = 10240 
#MySQL打開的文件描述符限制,默認最小1024;當open_files_limit沒有被配置的時候,比較max_connections*5和ulimit-n的值,哪個大用哪個,當open_file_limit被配置的時候,比較open_files_limit和max_connections*5的值,哪個大用哪個。
 
connect-timeout = 10 
#連接超時之前的最大秒數,在 Linux 平臺上,該超時也用作等待服務器首次迴應的時間
 
wait-timeout = 28800 
#等待關閉連接的時間
 
interactive-timeout = 28800 
#關閉連接之前,允許 interactive_timeout(取代了wait_timeout)秒的不活動時間。客戶端的會話 wait_timeout 變量被設爲會話interactive_timeout 變量的值。如果前端程序採用短連接,建議縮短這2個值, 如果前端程序採用長連接,可直接註釋掉這兩個選項,默認配置(8小時)  
 
slave-net-timeout = 600 
#從服務器也能夠處理網絡連接中斷。但是,只有從服務器超過slave_net_timeout 秒沒有從主服務器收到數據才通知網絡中斷
 
net_read_timeout = 30 
#從服務器讀取信息的超時
 
net_write_timeout = 60 
#從服務器寫入信息的超時
 
net_retry_count = 10 
#如果某個通信端口的讀操作中斷了,在放棄前重試多次
 
net_buffer_length = 16384 
#包消息緩衝區初始化爲 net_buffer_length 字節,但需要時可以增長到 max_allowed_packet 字節
 
max_allowed_packet = 64M
# 服務所能處理的請求包的最大大小以及服務所能處理的最大的請求大小(當與大的BLOB 字段一起工作時相當必要), 每個連接獨立的大小.大小動態增加。 設置最大包,限制server接受的數據包大小,避免超長SQL的執行有問題 默認值爲16M,當MySQL客戶端或mysqld
服務器收到大於 max_allowed_packet 字節的信息包時,將發出“信息包過大”錯誤,並關閉連接。對於某些客戶端,如果通信信息包過大,在執行查詢期間,可能會遇到“丟失與 MySQL 服務器的連接”錯誤。默認值 16M。
 
table_cache = 512 
# 所有線程所打開表的數量. 增加此值就增加了mysqld所需要的文件描述符的數量這樣你需要確認在[mysqld_safe]中 “open-files-limit” 變量設置打開文件數量允許至少4096
 
thread_stack = 192K 
# 線程使用的堆大小. 此容量的內存在每次連接時被預留.MySQL 本身常不會需要超過 64K 的內存如果你使用你自己的需要大量堆的 UDF 函數或者你的操作系統對於某些操作需要更多的堆,你也許需要將其設置的更高一點.默認設置足以滿足大多數應用
 
thread_cache_size = 20 
# 我們在 cache 中保留多少線程用於重用.當一個客戶端斷開連接後,如果 cache 中的線程還少於 thread_cache_size,則客戶端線程被放入 cache 中.這可以在你需要大量新連接的時候極大的減少線程創建的開銷(一般來說如果你有好的線程模型的話,
這不會有明顯的性能提升.)服務器線程緩存這個值表示可以重新利用保存在緩存中線程的數量,當斷開連接時如果緩存中還有空間,那麼客戶端的線程將被放到緩存中,如果線程重新被請求,那麼請求將從緩存中讀取,如果緩存中是空的或者是新的請求,那麼這個線程將被重新創建,
如果有很多新的線程,增加這個值可以改善系統性能.通過比較 Connections 和 Threads_created 狀態的變量,可以看到這個變量的作用
根據物理內存設置規則如下:
1G  —> 8
2G  —> 16
3G  —> 32
大於3G  —> 64
 
thread_concurrency = 8 
#此允許應用程序給予線程系統一個提示在同一時間給予渴望被運行的線程的數量.該參數取值爲服務器邏輯CPU數量×2,在本例中,服務器有 2 顆物理CPU,而每顆物理CPU又支持H.T超線程,所以實際取值爲 4 × 2 = 8.設置 thread_concurrency的值的正確與否, 
對 mysql 的性能影響很大, 在多個 cpu(或多核)的情況下,錯誤設置了 thread_concurrency 的值, 會導致 mysql 不能充分利用多 cpu(或多核),出現同一時刻只能一個 cpu(或核)在工作的情況。 thread_concurrency 應設爲 CPU 核數的 2 倍.比如有一個雙核的 CPU, 
那麼 thread_concurrency 的應該爲 4; 2 個雙核的 cpu,thread_concurrency 的值應爲 8,屬重點優化參數
 
 
#*** qcache settings 相關選項 ***#
query_cache_limit = 2M 
#不緩存查詢大於該值的結果.只有小於此設定值的結果纔會被緩衝,  此設置用來保護查詢緩衝,防止一個極大的結果集將其他所有的查詢結果都覆蓋.
 
query_cache_min_res_unit = 2K 
#查詢緩存分配的最小塊大小.默認是 4KB,設置值大對大數據查詢有好處,但如果你的查詢都是小數據查詢,就容易造成內存碎片和浪費
查詢緩存碎片率 = Qcache_free_blocks / Qcache_total_blocks * 100%
如果查詢緩存碎片率超過 20%,可以用 FLUSH QUERY CACHE 整理緩存碎片,或者試試減小query_cache_min_res_unit,如果你的查詢都是小數據量的話。
查詢緩存利用率 = (query_cache_size – Qcache_free_memory) / query_cache_size *100%
查詢緩存利用率在 25%以下的話說明 query_cache_size 設置的過大,可適當減小;查詢緩存利用率在 80%以上而且 Qcache_lowmem_prunes > 50 的話說明 query_cache_size 可能有點小,要不就是碎片太多。
查詢緩存命中率 = (Qcache_hits – Qcache_inserts) / Qcache_hits * 100%
 
query_cache_size = 64M  
#指定 MySQL 查詢緩衝區的大小。可以通過在 MySQL 控制檯執行以下命令觀察:
代碼:
> SHOW VARIABLES LIKE '%query_cache%';
> SHOW STATUS LIKE 'Qcache%';如果 Qcache_lowmem_prunes 的值非常大,則表明經常出現緩衝不夠的情況;
如果 Qcache_hits 的值非常大,則表明查詢緩衝使用非常頻繁,如果該值較小反而會影響效率,那麼可以考慮不用查詢緩衝; Qcache_free_blocks,如果該值非常大,則表明緩衝區中碎片很多。
memlock # 如果你的系統支持 memlock() 函數,你也許希望打開此選項用以讓運行中的 mysql 在在內存高度
緊張的時候,數據在內存中保持鎖定並且防止可能被 swapping out,此選項對於性能有益
 
#*** default settings 相關選項 ***#
default_table_type = InnoDB 
# 當創建新表時作爲默認使用的表類型,如果在創建表示沒有特別執行表類型,將會使用此值
 
default-time-zone = system 
#服務器時區
 
character-set-server = utf8 
#server 級別字符集
 
default-storage-engine = InnoDB 
#默認存儲引擎
 
#*** tmp && heap settings 相關選項 ***#
tmp_table_size = 512M 
#臨時表的最大大小,如果超過該值,則結果放到磁盤中,此限制是針對單個表的,而不是總和.
 
max_heap_table_size = 512M 
#獨立的內存表所允許的最大容量.此選項爲了防止意外創建一個超大的內存表導致永盡所有的內存資源.
 
#*** log settings 相關選項 ***#
log-bin = mysql-bin 
#打開二進制日誌功能.在複製(replication)配置中,作爲 MASTER 主服務器必須打開此項.如果你需要從你最後的備份中做基於時間點的恢復,你也同樣需要二進制日誌.這些路徑相對於 datadir
 
log_slave_updates = 1 
#表示slave將複製事件寫進自己的二進制日誌
 
log-bin-index = mysql-bin.index 
#二進制的索引文件名
 
relay-log = relay-log 
#定義relay_log的位置和名稱,如果值爲空,則默認位置在數據文件的目錄,文件名爲host_name-relay-bin.nnnnnn(By default, relay log file names have the form host_name-relay-bin.nnnnnn in the data directory);
 
relay_log_index = relay-log.index  
#relay-log的索引文件名
 
log-warnings = 1 
# 將警告打印輸出到錯誤 log 文件.如果你對於MySQL有任何問題,你應該打開警告 log 並且仔細審查錯誤日誌,查出可能的原因.
 
log-error =  /usr/local/mysql/log/mysql.err 
#錯誤日誌路徑
 
log_output = FILE 
#參數 log_output 指定了慢查詢輸出的格式,默認爲 FILE,你可以將它設爲 TABLE,然後就可以查詢 mysql 架構下的 slow_log 表了
 
log_slow_queries 
#指定是否開啓慢查詢日誌(該參數要被slow_query_log取代,做兼容性保留)
 
slow_query_log = 1 
# 指定是否開啓慢查詢日誌. 慢查詢是指消耗了比 “long_query_time” 定義的更多時間的查詢.如果 log_long_format 被打開,那些沒有使用索引的查詢也會被記錄.如果你經常增加新查詢到已有的系統內的話. 一般來說這是一個好主意,
 
long-query-time = 1 
#設定慢查詢的閥值,超出次設定值的SQL即被記錄到慢查詢日誌,缺省值爲10s.所有的使用了比這個時間(以秒爲單位)更多的查詢會被認爲是慢速查詢.不要在這裏使用”1″, 否則會導致所有的查詢,甚至非常快的查詢頁被記錄下來(由於MySQL 目前時間的精確度只能達到秒的級別).
 
log_long_format 
# 在慢速日誌中記錄更多的信息.一般此項最好打開,打開此項會記錄使得那些沒有使用索引的查詢也被作爲到慢速查詢附加到慢速日誌裏
 
slow_query_log_file =  /usr/local/mysql/log/slow.log 
# 指定慢日誌文件存放位置,可以爲空,系統會給一個缺省的文件host_name-slow.log
 
log-queries-not-using-indexes 
#如果運行的SQL語句沒有使用索引,則mysql數據庫同樣會將這條SQL語句記錄到慢查詢日誌文件中。
 
min_examined_row_limit=1000    
#記錄那些由於查找了多餘1000次而引發的慢查詢
 
long-slow-admin-statements    
#記錄那些慢的optimize table,analyze table和alter table語句
 
log-slow-slave-statements 
#記錄由Slave所產生的慢查詢
 
general_log = 1 
#將所有到達MySQL Server的SQL語句記錄下來,默認關閉 
 
general_log_file =  /usr/local/mysql/log/mysql.log 
#general_log路徑
 
max_binlog_size = 1G 
#如果二進制日誌寫入的內容超出給定值,日誌就會發生滾動。你不能將該變量設置爲大於1GB或小於4096字節。 默認值是1GB。如果你正使用大的事務,二進制日誌還會超過max_binlog_size
 
max_relay_log_size = 1G 
#標記relaylog允許的最大值,如果該值爲0,則默認值爲max_binlog_size(1G);如果不爲0,則max_relay_log_size則爲最大的relay_log文件大小;
 
relay-log-purge = 1 
#是否自動清空不再需要中繼日誌時。默認值爲1(啓用)
 
expire_logs_days = 30 
#超過 30 天的 binlog 刪除
 
binlog_cache_size = 1M 
# 在一個事務中 binlog 爲了記錄 SQL 狀態所持有的 cache 大小,如果你經常使用大的,多聲明的事務,你可以增加此值來獲取更大的性能.所有從事務來的狀態都將被緩衝在 binlog 緩衝中然後在提交後一次性寫入到 binlog 中,如果事務比此值大, 會使用磁盤上的臨時文件來替代.此緩衝在每個連接的事務第一次更新狀態時被創建.session 級別
 
replicate-wild-ignore-table = mysql.% 
#複製時忽略數據庫及表
slave_skip_errors=all 
#定義複製過程中從服務器可以自動跳過的錯誤號,當複製過程中遇到定義的錯誤號,就可以自動跳過,直接執行後面的SQL語句。
slave_skip_errors選項有四個可用值,分別爲:off,all,ErorCode,ddl_exist_errors。
  默認情況下該參數值是off,我們可以列出具體的error code,也可以選擇all,mysql5.6及MySQL Cluster NDB 7.3以及後續版本增加了參數ddl_exist_errors,該參數包含一系列error code(1007,1008,1050,1051,1054,1060,1061,1068,1094,1146)
    一些error code代表的錯誤如下:
    1007:數據庫已存在,創建數據庫失敗
    1008:數據庫不存在,刪除數據庫失敗
    1050:數據表已存在,創建數據表失敗
    1051:數據表不存在,刪除數據表失敗
    1054:字段不存在,或程序文件跟數據庫有衝突
    1060:字段重複,導致無法插入
    1061:重複鍵名
    1068:定義了多個主鍵
    1094:位置線程ID
    1146:數據表缺失,請恢復數據庫
    1053:複製過程中主服務器宕機
    1062:主鍵衝突 Duplicate entry '%s' for key %d
    
    
#*** MyISAM 相關選項 ***#
key_buffer_size = 256M 
#指定用於索引的緩衝區大小,增加它可得到更好的索引處理性能。如果是以InnoDB引擎爲主的DB,專用於MyISAM引擎的 key_buffer_size 可以設置較小,8MB 已足夠  如果是以MyISAM引擎爲主,可設置較大,但不能超過4G. 在這裏,強烈建議不使用MyISAM引擎,默認都是用InnoDB引擎.注意:該參數值設置的過大反而會是服務器整體效率降低!
 
sort_buffer_size = 2M 
#查詢排序時所能使用的緩衝區大小。排序緩衝被用來處理類似 ORDER BY 以及 GROUP BY 隊列所引起的排序.一個用來替代的基於磁盤的合併分類會被使用.查看 “Sort_merge_passes” 狀態變量. 在排序發生時由每個線程分配 注意:該參數對應的分配內存是每連接獨佔!如果有 100 個連接,那麼實際分配的總共排序緩衝區大小爲 100 × 6 =600MB,所以,對於內存在 4GB 左右的服務器推薦設置爲 6-8M。 
 
read_buffer_size = 2M 
#讀查詢操作所能使用的緩衝區大小。和 sort_buffer_size 一樣,該參數對應的分配內存也是每連接獨享!用來做 MyISAM 表全表掃描的緩衝大小.當全表掃描需要時,在對應線程中分配.
 
join_buffer_size = 8M 
#聯合查詢操作所能使用的緩衝區大小,和 sort_buffer_size 一樣,該參數對應的分配內存也是每連接獨享!此緩衝被使用來優化全聯合(full JOINs 不帶索引的聯合).類似的聯合在極大多數情況下有非常糟糕的性能表現, 但是將此值設大能夠減輕性能影響.通過 “Select_full_join”狀態變量查看全聯合的數量, 當全聯合發生時,在每個線程中分配。
 
read_rnd_buffer_size = 8M 
#MyISAM 以索引掃描(Random Scan)方式掃描數據的 buffer大小 
 
bulk_insert_buffer_size = 64M 
#MyISAM 使用特殊的類似樹的 cache 來使得突發插入(這些插入是,INSERT … SELECT, INSERT … VALUES (…), (…), …, 以及 LOAD DATAINFILE) 更快. 此變量限制每個進程中緩衝樹的字節數.設置爲 0 會關閉此優化.爲了最優化不要將此值設置大於 “key_buffer_size”.當突發插入被檢測到時此緩衝將被分配MyISAM 用在塊插入優化中的樹緩衝區的大小。註釋:這是一個 per thread 的限制 ( bulk 大量).此緩衝當 MySQL 需要在 REPAIR, OPTIMIZE, ALTER 以及 LOAD DATA INFILE到一個空表中引起重建索引時被分配.這在每個線程中被分配.所以在設置大值時需要小心.
 
myisam_sort_buffer_size = 64M 
#MyISAM 設置恢復表之時使用的緩衝區的尺寸,當在REPAIR TABLE 或用 CREATE INDEX 創建索引或 ALTER TABLE 過程中排序 MyISAM 索引分配的緩衝區
 
myisam_max_sort_file_size = 10G
#mysql重建索引時允許使用的臨時文件最大大小
 
myisam_repair_threads = 1 
#如果該值大於 1,在 Repair by sorting 過程中並行創建MyISAM 表索引(每個索引在自己的線程內).如果一個表擁有超過一個索引, MyISAM 可以通過並行排序使用超過一個線程去修復他們.這對於擁有多個 CPU 以及大量內存情況的用戶,是一個很好的選擇.
 
myisam_recover = 64K
#允許的 GROUP_CONCAT()函數結果的最大長度
transaction_isolation = REPEATABLE-READ # 設定默認的事務隔離級別.可用的級別如下:READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ,SERIALIZABLE
1.READ UNCOMMITTED-讀未提交 2.READ COMMITTE-讀已提交 3.REPEATABLE READ -可重複讀 4.SERIALIZABLE -串行
 
 
# *** INNODB 相關選項 ***#
skip-innodb 
# 如果你的 MySQL 服務包含 InnoDB 支持但是並不打算使用的話,使用此選項會節省內存以及磁盤空間,並且加速某些部分
 
innodb_file_per_table = 1 
# InnoDB爲獨立表空間模式,每個數據庫的每個表都會生成一個數據空間
獨立表空間優點:
1.每個表都有自已獨立的表空間。
2.每個表的數據和索引都會存在自已的表空間中。
3.可以實現單表在不同的數據庫中移動。
4.空間可以回收(除drop table操作處,表空不能自已回收)
缺點:
1.單表增加過大,如超過100G
結論:
共享表空間在Insert操作上少有優勢。其它都沒獨立表空間表現好。當啓用獨立表空間時,請合理調整:innodb_open_files
 
innodb_status_file = 1 
#啓用InnoDB的status file,便於管理員查看以及監控等
 
innodb_open_files = 2048 
# 限制Innodb能打開的表的數據,如果庫裏的表特別多的情況,請增加這個。這個值默認是300
 
innodb_additional_mem_pool_size = 100M 
#設置InnoDB存儲引擎用來存放數據字典信息以及一些內部數據結構的內存空間大小,所以當我們一個MySQL Instance中的數據庫對象非常多的時候,是需要適當調整該參數的大小以確保所有數據都能存放在內存中提高訪問效率的。 
 
innodb_buffer_pool_size = 2G 
#包括數據頁、索引頁、插入緩存、鎖信息、自適應哈希所以、數據字典信息.InnoDB 使用一個緩衝池來保存索引和原始數據, 不像 MyISAM.這裏你設置越大,你在存取表裏面數據時所需要的磁盤 I/O 越少.在一個獨立使用的數據庫服務器上,你可以設置這個變量到服務器物理內存大小的 80%,不要設置過大,否則,由於物理內存的競爭可能導致操作系統的換頁顛簸.注意在 32 位系統上你每個進程可能被限制在 2-3.5G 用戶層面內存限制,所以不要設置的太高.
 
innodb_write_io_threads = 4
innodb_read_io_threads = 4
# innodb使用後臺線程處理數據頁上的讀寫 I/O(輸入輸出)請求,根據你的 CPU 核數來更改,默認是4
# 注:這兩個參數不支持動態改變,需要把該參數加入到my.cnf裏,修改完後重啓MySQL服務,允許值的範圍從 1-64
 
innodb_data_home_dir =  /usr/local/mysql/var/ 
#設置此選項如果你希望 InnoDB 表空間文件被保存在其他分區.默認保存在 MySQL 的 datadir 中.
 
innodb_data_file_path = ibdata1:500M;ibdata2:2210M:autoextend
#InnoDB將數據保存在一個或者多個數據文件中成爲表空間.如果你只有單個邏輯驅動保存你的數據,一個單個的自增文件就足夠好了.其他情況下.每個設備一個文件一般都是個好的選擇.你也可以配置 InnoDB 來使用裸盤分區 – 請參考手冊來獲取更多相關內容
 
innodb_file_io_threads = 4 
#用來同步 IO 操作的 IO 線程的數量. 此值在 Unix 下被硬編碼爲 4,但是在 Windows 磁盤 I/O 可能在一個大數值下表現的更好.
 
innodb_thread_concurrency = 16
#在 InnoDb 核心內的允許線程數量,InnoDB 試着在 InnoDB 內保持操作系統線程的數量少於或等於這個參數給出的限制,最優值依賴於應用程序,硬件以及操作系統的調度方式.過高的值可能導致線程的互斥顛簸.默認設置爲 0,表示不限制併發數,這裏推薦設置爲0,更好去發揮CPU多核處理能力,提高併發量
 
innodb_flush_log_at_trx_commit = 1 
#如果設置爲 1 ,InnoDB 會在每次提交後刷新(fsync)事務日誌到磁盤上,這提供了完整的 ACID 行爲.如果你願意對事務安全折衷, 並且你正在運行一個小的食物, 你可以設置此值到 0 或者 2 來減少由事務日誌引起的磁盤 I/O
代表日誌只大約每秒寫入日誌文件並且日誌文件刷新到磁盤.
代表日誌寫入日誌文件在每次提交後,但是日誌文件只有大約每秒纔會刷新到磁盤上.
 
innodb_log_buffer_size = 8M 
#用來緩衝日誌數據的緩衝區的大小.當此值快滿時, InnoDB 將必須刷新數據到磁盤上.由於基本上每秒都會刷新一次,所以沒有必要將此值設置的太大(甚至對於長事務而言)
 
innodb_log_file_size = 500M 
#事物日誌大小.在日誌組中每個日誌文件的大小,你應該設置日誌文件總合大小到你緩衝池大小的5%~100%,來避免在日誌文件覆寫上不必要的緩衝池刷新行爲.不論如何, 請注意一個大的日誌文件大小會增加恢復進程所需要的時間.
 
innodb_log_files_in_group = 2 
#在日誌組中的文件總數.通常來說 2~3 是比較好的.
 
innodb_log_group_home_dir =  /usr/local/mysql/var/
# InnoDB 的日誌文件所在位置. 默認是 MySQL 的 datadir.你可以將其指定到一個獨立的硬盤上或者一個 RAID1 捲上來提高其性能innodb_max_dirty_pages_pct = 90 #innodb 主線程刷新緩存池中的數據,使髒數據比例小於 90%,這是一個軟限制,不被保證絕對執行.
 
innodb_lock_wait_timeout = 50 
#InnoDB 事務在被回滾之前可以等待一個鎖定的超時秒數。InnoDB 在它自己的 鎖定表中自動檢測事務死鎖並且回滾事務。 InnoDB 用 LOCK TABLES 語句注意到鎖定設置。默認值是 50 秒
 
innodb_flush_method = O_DSYNC 
# InnoDB 用來刷新日誌的方法.表空間總是使用雙重寫入刷新方法.默認值是 “fdatasync”, 另一個是 “O_DSYNC”.
 
innodb_force_recovery=1
# 如果你發現 InnoDB 表空間損壞, 設置此值爲一個非零值可能幫助你導出你的表.從1 開始並且增加此值知道你能夠成功的導出表.
 
innodb_fast_shutdown 
# 加速 InnoDB 的關閉. 這會阻止 InnoDB 在關閉時做全清除以及插入緩衝合併.這可能極大增加關機時間, 但是取而代之的是 InnoDB 可能在下次啓動時做這些操作.
 
 
 
# *** 其他 相關選項 ***#
[mysqldump]
quick 
#支持較大數據庫的轉儲,在導出非常巨大的表時需要此項。增加該變量的值十分安全,這是因爲僅當需要時纔會分配額外內存。例如,僅當你發出長查詢或mysqld必須返回大的結果行時mysqld纔會分配更多內存。該變量之所以取較小默認值是一種預防措施,以捕獲客戶端和服務器之間的錯誤信息包,並確保不會因偶然使用大的信息包而導致內存溢出。 如果你正是用大的BLOB值,而且未爲mysqld授予爲處理查詢而訪問足夠內存的權限,也會遇到與大信息包有關的奇怪問題。如果懷疑出現了該情況,請嘗試在mysqld_safe腳本開始增加ulimit -d 256000,並重啓mysqld。
 
[mysql]
auto-rehash 
#允許通過 TAB 鍵提示
 
default-character-set = utf8 
#數據庫字符集
 
connect-timeout = 3
[mysqld_safe]
 
open-files-limit = 8192 
#增加每個進程的可打開文件數量.確認你已經將全系統限制設定的足夠高!打開大量表需要將此值設大

 通過support-files目錄下的./mysql.server  start  進行啓動

首先 vi  mysql.sock.lock編寫配置文件

配置

basedir=/usr/local/mysql
datadir=/home/mysql/data

# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
#   [mysqld]
#   basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/usr/local/mysql
datadir=/home/mysql/data

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"

 

 

 

[root@ccsc-12 mysql]# ls
bin  COPYING  data  docs  include  lib  man  README  share  support-files
[root@ccsc-12 mysql]# cd support-files/
[root@ccsc-12 support-files]# ls
magic  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@ccsc-12 support-files]# pwd
/usr/local/mysql/support-files
[root@ccsc-12 support-files]# ./mysql.server  start

 

如果出現以下錯誤時,這是個大坑

2019-10-18T08:20:53.166693Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-10-18T08:20:53.166721Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-10-18T08:20:53.166731Z 0 [ERROR] InnoDB: Operating system error number 13 in a file operation.
2019-10-18T08:20:53.166737Z 0 [ERROR] InnoDB: The error means mysqld does not have the access rights to the directory.
2019-10-18T08:20:53.166747Z 0 [ERROR] InnoDB: Cannot open datafile './ibdata1'
2019-10-18T08:20:53.166756Z 0 [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
2019-10-18T08:20:53.166764Z 0 [ERROR] InnoDB: InnoDB Database creation was aborted with error Cannot open a file. You may need to delete the ibdata1 file before trying to start up again.
2019-10-18T08:20:53.767277Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2019-10-18T08:20:53.767299Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2019-10-18T08:20:53.767309Z 0 [ERROR] Failed to initialize plugins.
2019-10-18T08:20:53.767314Z 0 [ERROR] Aborting

 

這是由於mysql的data目錄權限不夠導致,我是將整個目錄賦值爲最高權限777

[root@ccsc-12 data]# cd ../
[root@ccsc-12 mysql]# chmod -R 777 data/

將原有的ibdata1  ib_logfile0  ib_logfile1 這3個文件全部刪除,重啓會自動創建的

如果遇到以下問題時

2019-10-18T08:26:10.771601Z 0 [Note] Server socket created on IP: '::'.
2019-10-18T08:26:10.771951Z 0 [ERROR] Could not open unix socket lock file /tmp/mysql.sock.lock.
2019-10-18T08:26:10.771961Z 0 [ERROR] Unable to setup unix socket lock file.
2019-10-18T08:26:10.771967Z 0 [ERROR] Aborting

將/tmp目錄下的mysql.sock.lock 刪除即可

然後重新啓動

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章