您好,登錄后才能下訂單哦!
這篇文章主要介紹了mysql5.7如何安裝,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
一、軟件下載
登錄到 http://dev.mysql.com/downloads/mysql/ ,選擇對應的版本進行下載。
二、創建mysql 用戶
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -g mysql mysql
[root@localhost ~]# passwd mysql
將tar 包拷貝到mysql的home 目錄下,進行解壓后得到的目錄 重命名為 mysql-5.7.9
三、安裝數據庫
進入 /mysql/mysql5.7/bin
[mysql@localhost bin]$ ./mysql_install_db --user=mysql --basedir=/mysql/mysql5.7 --datadir=/mysql/mysql5.7/data
2017-04-19 06:49:00 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2017-04-19 06:49:07 [ERROR] The bootstrap log isn't empty:
2017-04-19 06:49:07 [ERROR] 2017-04-19T14:49:01.852039Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2017-04-19T14:49:01.868000Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-04-19T14:49:01.868056Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-04-19T14:49:01.888730Z 0 [ERROR] Can't read from messagefile '/usr/share/mysql/english/errmsg.sys'
提示mysql_install_db 命令已棄用,使用mysqld
[mysql@localhost bin]$ ./mysqld --user=mysql --basedir=/mysql/mysql5.7 --datadir=/mysql/mysql5.7/data
[root@webtest1 mysql]# bin/mysqld --initialize --user=mysql --basedir=/mysql/mysql5.7 --datadir=/mysql/mysql5.7/data
2017-04-19T14:50:18.145225Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2017-04-19T14:50:18.145526Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2017-04-19T14:50:18.797964Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-04-19T14:50:18.798019Z 0 [Warning] Insecure configuration for --secure-file-priv: Current value does not restrict location of generated files. Consider setting it to a valid, non-empty path.
2017-04-19T14:50:18.798053Z 0 [Note] ./mysqld (mysqld 5.7.9) starting as process 3578 ...
2017-04-19T14:50:18.798104Z 0 [ERROR] Can't find error-message file '/mysql/mysql5.7share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
2017-04-19T14:50:18.802586Z 0 [Note] InnoDB: PUNCH HOLE support not available
2017-04-19T14:50:18.802645Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-04-19T14:50:18.802656Z 0 [Note] InnoDB: Uses event mutexes
2017-04-19T14:50:18.802665Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2017-04-19T14:50:18.802674Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-04-19T14:50:18.802682Z 0 [Note] InnoDB: Using Linux native AIO
2017-04-19T14:50:18.803153Z 0 [Note] InnoDB: Number of pools: 1
2017-04-19T14:50:18.803868Z 0 [Note] InnoDB: Using CPU crc32 instructions
2017-04-19T14:50:18.843406Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2017-04-19T14:50:18.860507Z 0 [Note] InnoDB: Completed initialization of buffer pool
2017-04-19T14:50:18.864349Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2017-04-19T14:50:18.878937Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2017-04-19T14:50:18.901395Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2017-04-19T14:50:18.901629Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2017-04-19T14:50:18.943961Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2017-04-19T14:50:18.945376Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2017-04-19T14:50:18.945403Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2017-04-19T14:50:18.952368Z 0 [Note] InnoDB: 5.7.9 started; log sequence number 2471242
2017-04-19T14:50:18.974882Z 0 [Note] InnoDB: Loading buffer pool(s) from /mysql/mysql5.7/data/ib_buffer_pool
2017-04-19T14:50:18.976665Z 0 [Note] InnoDB: Buffer pool(s) load completed at 151119 6:50:18
2017-04-19T14:50:18.978694Z 0 [Note] InnoDB: not started
2017-04-19T14:50:18.978878Z 0 [Note] Plugin 'FEDERATED' is disabled.
2017-04-19T14:50:18.983412Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2017-04-19T14:50:18.984289Z 0 [Warning] CA certificate ca.pem is self signed.
2017-04-19T14:50:19.003696Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2017-04-19T14:50:19.021246Z 0 [Note] IPv6 is available.
2017-04-19T14:50:19.021291Z 0 [Note] - '::' resolves to '::';
2017-04-19T14:50:19.021299Z 0 [Note] Server socket created on IP: '::'.
2017-04-19T14:50:19.037949Z 0 [ERROR] Could not create unix socket lock file /var/lib/mysql/mysql.sock.lock.
2017-04-19T14:50:19.037976Z 0 [ERROR] Unable to setup unix socket lock file.
2017-04-19T14:50:19.037982Z 0 [ERROR] Aborting
2017-04-19T14:50:19.038004Z 0 [Note] Binlog end
2017-04-19T14:50:19.038084Z 0 [Note] Shutting down plugin 'ngram'
2017-04-19T14:50:19.038094Z 0 [Note] Shutting down plugin 'ARCHIVE'
2017-04-19T14:50:19.038098Z 0 [Note] Shutting down plugin 'partition'
2017-04-19T14:50:19.038102Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2017-04-19T14:50:19.038106Z 0 [Note] Shutting down plugin 'CSV'
2017-04-19T14:50:19.038112Z 0 [Note] Shutting down plugin 'MEMORY'
2017-04-19T14:50:19.038118Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2017-04-19T14:50:19.038124Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2017-04-19T14:50:19.038128Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2017-04-19T14:50:19.038131Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2017-04-19T14:50:19.038135Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2017-04-19T14:50:19.038138Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2017-04-19T14:50:19.038142Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2017-04-19T14:50:19.038145Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2017-04-19T14:50:19.038149Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2017-04-19T14:50:19.038152Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2017-04-19T14:50:19.038155Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2017-04-19T14:50:19.038159Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2017-04-19T14:50:19.038162Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2017-04-19T14:50:19.038165Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2017-04-19T14:50:19.038168Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2017-04-19T14:50:19.038172Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2017-04-19T14:50:19.038175Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2017-04-19T14:50:19.038179Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2017-04-19T14:50:19.038182Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2017-04-19T14:50:19.038186Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2017-04-19T14:50:19.038189Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2017-04-19T14:50:19.038192Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2017-04-19T14:50:19.038196Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2017-04-19T14:50:19.038199Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2017-04-19T14:50:19.038203Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2017-04-19T14:50:19.038206Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2017-04-19T14:50:19.038210Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2017-04-19T14:50:19.038213Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2017-04-19T14:50:19.038217Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2017-04-19T14:50:19.038221Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2017-04-19T14:50:19.038224Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2017-04-19T14:50:19.038228Z 0 [Note] Shutting down plugin 'InnoDB'
2017-04-19T14:50:19.038317Z 0 [Note] InnoDB: FTS optimize thread exiting.
2017-04-19T14:50:19.038421Z 0 [Note] InnoDB: Starting shutdown...
2017-04-19T14:50:19.151526Z 0 [Note] InnoDB: Dumping buffer pool(s) to /mysql/mysql5.7/data/ib_buffer_pool
2017-04-19T14:50:19.152515Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 151119 6:50:19
2017-04-19T14:50:20.802442Z 0 [Note] InnoDB: Shutdown completed; log sequence number 2471261
2017-04-19T14:50:20.811473Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2017-04-19T14:50:20.811528Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2017-04-19T14:50:20.811690Z 0 [Note] Shutting down plugin 'MyISAM'
2017-04-19T14:50:20.811730Z 0 [Note] Shutting down plugin 'sha256_password'
2017-04-19T14:50:20.811739Z 0 [Note] Shutting down plugin 'mysql_native_password'
2017-04-19T14:50:20.812061Z 0 [Note] Shutting down plugin 'binlog'
2017-04-19T14:50:20.813161Z 0 [Note]
在mysql5.7.17的安裝過程中,初始化參數使用了--initialize-insecure,這樣不會設置初始化root密碼,如果是 --initialize的話,會隨機生成一個密碼,這個密碼顯示在安裝過程最后
2017-04-19T14:50:20.813161Z 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: 2800d0e1-a3ec-11e7-a082-005056bb44b1.
2017-04-19T14:50:20.813161Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-04-19T14:50:20.813161Z 1 [Note] A temporary password is generated for root@localhost: VfAG=aal=8;/
四、配置文件
[root@localhost ~]# cd /mysql/mysql5.7/support-files/
[root@localhost support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf'? yes
[root@localhost support-files]# cp mysql.server /etc/init.d/mysql
[root@localhost ~]# vim /etc/init.d/mysql
basedir=/mysql/mysql5.7
datadir=/mysql/mysql5.7/data
五、配置環境變量
[mysql@localhost ~]$ vi .bash_profile
PATH=$PATH:$HOME/bin
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export MYSQL_HOME="/mysql/mysql5.7"
export PATH="$PATH:$MYSQL_HOME/bin"
~
六、添加開機啟動服務
chkconfig --add mysql
chkconfig mysql on
七、啟動mysql
[root@localhost support-files]# su - mysql
報錯1
[mysql@localhost ~]$ service mysql start
/etc/init.d/mysql: line 256: my_print_defaults: command not found
Starting MySQL ERROR! Couldn't find MySQL server (/mysql/mysql5.7/bin/mysqld_safe)
啟動報錯了,原來是編輯/etc/init.d/mysql 文件出錯了,修改為下面
vim /etc/init.d/mysql
basedir=/mysql/mysql5.7
datadir=/mysql/mysql5.7/data
[mysql@localhost ~]$ service mysql start
Starting MySQL. SUCCESS!
再次啟動成功
報錯2
[mysql@goldqua1 ~]$ service mysqld start
Starting MySQL.2017-04-19T02:28:36.399450Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
The server quit without updating PID file (/mysql/mysql5.7/data/goldqua1.pid).[FAILED]
說明:mysqld_safe啟動腳本默認的從/usr/local/mysql目錄中讀取另外一個啟動腳本mysqld,因為我的安裝目錄為/mysql/mysql5.7product/5.6/mysql-1。所以找不到相關文件。可以從兩個方面解決。
方法一:在/usr/local/mysql創建鏈接文件
1.mkdir -p /usr/local/mysql/bin
2.ln -s /mysql/mysql5.7/bin/mysqld /usr/local/mysql/bin/mysqld
方法二:將mysqld_safe中的所有/usr/local/mysql目錄改為自己實際的安裝目錄
1.<pre name="code" class="sql">sed -i 's#/usr/local/mysql#/mysql/mysql5.7product/5.6/mysql-1#g' /mysql/mysql5.7product/5.6/mysql-1/bin/mysqld_safe
再次啟動成功。
報錯3
mysql> show databases;
ERROR 1820 (HY000): Unknown error 1820
mysql> use mysql;
ERROR 1820 (HY000): Unknown error 1820
mysql> show databases;
ERROR 1820 (HY000): Unknown error 1820
這里,不管怎么執行都會報錯,挺奇怪的,后來發現需要首先執行密碼修改
mysql> set password=password('(Kl1b4X*');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
初始密碼:
[root@localhost bin]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2016-06-01 15:23:25
,xxxxxR5H9
[root@localhost bin]# ./mysql -uroot -p
八、網絡上出現的故障處理方法:
1、故障現象
[root@mysqltest mysqldata]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysqldata/mysql.sock' (111)
#故障環境
[root@mysqltest mysqldata]# more /etc/issue
CentOS release 5.9 (Final)
Kernel \r on an \m
2、故障分析
#查看mysql實例的狀態
[root@mysqltest mysqldata]# netstat -ntlp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 13001/mysqld
#查看my.cnf關于socket的配置
[root@mysqltest mysqldata]# more /etc/my.cnf |grep sock
socket = /tmp/mysql.sock
#由上可知my.cnf中定義的為/tmp目錄下,而錯誤提示為/data/mysqldata/目錄下
#也就是說mysqld已經聲稱了正確的sock文件,但客戶端連接還是從初始目錄去找sock文件
#下面查看后臺日志,有個ERROR,是關于滿查詢日志的,是由于目錄不存在而產生的錯誤,與當前故障無關
[root@mysqltest mysqldata]# more mysqltest.err
............
2014-10-11 13:17:21 13001 [Note] InnoDB: 5.6.12 started; log sequence number 1625997
/app/soft/mysql/bin/mysqld: File '/log/mysql_logs/slowquery.log' not found (Errcode: 2 - No such file or directory)
2014-10-11 13:17:21 13001 [ERROR] Could not use /log/mysql_logs/slowquery.log for logging (error 2). Turning logging off for the who
le duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
2014-10-11 13:17:21 13001 [Note] Server hostname (bind-address): '*'; port: 3306
2014-10-11 13:17:21 13001 [Note] IPv6 is available.
2014-10-11 13:17:21 13001 [Note] - '::' resolves to '::';
2014-10-11 13:17:21 13001 [Note] Server socket created on IP: '::'.
2014-10-11 13:17:21 13001 [Note] Event Scheduler: Loaded 0 events
2014-10-11 13:17:21 13001 [Note] /app/soft/mysql/bin/mysqld: ready for connections.
Version: '5.6.12-log' socket: '/tmp/mysql.sock' port: 3306 Source distribution
3、解決故障
a、通過配置my.cnf mysql選項socket文件位置解決
#先停止mysql服務器
[root@mysqltest mysqldata]# service mysqld stop
Shutting down MySQL.[ OK ]
#修改my.cnf,如下
[root@mysqltest mysqldata]# vi /etc/my.cnf
[mysql]
no-auto-rehash
socket = /tmp/mysql.sock #添加該行
#重啟mysql服務器
[root@mysqltest mysqldata]# service mysqld start
Starting MySQL..[ OK ]
#再次連接正常
[root@mysqltest mysqldata]# mysql -uroot -p
Enter password:
mysql> show variables like 'version';
+---------------+------------+
| Variable_name | Value |
+---------------+------------+
| version | 5.6.12-log |
+---------------+------------+
b、為socket文件建立鏈接方式
[root@mysqltest mysqldata]# ln -s /tmp/mysql.sock /data/mysqldata/mysql.sock
ln: creating symbolic link `/data/mysqldata/mysql.sock' to `/tmp/mysql.sock': File exists
[root@mysqltest mysqldata]# rm mysql.sock #上面提示文件存在,所以刪除之前的mysql.sock文件
[root@mysqltest mysqldata]# ln -s /tmp/mysql.sock /data/mysqldata/mysql.sock
[root@mysqltest mysqldata]# ls -hltr mysql.sock
lrwxrwxrwx 1 root root 15 Oct 11 14:00 mysql.sock -> /tmp/mysql.sock
[root@mysqltest mysqldata]# mysql -uroot -p
Enter password:
mysql> show variables like 'socket';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| socket | /tmp/mysql.sock |
+---------------+-----------------+
九、mysql undo空間說明
[ERROR] InnoDB: Expected to open 4 undo tablespaces but was able to find only 0 undo tablespaces. Set the innodb_undo_tablespaces parameter to the correct value and retry. Suggested value is 0
報錯原因:
在初始化數據庫的時候沒有指定innodb_undo_tablespaces參數
解決方法:
在初始化數據庫的時候寫上--defaults-file參數,在對應的配置文件中寫上對應的innodb_undo_tablespaces參數
[mysql@localhost mysql_data]$ vi /tmp/my.cnf
##InnoDB engine undo log related setting
innodb_undo_directory = /u01/mysql_data
innodb_undo_tablespaces = 4
[mysql@localhost percona]$ bin/mysqld --defaults-file=/tmp/my.cnf --user=mysql --initialize-insecure
注意初始化數據庫語句的寫法,將--defaults-file放到語句最后會導致配置文件中的參數不會生效
十、參數說明
# MySql5.7配置文件my.cnf設置
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
###############################基礎設置#####################################
#Mysql服務的唯一編號 每個mysql服務Id需唯一
server-id = 1
#服務端口號 默認3306
port = 3306
#mysql安裝根目錄
basedir = /opt/mysql
#mysql數據文件所在位置
datadir = /opt/mysql/data
#臨時目錄 比如load data infile會用到
tmpdir = /tmp
#設置socke文件所在目錄
socket = /tmp/mysql.sock
#主要用于MyISAM存儲引擎,如果多臺服務器連接一個數據庫則建議注釋下面內容
skip-external-locking
#只能用IP地址檢查客戶端的登錄,不用主機名
skip_name_resolve = 1
#事務隔離級別,默認為可重復讀,mysql默認可重復讀級別(此級別下可能參數很多間隙鎖,影響性能)
transaction_isolation = READ-COMMITTED
#數據庫默認字符集,主流字符集支持一些特殊表情符號(特殊表情符占用4個字節)
character-set-server = utf8mb4
#數據庫字符集對應一些排序等規則,注意要和character-set-server對應
collation-server = utf8mb4_general_ci
#設置client連接mysql時的字符集,防止亂碼
init_connect='SET NAMES utf8mb4'
#是否對sql語句大小寫敏感,1表示不敏感
lower_case_table_names = 1
#最大連接數
max_connections = 400
#最大錯誤連接數
max_connect_errors = 1000
#TIMESTAMP如果沒有顯示聲明NOT NULL,允許NULL值
explicit_defaults_for_timestamp = true
#SQL數據包發送的大小,如果有BLOB對象建議修改成1G
max_allowed_packet = 128M
#MySQL連接閑置超過一定時間后(單位:秒)將會被強行關閉
#MySQL默認的wait_timeout 值為8個小時, interactive_timeout參數需要同時配置才能生效
interactive_timeout = 1800
wait_timeout = 1800
#內部內存臨時表的最大值 ,設置成128M。
#比如大數據量的group by ,order by時可能用到臨時表,
#超過了這個值將寫入磁盤,系統IO壓力增大
tmp_table_size = 134217728
max_heap_table_size = 134217728
#禁用mysql的緩存查詢結果集功能
#后期根據業務情況測試決定是否開啟
#大部分情況下關閉下面兩項
query_cache_size = 0
query_cache_type = 0
##----------------------------用戶進程分配到的內存設置BEGIN-----------------------------##
##每個session將會分配參數設置的內存大小
#用于表的順序掃描,讀出的數據暫存于read_buffer_size中,當buff滿時或讀完,將數據返回上層調用者
#一般在128kb ~ 256kb,用于MyISAM
#read_buffer_size = 131072
#用于表的隨機讀取,當按照一個非索引字段排序讀取時會用到,
#一般在128kb ~ 256kb,用于MyISAM
#read_rnd_buffer_size = 262144
#order by或group by時用到
#建議先調整為2M,后期觀察調整
sort_buffer_size = 2097152
#一般數據庫中沒什么大的事務,設成1~2M,默認32kb
binlog_cache_size = 524288
##---------------------------用戶進程分配到的內存設置END-------------------------------##
#在MySQL暫時停止響應新請求之前的短時間內多少個請求可以被存在堆棧中
#官方建議back_log = 50 + (max_connections / 5),封頂數為900
back_log = 130
############################日 志 設置##########################################
#數據庫錯誤日志文件
log_error = error.log
#慢查詢sql日志設置
slow_query_log = 1
slow_query_log_file = slow.log
#檢查未使用到索引的sql
log_queries_not_using_indexes = 1
#針對log_queries_not_using_indexes開啟后,記錄慢sql的頻次、每分鐘記錄的條數
log_throttle_queries_not_using_indexes = 5
#作為從庫時生效,從庫復制中如何有慢sql也將被記錄
log_slow_slave_statements = 1
#慢查詢執行的秒數,必須達到此值可被記錄
long_query_time = 8
#檢索的行數必須達到此值才可被記為慢查詢
min_examined_row_limit = 100
#mysql binlog日志文件保存的過期時間,過期后自動刪除
expire_logs_days = 5
############################主從復制 設置########################################
#開啟mysql binlog功能
log-bin=mysql-bin
#binlog記錄內容的方式,記錄被操作的每一行
binlog_format = ROW
#對于binlog_format = ROW模式時,減少記錄日志的內容,只記錄受影響的列
binlog_row_image = minimal
#master status and connection information輸出到表mysql.slave_master_info中
master_info_repository = TABLE
#the slave's position in the relay logs輸出到表mysql.slave_relay_log_info中
relay_log_info_repository = TABLE
#作為從庫時生效,想進行級聯復制,則需要此參數
log_slave_updates
#作為從庫時生效,中繼日志relay-log可以自我修復
relay_log_recovery = 1
#作為從庫時生效,主從復制時忽略的錯誤
slave_skip_errors = ddl_exist_errors
##---redo log和binlog的關系設置BEGIN---##
#(步驟1) prepare dml相關的SQL操作,然后將redo log buff中的緩存持久化到磁盤
#(步驟2)如果前面prepare成功,那么再繼續將事務日志持久化到binlog
#(步驟3)如果前面成功,那么在redo log里面寫上一個commit記錄
#當innodb_flush_log_at_trx_commit和sync_binlog都為1時是最安全的,
#在mysqld服務崩潰或者服務器主機crash的情況下,binary log只有可能丟失最多一個語句或者一個事務。
#但是都設置為1時會導致頻繁的io操作,因此該模式也是最慢的一種方式。
#當innodb_flush_log_at_trx_commit設置為0,mysqld進程的崩潰會導致上一秒鐘所有事務數據的丟失。
#當innodb_flush_log_at_trx_commit設置為2,只有在操作系統崩潰或者系統掉電的情況下,上一秒鐘所有事務數據才可能丟失。
#commit事務時,控制redo log buff持久化磁盤的模式 默認為1
innodb_flush_log_at_trx_commit = 2
#commit事務時,控制寫入mysql binlog日志的模式 默認為 0
#innodb_flush_log_at_trx_commit和sync_binlog都為1時,mysql最為安全但性能上壓力也是最大
sync_binlog = 1
##---redo log 和 binlog的關系設置END---##
############################Innodb設置##########################################
#數據塊的單位8k,默認是16k,16kCPU壓力稍小,8k對select的吞吐量大
#innodb_page_size的參數值也影響最大索引長度,8k比16k的最大索引長度小
#innodb_page_size = 8192
#一般設置物理存儲的60% ~ 70%
innodb_buffer_pool_size = 1G
#5.7.6之后默認16M
#innodb_log_buffer_size = 16777216
#該參數針對unix、linux,window上直接注釋該參數.默認值為NULL
#O_DIRECT減少操作系統級別VFS的緩存和Innodb本身的buffer緩存之間的沖突
innodb_flush_method = O_DIRECT
#此格式支持壓縮, 5.7.7之后為默認值
innodb_file_format = Barracuda
#CPU多核處理能力設置,假設CPU是2顆4核的,設置如下
#讀多,寫少可以設成2:6的比例
innodb_write_io_threads = 4
innodb_read_io_threads = 4
#提高刷新臟頁數量和合并插入數量,改善磁盤I/O處理能力
#默認值200(單位:頁)
#可根據磁盤近期的IOPS確定該值
innodb_io_capacity = 500
#為了獲取被鎖定的資源最大等待時間,默認50秒,超過該時間會報如下錯誤:
# ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
innodb_lock_wait_timeout = 30
#調整buffer pool中最近使用的頁讀取并dump的百分比,通過設置該參數可以減少轉儲的page數
innodb_buffer_pool_dump_pct = 40
#設置redoLog文件所在目錄, redoLog記錄事務具體操作內容
innodb_log_group_home_dir = /opt/mysql/redolog/
#設置undoLog文件所在目錄, undoLog用于事務回滾操作
innodb_undo_directory = /opt/mysql/undolog/
#在innodb_log_group_home_dir中的redoLog文件數, redoLog文件內容是循環覆蓋寫入。
innodb_log_files_in_group = 3
#MySql5.7官方建議盡量設置的大些,可以接近innodb_buffer_pool_size的大小
#之前設置該值較大時可能導致mysql宕機恢復時間過長,現在恢復已經加快很多了
#該值減少臟數據刷新到磁盤的頻次
#最大值innodb_log_file_size * innodb_log_files_in_group <= 512GB,單文件<=256GB
innodb_log_file_size = 1024M
#設置undoLog文件所占空間可以回收
#5.7之前的MySql的undoLog文件一直增大無法回收
innodb_undo_log_truncate = 1
innodb_undo_tablespaces = 3
innodb_undo_logs = 128
#5.7.7默認開啟該參數 控制單列索引長度最大達到3072
#innodb_large_prefix = 1
#5.7.8默認為4個, Inodb后臺清理工作的線程數
#innodb_purge_threads = 4
#通過設置配置參數innodb_thread_concurrency來限制并發線程的數量,
#一旦執行線程的數量達到這個限制,額外的線程在被放置到對隊列中之前,會睡眠數微秒,
#可以通過設定參數innodb_thread_sleep_delay來配置睡眠時間
#該值默認為0,在官方doc上,對于innodb_thread_concurrency的使用,也給出了一些建議:
#(1)如果一個工作負載中,并發用戶線程的數量小于64,建議設置innodb_thread_concurrency=0;
#(2)如果工作負載一直較為嚴重甚至偶爾達到頂峰,建議先設置innodb_thread_concurrency=128,
###并通過不斷的降低這個參數,96, 80, 64等等,直到發現能夠提供最佳性能的線程數
#innodb_thread_concurrency = 0
#強所有發生的死鎖錯誤信息記錄到error.log中,之前通過命令行只能查看最近一次死鎖信息
innodb_print_all_deadlocks = 1
############################其他內容 設置##########################################
[mysqldump]
quick
max_allowed_packet = 128M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 256k
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
#增加每個進程的可打開文件數量.
open-files-limit = 28192
感謝你能夠認真閱讀完這篇文章,希望小編分享的“mysql5.7如何安裝”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。