why my MySQL binary log file size is so small? - mysql

I have a lot of small binary log files , each of them just only 126 Bytes
-rw-rw----. 1 mysql mysql 126 Jan 6 16:13 mysql-bin.000001
-rw-rw----. 1 mysql mysql 126 Jan 6 16:16 mysql-bin.000002
-rw-rw----. 1 mysql mysql 150 Jan 7 10:34 mysql-bin.000003
-rw-rw----. 1 mysql mysql 126 Jan 8 09:57 mysql-bin.000004
-rw-rw----. 1 mysql mysql 126 Jan 8 11:08 mysql-bin.000005
-rw-rw----. 1 mysql mysql 107 Jan 8 11:09 mysql-bin.000006
-rw-rw----. 1 mysql mysql 126 Jan 8 13:21 mysql-bin.000007
-rw-rw----. 1 mysql mysql 342 Jan 8 16:25 mysql-bin.index
how to let them grow bigger? and my "binlog_cache_size" is more than 126 Byte
mysql> show variables like 'binlog_cache_size';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 1
Current database: test
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| binlog_cache_size | 32768 |
+-------------------+-------+
1 row in set (0.00 sec)
can anybody tell me why(⊙ˍ⊙) ? thank you very much :)

Related

does the optimize table of mysql really rebuild(recreate) table?

I have a question about optimize table of mysql,I have read many documents about this function,all of the document says:it can defragment an InnoDB table and reorganizes the physical storage of table data and associated index data, to reduce storage space,but no one can tell me the principle of optimize table and slove my questions,I have known those informations:
As of MySQL 5.6.17,OPTIMIZE TABLE uses online DDL for regular and partitioned InnoDB tables
,As of MySQL 5.6.17,The table rebuild triggered by OPTIMIZE TABLE and performed under the cover by ALTER TABLE ... FORCE is completed in place(ALGORITHM =inplace)
my questions:
does the optimize table of mysql really rebuild(recreate) table? because it completed in place(not ALGORITHM=copy),is ALGORITHM=inplace real rebuild(recreate) table?
thank you for your response.
https://dev.mysql.com/doc/refman/5.6/en/innodb-online-ddl-operations.html
enter image description here
Demo:
I created a table on MySQL 5.6.37 and filled it with about 1GB of random data.
mysql> select version();
+-----------------+
| version() |
+-----------------+
| 5.6.37-82.2-log |
+-----------------+
mysql> show table status\G
*************************** 1. row ***************************
Name: mytable
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 61914
Avg_row_length: 20926
Data_length: 1295613952
Max_data_length: 0
Index_length: 1589248
Data_free: 4194304
Auto_increment: 131056
Create_time: 2019-02-20 15:54:23
Update_time: NULL
Check_time: NULL
Collation: utf8mb4_general_ci
Checksum: NULL
Create_options:
Comment:
I can observe the file in my datadir and note the inode number (the leftmost number).
/usr/local/var/mysql/test ls -li
total 2590752
8625784850 -rw-rw---- 1 bkarwin admin 67 Feb 20 07:54 db.opt
8625784853 -rw-rw---- 1 bkarwin admin 8580 Feb 20 07:54 mytable.frm
8625784854 -rw-rw---- 1 bkarwin admin 1321205760 Feb 20 07:56 mytable.ibd
I run optimize table.
mysql> optimize table mytable;
While it's running, I check progress by listing files in the datadir again. I see it has created a new temp file and it's filling it with a copy of the data.
Note the inode number of the temp file.
/usr/local/var/mysql/test ls -li
total 4395064
8625785082 -rw-rw---- 1 bkarwin admin 8580 Feb 20 07:57 #sql-337_16.frm
8625785083 -rw-rw---- 1 bkarwin admin 914358272 Feb 20 07:57 #sql-ib2021-3689447301.ibd
8625784850 -rw-rw---- 1 bkarwin admin 67 Feb 20 07:54 db.opt
8625784853 -rw-rw---- 1 bkarwin admin 8580 Feb 20 07:54 mytable.frm
8625784854 -rw-rw---- 1 bkarwin admin 1321205760 Feb 20 07:56 mytable.ibd
Finally my optimize table finishes. It took almost 2 minutes. If it wasn't doing a real table copy, why would it have taken so long?
+--------------+----------+----------+-------------------------------------------------------------------+
| Table | Op | Msg_type | Msg_text |
+--------------+----------+----------+-------------------------------------------------------------------+
| test.mytable | optimize | note | Table does not support optimize, doing recreate + analyze instead |
| test.mytable | optimize | status | OK |
+--------------+----------+----------+-------------------------------------------------------------------+
2 rows in set (1 min 5.52 sec)
Looking at the datadir again, I see the temp file has been renamed to be the new tablespace, and the old file has been removed. The new file has the inode number of the temp file, indicating it's the copy.
/usr/local/var/mysql/test ls -li
total 2557984
8625784850 -rw-rw---- 1 bkarwin admin 67 Feb 20 07:54 db.opt
8625785082 -rw-rw---- 1 bkarwin admin 8580 Feb 20 07:57 mytable.frm
8625785083 -rw-rw---- 1 bkarwin admin 1304428544 Feb 20 07:58 mytable.ibd

