增加线程缓存大小
MySQL提供了许多与连接线程相关的服务器变量:
线程缓存大小由thread_cache_size系统变量决定.默认值为0(无缓存),这将导致为每个新连接设置一个线程,并在连接终止时需要处理该线程.如果希望服务器每秒接收数百个连接请求,那么应该将thread_cache_size设置的足够高,以便大多数新连接可以使用缓存线程.可以在服务器启动或运行时设置max_connections的值.
还应该监视缓存中的线程数(Threads_cached)以及创建了多少个线程,因为无法从缓存中获取线程(Threads_created).关于后者,如果Threads_created继续以每分钟多于几个线程的增加,请考虑增加thread_cache_size的值.
使用MySQL show status命令显示MySQL的变量和状态信息.这里有几个例子:
Monyog线程缓存监测
Monyog提供了一个监控线程缓存的屏幕,名为"线程".与MySQL线程相关的服务器变量映射到以下Monyog指标:
Monyog线程屏幕还包括"线程缓存命中率"指标.这是一个提示线程缓存命中率的指标.如果值较低,则应该考虑增加线程缓存.在状态栏以百分比形式显示该值;它的值越接近100%越好.
如果这些指标的值等于或超过指定值,则可以将每一个指标配置为发出警告和/或严重警报
如果数据库是安装在你机器上的 那么你可以暂时把MYSQL关闭 然后进入安装目录 找到data文件夹 这里面就是放置数据库文件的..你会看到data里面每一个文件夹都对应你一个数据库名称 把他们删除就好了 就彻底没了 不过可别把mysql这个文件夹删了 还有别的文件 比如.err别乱删哦.
mysql耗内存吗?很多人都说MySQL占用了很大的虚拟内存,那么这个问题应该怎么解决呢?下面是我收集整理的一些方法,现在分享给大家!
解决mysql耗内存的具体方法一:
优化方法:
① 退出EMS clientserver
my.ini
# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
#
# Installation Instructions
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (@localstatedir@ for this installation) or to
# ~/.my.cnf to set user-specific options.
# On Windows you should keep this file in the installation directory
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option
# "--defaults-file".
# To run run the server from the command line, execute this in a
# command line shell, e.g.
# mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
# To install the server as a Windows service manually, execute this in a
# mysqld --install MySQLXY --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
# And then execute this in a command line shell to start the server, e.g.
# net start MySQLXY
# Guildlines for editing this file
# In this file, you can use all long options that the program supports.
# If you want to know the options a program supports, start the program
# with the "--help" option.
# found in the manual.
# CLIENT SECTION
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
[client]
[mysql]
# SERVER SECTION
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
#Path to installation directory. All paths are usually resolved relative to this.
#Path to the database root
# The default character set that will be used when a new schema or table is
# created and no character set is defined
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
# Query cache is used to cache SELECT results and later return them
# without actual executing the same query once again. Having the query
# cache enabled may result in significant speed improvements, if your
# have a lot of identical queries and rarely changing tables. See the
# "Qcache_lowmem_prunes" status variable to check if the current value
# is high enough for your load.
# Note: In case your tables change very often or if your queries are
# textually different every time, the query cache may result in a
# slowdown instead of a performance improvement.
# The number of open tables for all threads. Increasing this value
# increases the number of file descriptors that mysqld requires.
# Therefore you have to make sure to set the amount of open files
# section [mysqld_safe]
# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client's threads are put in the cache if there aren't
# more than thread_cache_size threads from before. This greatly reduces
# the amount of thread creations needed if you have a lot of new
# connections. (Normally this doesn't give a notable performance
# improvement if you have a good thread implementation.)
#*** MyISAM Specific options
# The maximum size of the temporary file MySQL is allowed to use while
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
# If the file-size would be bigger than this, the index will be created
# through the key cache (which is slower).
myisam_max_sort_file_size=100G
# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method. This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
# Size of the Key Buffer, used to cache index blocks for MyISAM tables.
# is also required by the OS to cache rows. Even if you're not using
# used for internal temporary disk tables.
# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
# This buffer is allocated when MySQL needs to rebuild the index in
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE
# into an empty table. It is allocated per thread so be careful with
# large settings.
#*** INNODB Specific options ***
# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb
# Additional memory pool that is used by InnoDB to store metadata
# information. If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS. As this is fast enough on most
# recent operating systems, you normally do not need to change this
# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# logs. Value 0 means that the log is only written to the log file and
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1
# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# too large, though, because competition of the physical memory may
# set it too high.
# Size of each log file in a log group. You should set the combined size
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
解决mysql耗内存的具体方法二:
更改后如下:
另外mysql安装目录下有几个文件:my-huge.ini 、my-large.ini、my-medium.ini...这几个是根据内存大小作的建议配置,新手在设置的时候也可以参考一下.
innodb_flush_log_at_trx_commit=0 等到innodb_log_buffer_size列队满后再统一储存,默认为1
试验一:
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=1M
试验二:
一般:
经过测试.没有特殊情况,最好还是用默认的.
(设置为0就是等到innodb_log_buffer_size列队满后再统一储存,默认为1)
优化mysql数据库性能的十个参数
(1)、max_connections:
要求 mysql 能有的连接数量.当主要mysql线程在一个很短时间内得到非常多的连接请求,这就起作用,然后主线程花些时间(尽管很短)检查连接并且启动一个新线程.
back_log 值指出在mysql暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中.只有如果期望在一个短时间内有很多连接,你需要增加它,换句话说,这值对到来的tcp/ip连接的侦听队列的大小.你的操作系统在这个队列大小上有它自己的限制.试图设定back_log高于你的操作系统的限制将是无效的.
用mysql进行搜索,目的是能不分大小写,又能用中文进行搜索
(10)、wait_timeout:
注:参数的调整可以通过修改 /etc/my.cnf 文件并重启 mysql 实现.这是一个比较谨慎的工作,上面的结果也仅仅是我的一些看法,你可以根据你自己主机的硬件情况(特别是内存大小)进一步修改.
我们都知道 MySQL 的 Table Cache 是表定义的缓存,江湖上流传着各种对这个参数的调优方法.
table cache 的作用,就是节约读取表结构文件的开销.对于table cache 是否命中,其实table cache 是针对于线程的,每个线程有自己的缓存,只缓存本线程的表结构定义.不过我们发现,strace 中没有关于表结构文件的 open 操作(只有 stat 操作,定位表结构文件是否存在),也就是说 table cache 不命中,不一定需要读取表结构文件.这种感觉好像是:在不命中 table cache 时,命中了另外一个表结构缓存.
运维建议:
我们读一下 MySQL 的文档,关于 table_open_cache 的建议值公式:建议值 = 最大并发数 * join 语句涉及的表的最大个数.
通过实验我们容易理解:table_cache 是针对于线程的,所以需要最大并发数个缓存.另外,一个语句 join 涉及的表,需要同时在缓存中存在.所以最小的缓存大小,等于语句 join 涉及的表的最大个数.将这两个数相乘,就得到了 MySQL 的建议值公式.
应用redis实现数据的读写,同时利用队列处理器定时将数据写入mysql.
同时要注意避免冲突,在redis启动时去mysql读取所有表键值存入redis中,往redis写数据时,对redis主键自增并进行读取,若mysql更新失败,则需要及时清除缓存及同步redis主键.
这样处理,主要是实时读写redis,而mysql数据则通过队列异步处理,缓解mysql压力,不过这种方法应用场景主要基于高并发,而且redis的高可用集群架构相对更复杂,一般不是很推荐.
以上就是土嘎嘎小编为大家整理的mysql怎么管理缓存相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!