![](/img/trans.png)
[英]Reducing memory consumption of mysql on ubuntu@aws micro instance
[英]moving mysql from ubuntu machine was successful, but the memory consumption is from old directory
我在ubuntu機器上安裝了apache,mysql,phpmyadmin。 我有一個很大的數據庫要存儲在mysql中,因此將mysql從根目錄移到/ mnt0目錄。 但是看起來根本沒有消耗mnt0的內存,而是消耗了根目錄的內存。 這意味着可能無法成功移動mysql。 下面是我的機器的內存使用情況(當我啟動根目錄時,它具有6.3G的可用內存。使用數據庫一段時間后,根目錄中的可用內存為5.1G&mnt0看起來相同,我的意思是沒有內存使用率)
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 2.4G 5.1G 32% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 3.7G 8.0K 3.7G 1% /dev
tmpfs 752M 212K 752M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 3.7G 0 3.7G 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/xvdb 414G 485M 392G 1% /mnt0
這是我將mysql移至buntu @ ip-xx-xxx-xxx-xxx:/ mnt0 $ ls -l drwx ------ 2根root 16384 Feb 6 00:17 lost + found drwx ----- -8個mysql mysql 4096 2月21日19:37 mysql
我已經將此文件/etc/apparmor.d/usr.sbin.mysql更改為新的datadir。 / mnt0 $ cat /etc/apparmor.d/usr.sbin.mysqld
# vim:syntax=apparmor
# Last Modified: Tue Jun 19 17:37:30 2007
#include <tunables/global>
/usr/sbin/mysqld {
#include <abstractions/base>
#include <abstractions/nameservice>
#include <abstractions/user-tmp>
#include <abstractions/mysql>
#include <abstractions/winbind>
capability dac_override,
capability sys_resource,
capability setgid,
capability setuid,
network tcp,
/etc/hosts.allow r,
/etc/hosts.deny r,
/etc/mysql/*.pem r,
/etc/mysql/conf.d/ r,
/etc/mysql/conf.d/* r,
/etc/mysql/*.cnf r,
/usr/lib/mysql/plugin/ r,
/usr/lib/mysql/plugin/*.so* mr,
/usr/sbin/mysqld mr,
/usr/share/mysql/** r,
/var/log/mysql.log rw,
/var/log/mysql.err rw,
/mnt0/mysql/ r,
/mnt0/mysql/** rwk,
/var/log/mysql/ r,
/var/log/mysql/* rw,
/var/run/mysqld/mysqld.pid rw,
/var/run/mysqld/mysqld.sock w,
/run/mysqld/mysqld.pid rw,
/run/mysqld/mysqld.sock w,
/sys/devices/system/cpu/ r,
# Site-specific additions and overrides. See local/README for details.
#include <local/usr.sbin.mysqld>
}
編輯:添加了/ mnt0和ls -lha / mnt0 / mysql的du -kh
root@ip-xx-xxx-xxx-xxx:/mnt0# du -kh
204K ./mysql-crapy/mysql/phpmyadmin
4.0K ./mysql-crapy/mysql/test
212K ./mysql-crapy/mysql/performance_schema
1.1M ./mysql-crapy/mysql/mysql
30M ./mysql-crapy/mysql
30M ./mysql-crapy
16K ./lost+found
40K ./api.Kavitha.com
32K ./mysql/DB
224K ./mysql/phpmyadmin
4.0K ./mysql/test
212K ./mysql/performance_schema
1.1M ./mysql/mysql
20K ./mysql/KavithaDataBase
110M ./mysql
96K ./CoreUtils/cli/fb
952K ./CoreUtils/cli
44K ./CoreUtils/addrstd
43M ./CoreUtils/db
12K ./CoreUtils/etc-conf
16K ./CoreUtils/feeds
16K ./CoreUtils/api/
68K ./CoreUtils/api
104M ./CoreUtils/dict
16K ./CoreUtils/core/sendgrid/sendgrid-php/Test/Mock
28K ./CoreUtils/core/sendgrid/sendgrid-php/Test/SendGrid
56K ./CoreUtils/core/sendgrid/sendgrid-php/Test
20K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/CharacterReader
8.0K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/CharacterReaderFactory
20K ./CoreUtils/core/sendgrid/sendgrid-php/lib/
36K ./CoreUtils/core/sendgrid/sendgrid-php/lib/
12K ./CoreUtils/core/sendgrid/sendgrid-php/lib/
12K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Plugins/Reporters
8.0K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Plugins/Decorator
12K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Plugins/Loggers
12K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Plugins/Pop
112K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Plugins
20K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/StreamFilters
20K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/CharacterStream
16K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Transport/Esmtp/Auth
32K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Transport/Esmtp
124K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Transport
52K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Mime/Headers
12K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Mime/HeaderEncoder
16K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Mime/ContentEncoder
212K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Mime
68K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Events
24K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift/Encoder
844K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes/Swift
852K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/classes
20K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift/dependency_maps
896K ./CoreUtils/core/sendgrid/sendgrid-php/lib/swift
900K ./CoreUtils/core/sendgrid/sendgrid-php/lib
40K ./CoreUtils/core/sendgrid/sendgrid-php/SendGrid
1008K ./CoreUtils/core/sendgrid/sendgrid-php
1016K ./CoreUtils/core/sendgrid
1.6M ./CoreUtils/core
20K ./CoreUtils/
149M ./CoreUtils
316M .
/mnt0# ls -lha /mnt0/mysql
total 109M
drwx------ 8 mysql mysql 4.0K Feb 21 20:31 .
drwxrwxrwx 7 root root 4.0K Feb 21 20:19 ..
drwx------ 2 mysql mysql 4.0K Feb 12 00:22 Db
-rw-r--r-- 1 root root 0 Feb 11 19:38 debian-5.5.flag
-rw-rw---- 1 mysql mysql 98M Feb 24 18:12 ibdata1
-rw-rw---- 1 mysql mysql 5.0M Feb 24 18:12 ib_logfile0
-rw-rw---- 1 mysql mysql 5.0M Feb 24 18:12 ib_logfile1
drwx------ 2 mysql root 4.0K Feb 11 19:39 mysql
-rw-rw---- 1 root root 6 Feb 11 19:39 mysql_upgrade_info
drwx------ 2 mysql mysql 4.0K Feb 11 19:39 performance_schema
drwx------ 2 mysql mysql 4.0K Feb 11 19:45 phpmyadmin
drwx------ 2 mysql root 4.0K Feb 11 19:38 test
drwx------ 2 mysql mysql 4.0K Feb 12 20:39 KavithaDataBase
您是否期望數據庫龐大? 這看起來是正確和正常的,如果數據庫不是那么大,那么其他分區上的1.2GB幻像已用空間可以通過一些非MySQL進程來解釋。
我發現的這段有用的代碼應該顯示您大約的數據庫大小:
SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;
我建議從phpMyAdmin的SQL選項卡運行該命令,然后查看結果。 如果將它們全部加在一起,則大約應為110MB。 這樣一來,您就可以大致判斷出該數據實際上是否在MySQL中。
您可能是安裝不足的受害者。 這是一件很容易測試的事情:
# make a temp directory to mount
mkdir /tmp/testmount
# bind-mount the root partition to a new location
mount --bind / /tmp/testmount
# change into that directory.
# Note: as this is a bind-mount, /mnt0 will NOT be mounted. It SHOULD be empty.
cd /tmp/testmount/mnt0
# see if there are any files where /mnt0 is
du -ah
如果您在/ tmp / testmount / mnt0下獲得任何文件,則mysql會以某種方式在實際安裝/ mnt0 之前開始訪問文件。 文件是在正確的位置創建的,只是不在正確的文件系統上創建。 如果是這種情況,請延遲mysql啟動,直到安裝/ mnt0之后。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.