介绍

宝塔面板安装 MySQL 5.6 时提示最低内存要求 768MB;安装 MySQL 5.7 时提示最低内存要求 1560MB。对于512MB的VPS非常不友好,版本过低的MySQL容易导致程序不稳定。甚至有些程序要求MySQL>=5.6。

安装前准备(特别重要)小内存机器务必添加虚拟内存(swap)

使用宝塔面板Linux工具箱直接添加(推荐)

3.png
安装完后最好检查一下是否添加成功!使用一下命令查询

#查询内存使用情况(使用MBytes输出)
free -m

4.png
顺便再提醒一下:/www(或文件安装目录)所在的磁盘建议剩余空间不小于 5G。如果不够,把不需要的文件删一下,或者扩容磁盘,这里不赘述。

#查询磁盘空间及挂载
df -h

安装方法 (二选一即可)

①直接修改宝塔面板限制内容(简单粗暴)

找到宝塔面板文件:/www/server/panel/data/plugin.json ,打开后按下[ctrl+F]搜索 768(如果要安装 MySQL 5.6)或 1560(如果要安装 MySQL 5.7) ,找到如下内容,将768或1560修改为需要的数值(一般是降低到VPS内存限值)。最后记得保存!!
1.png
直接从宝塔面板软件商店安装即可
2.png

②手动安装

由于安装时间可能过长或因为系统运行速度问题导致断开,建议使用screen,按照下面操作即可

##安装screen
#debian系统
apt install screen 
#centos系统
yum install screen 
##创建screen 
screen -S mysql
##进入screen窗口开始编译安装mysql
cd /www/server/panel/install
bash mysql.sh install 5.6  
<==会自动开始编译安装
<==切换为英文输入法后按下[ctrl+a]随后按下d,screen被挂载到后台,此时可以退出ssh

静静的等待安装即可,可以第二天回来看看是否已经安装完毕

#打开screen终端查看安装进程
screen -r mysql

安装完毕done,enjoy!!

一些可以优化的操作(可选)

mysql 5.6、5.7默认启动占用内存几百多M,如果是vps等小内存应用,mysql内存占用率明显偏高,将会导致崩溃,或被系统kill,mysql会自动停止。

##可以通过调整一下参数降低内存占用
performance_schema_max_table_instances = 200
table_definition_cache = 100
table_open_cache = 100
innodb_buffer_pool_size=2M

5.png
6.png

##附上我使用的Bt面板配置参数
[client]
#password    = your_password
port = 3306
socket        = /tmp/mysql.sock

[mysqld]
port = 3306
socket        = /tmp/mysql.sock
datadir = /www/server/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 50
table_definition_cache = 50
skip-external-locking
key_buffer_size = 8M
max_allowed_packet = 1M
table_open_cache = 32
sort_buffer_size = 64K
net_buffer_length = 2K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 4M
thread_cache_size = 4
query_cache_size = 4M
tmp_table_size = 8M
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

explicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 50
max_connect_errors = 100
open_files_limit = 65535

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
expire_logs_days = 10
slow_query_log=1
slow-query-log-file=/www/server/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on


innodb_data_home_dir = /www/server/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /www/server/data
innodb_buffer_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 1
innodb_write_io_threads = 1

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
最后修改:2024 年 03 月 31 日
如果觉得我的文章对你有用,请随意赞赏