Cannot see MySQL tables after moving database dir with symbolic link

I'm running out of space on the partition where MySQL is installed so I tried moving my largest database to a new partition and symlinked this in the data directory. When I try to use this database I get the following error
mysql> use fb20;
Database changed
mysql> show tables;
ERROR 1018 (HY000): Can't read dir of './fb20/' (errno: 13)
I've checked that symlinks are enabled:
mysql> show variables like 'have_symlink';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_symlink | YES |
+---------------+-------+
All of the permissions look correct. The MySQL data directory is /data:
root> ll /data/
drwxr-x--- 243 mysql mysql 8192 Feb 21 08:02 mysql/
root> ll /data/mysql/ | grep fb20
lrwxrwxrwx 1 mysql mysql 19 Feb 21 08:02 fb20 -> /sandata/mysql/fb20/
and the new directory is /sandata:
root> ll /sandata/
drwxr-x--- 3 mysql mysql 60 Feb 20 20:32 mysql/
root> ll /sandata/mysql/
total 360
drwxr-x--- 3 mysql mysql 60 Feb 20 20:32 ./
drwxrwxr-x 35 root perma 4096 Feb 20 19:59 ../
drwx------ 2 mysql mysql 303104 Feb 15 12:20 fb20/
Not sure what I am doing wrong.
Based on the comment I added the following lines to the file /etc/apparmor.d/usr.sbin.mysqld
/sandata/mysql/ r,
/sandata/mysql/** rwk,
and then reloaded the profile (restarting apparmor did not work):
sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.mysqld

Can't start mysql and my.cnf is missing

For some reason, I can't start MySql.
$ sudo /etc/init.d/mysql start
[sudo] password for abigail:
Starting MySQL.............................................[FAILED]................................................................................
What caused this?
This is what in my /var/lib/mysql
$ ll -h /var/lib/mysql
total 1005M
-rw-rw----. 1 mysql mysql 16K Mar 28 11:08 aria_log.00000001
-rw-rw----. 1 mysql mysql 52 Mar 28 11:08 aria_log_control
-rw-rw----. 1 mysql mysql 908M Mar 31 20:10 ibdata1
-rw-rw----. 1 mysql mysql 48M Mar 31 20:09 ib_logfile0
-rw-rw----. 1 mysql mysql 48M Mar 31 20:10 ib_logfile1
-rw-rw----. 1 mysql mysql 5 Mar 28 11:09 localhost.pid
-rw-rw----. 1 mysql mysql 0 Oct 29 23:04 multi-master.info
drwx--x--x. 2 mysql mysql 4.0K Oct 29 23:01 mysql
drwx------. 2 mysql mysql 19 Oct 29 23:01 performance_schema
-rw-rw----. 1 mysql mysql 24K Mar 28 11:09 tc.log
drwx------. 2 mysql mysql 4.0K Nov 3 22:10 test
I think I might have to reinstall mysql.
my.cnf is supposed to be in /etc/my.cnf.
Check the start log for the error message, like in /var/log/mysqld.log.

Rogue Database Appears in MySQL Show Databases

I see today that
show databases
displays an unknown database:
(msl_ampcs_v4_0_0_2g)> show databases;
+----------------------+
| Database |
+----------------------+
| information_schema |
| #mysql50#.ssh |
| global_lad
Normally when I see something like that it is due to a bad file in /var/lib/mysql:
-rw-r--r-- 1 mysql mysql 1663 Mar 17 2011 /var/lib/mysql/ca-cert.pem
drwx------ 2 mysql mysql 4096 Jun 18 15:00 /var/lib/mysql/global_lad
drwx------ 2 mysql mysql 4096 Jun 18 15:00 /var/lib/mysql/global_lad_unit_test
-rw-rw---- 1 mysql mysql 3231711232 Aug 22 07:20 /var/lib/mysql/ibdata1
-rw-rw---- 1 mysql mysql 5242880 Aug 22 07:20 /var/lib/mysql/ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Aug 21 16:25 /var/lib/mysql/ib_logfile1
-rw-rw---- 1 mysql mysql 5 Feb 21 2013 /var/lib/mysql/istsdb2.jpl.nasa.gov.pid
-rw-rw---- 1 mysql mysql 4596466 Oct 15 2010 /var/lib/mysql/istsdb2-slow.log
drwx------ 2 mysql mysql 4096 Jul 13 2011 /var/lib/mysql/msl_ampcs_v2_0_0
drwx------ 2 mysql mysql 4096 Jul 21 2012 /var/lib/mysql/msl_ampcs_v3_0_0
drwx------ 2 mysql mysql 4096 Jun 20 02:55 /var/lib/mysql/msl_ampcs_v4_0_0
drwx------ 2 mysql mysql 4096 Sep 5 19:45 /var/lib/mysql/msl_ampcs_v4_0_0_2g
drwx------ 2 mysql mysql 4096 Sep 30 2010 /var/lib/mysql/msl_gdsdb_v5_0
drwx------ 2 mysql mysql 4096 Jan 19 2011 /var/lib/mysql/msl_gdsdb_v5_5
drwx------ 2 mysql mysql 4096 Nov 21 2011 /var/lib/mysql/msl_gdsdb_v5_6
drwx------ 2 mysql root 4096 Mar 23 2010 /var/lib/mysql/mysql
srwxrwxrwx 1 mysql mysql 0 Feb 21 2013 /var/lib/mysql/mysql.sock
-rw------- 1 root root 841 Jun 10 2010 /var/lib/mysql/nohup.out
drwx------ 2 mysql mysql 4096 Feb 5 2013 /var/lib/mysql/pdpp_automation
-rw-r--r-- 1 mysql mysql 1310 Mar 17 2011 /var/lib/mysql/server-cert.pem
-rw-r--r-- 1 mysql mysql 1679 Mar 17 2011 /var/lib/mysql/server-key.pem
But nothing like that is present. The nohup shouldn't be there. But
#mysql50#.ssh
does not appear.

MYSQL data files are compressed to gz

I have drupal website, the database is about 10GB. I was checking the datadir of my drupal database and found that some files are .gz!! why is this? and does it affect performance??
the website is working fine and i can use those tables normally although there is no corresponding file for.gz (ie. I have content_type_company.MYD.gz in the data directory but there is no content_type_company.MYD)
the list is something like this:
ls -lhS *.gz
-rw-rw---- 1 mysql mysql 3.4M 2011-04-18 06:52 content_field_headline_image.MYI.gz
-rw-rw---- 1 mysql mysql 379K 2011-04-14 15:50 print_node_conf.MYD.gz
-rw-rw---- 1 mysql mysql 105K 2011-04-18 06:56 content_type_company.MYD.gz
-rw-rw---- 1 mysql mysql 22K 2011-04-14 15:50 nodewords.MYD.gz
-rw-rw---- 1 mysql mysql 18K 2011-04-18 06:59 content_field_company_fax.MYD.gz
-rw-rw---- 1 mysql mysql 18K 2011-04-18 06:59 content_field_company_email.MYI.gz
-rw-rw---- 1 mysql mysql 4.7K 2011-04-17 21:55 content_type_editor_choice.MYI.gz
-rw-rw---- 1 mysql mysql 4.2K 2011-02-01 09:15 content_node_field_instance.MYD.gz
-rw-rw---- 1 mysql mysql 2.7K 2011-01-31 14:03 content_node_field.MYD.gz
-rw-rw---- 1 mysql mysql 1.9K 2011-04-18 01:31 content_type_press_review.MYI.gz
-rw-rw---- 1 mysql mysql 1.4K 2011-04-18 06:59 users.MYI.gz
-rw-rw---- 1 mysql mysql 1.1K 2011-02-02 12:25 batch.MYD.gz
-rw-rw---- 1 mysql mysql 1.1K 2011-01-19 12:35 node_access.MYI.gz
-rw-rw---- 1 mysql mysql 801 2010-09-06 09:49 menu_custom.MYD.gz
-rw-rw---- 1 mysql mysql 679 2011-04-17 12:12 scheduler.MYI.gz
-rw-rw---- 1 mysql mysql 671 2011-01-12 11:24 users.frm.gz
-rw-rw---- 1 mysql mysql 659 2011-04-14 22:53 video_rendering.MYI.gz
-rw-rw---- 1 mysql mysql 570 2011-04-17 14:39 content_type_slideshow.MYD.gz
-rw-rw---- 1 mysql mysql 533 2011-02-02 09:46 permission.MYI.gz
-rw-rw---- 1 mysql mysql 471 2011-01-30 12:53 panels_display.MYD.gz
-rw-rw---- 1 mysql mysql 412 2010-09-07 14:41 content_field_slideshow_image.frm.gz
-rw-rw---- 1 mysql mysql 372 2011-01-12 11:24 date_formats.MYD.gz
-rw-rw---- 1 mysql mysql 355 2010-07-26 15:51 contact.frm.gz
-rw-rw---- 1 mysql mysql 351 2010-07-26 16:15 sessions.frm.gz
-rw-rw---- 1 mysql mysql 349 2011-03-28 18:02 cache_update.frm.gz
-rw-rw---- 1 mysql mysql 345 2011-03-28 18:03 ctools_object_cache.frm.gz
-rw-rw---- 1 mysql mysql 326 2010-07-26 15:54 print_mail_page_counter.frm.gz
-rw-rw---- 1 mysql mysql 317 2010-07-26 15:54 search_index.frm.gz
-rw-rw---- 1 mysql mysql 310 2010-07-26 15:51 i18n_strings.frm.gz
-rw-rw---- 1 mysql mysql 292 2010-07-26 15:49 authmap.frm.gz
-rw-rw---- 1 mysql mysql 291 2011-01-12 11:24 scheduler.frm.gz
-rw-rw---- 1 mysql mysql 286 2010-07-26 15:54 permission.frm.gz
-rw-rw---- 1 mysql mysql 275 2010-07-26 15:49 block_class.frm.gz
-rw-rw---- 1 mysql mysql 272 2010-07-26 15:51 captcha_points.frm.gz
-rw-rw---- 1 mysql mysql 269 2010-07-26 15:54 page_manager_weights.frm.gz
-rw-rw---- 1 mysql mysql 251 2011-03-28 18:03 imagecache_preset.frm.gz
-rw-rw---- 1 mysql mysql 249 2010-11-24 13:19 content_type_press_review.frm.gz
-rw-rw---- 1 mysql mysql 248 2011-01-26 09:21 aggregator_category_feed.frm.gz
-rw-rw---- 1 mysql mysql 243 2010-07-26 15:54 role.frm.gz
-rw-rw---- 1 mysql mysql 240 2010-07-26 16:15 variable.frm.gz
-rw-rw---- 1 mysql mysql 202 2010-08-09 13:20 stylizer.MYI.gz
-rw-rw---- 1 mysql mysql 192 2011-04-05 07:50 vocabulary_node_types.MYD.gz
-rw-rw---- 1 mysql mysql 152 2010-07-26 16:15 taxonomy_manager_merge.MYI.gz
-rw-rw---- 1 mysql mysql 78 2011-04-14 03:06 video_rendering.MYD.gz
-rw-rw---- 1 mysql mysql 58 2011-02-01 17:40 content_type_video_gallery.MYD.gz
The files are compressed to save space, of course, and gzip works like that - when a file called 'x' is gzipped, it's replaced by 'x.gz' the original file ''becomes'' the compressed file.
If the database works as expected, I wouldn't worry about it.
The size of gzipped files is much smaller than Your database size. Nothing to worry.