Last week after some previous database tuning, I stopped mysql and it failed to restart.
After a long period of troubleshooting I found that the ibdata1 file was not as big as it should have been, it had been deleted and recreated as new.
I retrieved the old 9.5gb file from backup, replaced it and mysql started again, happy days.
I've been having some more server trouble today, had a look in the mysql folder and the file has disappeared again.
I haven't stopped mysql yet so everything is still up and running, I will have to retrieve it from backup and restart with my fingers crossed.
So my question is, why is it disappearing?? My guess us I've made an accidental change in the my.cnf file and then not restarted. Unfortunately I don't have a backup of the file because I didn't know there was a change made.
(Untidy) My.cnf is as follows:
[mysqld]
local-infile=0
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
innodb_thread_concurrency= 4
innodb_buffer_pool_size = 2G
thread_concurrency = 3
thread_cache_size = 32
table_cache = 1024
query_cache_size = 64M
query_cache_limit = 2M
join_buffer_size = 8M
tmp_table_size = 256M
key_buffer = 32M
innodb_autoextend_increment=512
max_allowed_packet = 16M
max_heap_table_size = 256M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
innodb_log_file_size = 100M
innodb_additional_mem_pool_size = 20M
innodb_flush_log_at_trx_commit=2
innodb_lock_wait_timeout=1800
innodb_log_buffer_size=500K
log-error=/var/log/mysqld.log
slow_query_log = /var/log/mysql-slow.log
long_query_time = 5
pid-file=/var/run/mysqld/mysqld.pid
sort_buffer_size = 2M
read_buffer_size = 2M
wait_timeout = 120
key_buffer = 384M
tmp_table_size = 64M
max_heap_table_size = 64M
max_allowed_packet = 1M
max_connections=50
query_cache_type = 1
Any help greatly appreciated!
Thanks
Don't stop MySQL! mysqld keeps it open while it's running, so it's still on the file system.
MySQL never deletes ibdata1, so it must be some external command.
To recover the database stop all writes to the database, wait till the main thread is in "waiting for server activity" or "sleeping" state:
mysql> pager grep Main
PAGER set to 'grep Main'
mysql> show engine innodb status\G
Main thread id 4994568192, state: sleeping
1 row in set (0.00 sec)
Take dump of all databases (this step is not necessary, but for extra safety do it);
mysqldump -A > mydb.sql
Find the deleted ibdata1 in /proc filesystem and copy it back to MySQL datadir
# ls -la /proc/`pidof mysqld`/fd/ | grep -e ibdata
lrwx------ 1 root root 64 May 26 02:41 3 -> /var/lib/mysql/ibdata1 (deleted)
Note 3 - it's a file descriptor of ibdata1.
Copy ibdata1 back:
# cp /proc/`pidof mysqld`/fd/3 /var/lib/mysql/ibdata1
Then restart MySQL
#Akuzminsky's answer is what you need to do to get your current ibdata1 back. And he is correct that MySQL never deletes ibdata1, regardless of your my.cnf configuration.
So something else is deleting the file. How can one find out? Try running the Linux Audit Daemon. You won't be able to find out what deleted the file last time (unless you were already running the Audit Daemon), but in case it happens again you're ready.
See this StackExchange answer for details: https://askubuntu.com/questions/48844/how-to-find-the-pid-of-the-process-which-has-deleted-a-file
Related
I have a simple master-slave config. For an unknown reason, relay log files are created on the master as well as on the slave server. Everything works fine on the slave and the slave delete relay log files as it go however, since the master is not a slave, I do not understand why relay log files are created there too and these relay log files are never deleted neither.
So, am I missing something?
How to instruct the master to stop creating relay log files?
Mariadb version on these master/slave servers is: 10.0.38-MariaDB
Here is my master server cnf config file:
[mysqld]
expire_logs_days=21
innodb_support_xa=1
sync_binlog=1
sync_master_info=1
sync_relay_log=1
sync_relay_log_info=1
binlog_format=mixed
datadir=/data/mysql
max_heap_table_size = 256M
log_bin_trust_function_creators = 1
net_read_timeout = 3600
net_write_timeout = 3600
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 256M
max_connections = 500
table_open_cache = 201000
table_definition_cache = 201000
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 128
query_cache_size = 128M
innodb_buffer_pool_size = 16G
slave_compressed_protocol = 1
log-bin=mysql-bin
server-id = 1
Thank you for your time.
I can't find the source of the issue on our Master/Slave replication .
Today i was updating the Master and suddenly got the following error from the slave
Error 'The table 'caching_api' is full' on query.
Query: '
ALTER TABLE `caching_api`
ADD UNIQUE INDEX `id` (`id`) USING BTREE ,
ADD INDEX `search` (`component`, `method`) USING BTREE
It's not a disk issue , the Slave is an exact replicate of the Master
And my.cnf config :
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /data/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
key_buffer = 16M
max_allowed_packet = 128M
thread_stack = 192K
thread_cache_size = 64
table_open_cache = 3000
join_buffer_size = 128k
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
max_connections = 4000
wait_timeout = 150
interactive_timeout = 30
innodb_buffer_pool_size = 25G
innodb_log_file_size = 1G
innodb_buffer_pool_instances = 10
tmp_table_size = 256M
max_heap_table_size = 256M
innodb_flush_log_at_trx_commit = 2
query_cache_limit = 64M
query_cache_size = 256M
relay_log_space_limit = 10G
server-id = 2
relay-log = /var/log/mysql/mysqld-relay-bin
expire_logs_days = 1
max_binlog_size = 100M
slave-skip-errors = 1062,1054
[mysqldump]
quick
quote-names
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
Update to questions from comments :
When i try to run the query directly on the SLAVE :
caching_api table status
Slave Disk Info
ibdata1 about 36GB
ulimit -a
The manual doesn't rule out the possibility of a full disk.
If a table-full error occurs, it may be that the disk is full or that
the table has reached its maximum size. The effective maximum table
size for MySQL databases is usually determined by operating system
constraints on file sizes, not by MySQL internal limits.
But since have checked that already before posting this question. So the only other possiblility is that maximum table size has been reached.
I don't know if this problem is specific to my set up but when I add the line
log = /var/log/mysql.log
to the mysqld section of a copied my-large.cnf file and try to restart the mysql server I get the error
Starting MySQL. ERROR! The server quit without updating PID file (/var/lib/mysql/centos-server.pid).
I've created the file /var/log/mysql.log, set its owner and group to mysql and set the permissions on /var/log to 777 (for the moment)
I'm on centos, with mysql 5.6.5 m8 (the development release).
This is a snippet of the my.cnf file
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
log = /var/log/mysql.log
Seems like the log directive is outdated and my.cnf requires the directive
general-log = 1
If specified like this the log file will be created in a default location (which on centos is /var/lib/mysql/centos-server.log)
Days of searching but still no solution.
My situation
I am using this command to dump a 16+Gb (growing) database (all but 2 tables are InnoDB)
The dump is run via cron once a day and sits in a small perl script
mysqldump -uuser -pxxx --single-transaction --quick DBNAME > DBBACKUP.sql
Now the website has 2 main tables that are very heavy read/write (low load when the dump is actually happening in the morning however)
The DB has 54 tables (most under 10-20 MB)
Table 1 is 71 Million rows (9GB) InnoDB table
Table 2 is 25 million rows (3GB) InnoDB table
Now when the dump runs, the application (whist accessing Table 1 or 2) is fine, until around 3 minutes into the dump when I expect Table 1 starts to backup, the website when submitting data to be inserted into Table 1 hangs for around 9 minutes, then works again, and then Table 2 starts to be dumped and the application that uses Table 2 starts to hang.
--single-transaction should not lock tables
--quick should not buffer in memory
Lastly, the CPU and MEM %'s are very low while the dump is happening.
So has anyone seen this and know of a solution or have any suggestions at all?
SYSTEM SPECS
Processor: Dual Intel Xeon E5506 Quad Core
RAM: 12 Gb DDR3
HD1: 4 147 Gb SAS drives in a RAID 10 array
HD2: 500 Gb SATA Backup Drive
OS: Linux OS - CentOS 5 64-bit
MY.CNF
max_connections = 500
safe-show-database
skip-locking
key_buffer = 128M
max_allowed_packet = 16M
table_cache = 256
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 64M
thread_concurrency = 8
wait_timeout = 30
innodb_file_per_table
innodb_log_file_size = 10485760
open_files_limit = 8192
ft_min_word_len = 3
log-error=/var/log/mysql/mysql-error.log
log-slow-queries = /var/log/mysql/mysql-slow.log
long_query_time = 7
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M
Thank You.
OK Looks like I found the issue.
Basically, my DB has 4 myiisam table and around 20 innodb tables, the myissam table are under 2 Mb in size (total) but were causing the locks :(
So I am lucky enough to be able to dump the innodb tables (as above excluding the myissam tables) separately (and keep consistency) from the myissam tables, and no more locking :)
If anybody has other solutions feel free to post.
As mentioned here you could setup replication (master/slave) and backup the slave (with or without locking) and have no fear of changes, thus getting around the locking issue.
You can find a guide to setup replication here:
http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html
I have a table which has 38.406.168 rows and according to size in phpmyadmin 4.5GB. I want to see the last row of the table. Unfortunately I couldn't use select * from ... limit 38.406.166,1 or even I couldn't use select count(*) from ... function.
I changed my.ini in wamp server, but still I get mysql server has gone away error while attempting execute one of these queries. BTW; I couldn't even set an index on ID to make these processes much quicker.
My last try was to export the table to look at the last row. However, It just shows me 123MB of the file.
What should I do? Please help me. The features of the computer is 2.93 GHz, 3.50GB
Here is my my.ini file:
# The MySQL server
[wampmysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 2000M
table_cache = 4096
sort_buffer_size = 2000M
net_buffer_length = 8K
read_buffer_size = 2000M
read_rnd_buffer_size = 2000M
myisam_sort_buffer_size = 2000M
basedir=c:/wamp/bin/mysql/mysql5.1.36
log-error=c:/wamp/logs/mysql.log
datadir=c:/wamp/bin/mysql/mysql5.1.36/data
(.. these parts are deleted, since there is nothing to set as value)
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = C:\mysql\data/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = C:\mysql\data/
#innodb_log_arch_dir = C:\mysql\data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 384M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 10M
#innodb_log_buffer_size = 64M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 180
[mysqldump]
quick
max_allowed_packet = 160M
Thank you so much for your help
I tried a lot of stuff and ended up with those 2 working:
Simply mirror the database via mysql's internal master-slave-functions (try google, you ll find good tutorials) onto a simple backup server (most cheap hosting packages will work if they have ssh access)
Try http://www.mysqldumper.net/, the best tool to copy & split huge databases into 100mb-parts. This simple open source tool did everything that "professional" backup scripts couldn't do.
You will want to use the mysqldump command to do this. Here is what I do in linux, but I think it will translate to Windows (I see that you're running WAMP).
mysqldump --opt --force -Q --user=[your_user] -p [database_name] > dump.sql
You may need to change directory to where the mysqldump file is located:
cd c:\path\to\mysql\bin