I just enabled mysql slow query logging.
Now I see these queries being logged on different tables time to time:
SELECT /*!40001 SQL_NO_CACHE */ * FROM `paitents`;
# Time: 181128 6:38:50
# User#Host: my_testdatabase[my_testdatabase] # localhost []
# Query_time: 2.964142 Lock_time: 0.000081 Rows_sent: 3 Rows_examined: 1606915
I just searched and found out that it might be the database dump causing these queries.
But I want to make sure that its the mysql dump not some unauthorized access.
This is the latest log from that specific table in my logs right now:
SELECT /*!40001 SQL_NO_CACHE */ * FROM `paitents`;
# Time: 181128 6:38:50
# User#Host: my_testdatabase[my_testdatabase] # localhost []
# Query_time: 2.964142 Lock_time: 0.000081 Rows_sent: 3 Rows_examined: 1606915
And here is the logs of dumps that were created:
-rw-r--r-- 1 root root 381511206 Nov 23 23:21 my_testdatabase_2018-11-23.sql.tar.bz2
-rw-r--r-- 1 root root 381754145 Nov 24 23:21 my_testdatabase_2018-11-24.sql.tar.bz2
-rw-r--r-- 1 root root 381999764 Nov 25 23:21 my_testdatabase_2018-11-25.sql.tar.bz2
-rw-r--r-- 1 root root 382146325 Nov 26 23:22 my_testdatabase_2018-11-26.sql.tar.bz2
-rw-r--r-- 1 root root 382357755 Nov 27 23:23 my_testdatabase_2018-11-27.sql.tar.bz2
-rw-r--r-- 1 root root 382384209 Nov 28 06:29 my_testdatabase_2018-11-28.sql.tar.bz2
Now here I can see the difference in the latest query logged in slow query log and the latest dump created.
Latest query logged time: 181128 6:38:50
Latest dump created time: 2018-11-28 06:29
Why is there a difference?
Related
i find lot's of ibd file in my mysql server datadir ,what is it ? mysql version is 5.7.12 , strange things is they are all no frm file
-rw-r----- 1 mysql mysql 84M Aug 20 13:56 FTS_0000000000002fe2_000000000000694c_INDEX_1.ibd
-rw-r----- 1 mysql mysql 12M Aug 20 13:55 FTS_0000000000002fe2_000000000000694c_INDEX_2.ibd
-rw-r----- 1 mysql mysql 7.0M Aug 20 13:52 FTS_0000000000002fe2_000000000000694c_INDEX_3.ibd
-rw-r----- 1 mysql mysql 496K Aug 20 13:52 FTS_0000000000002fe2_000000000000694c_INDEX_4.ibd
-rw-r----- 1 mysql mysql 448K Aug 20 13:53 FTS_0000000000002fe2_000000000000694c_INDEX_5.ibd
-rw-r----- 1 mysql mysql 7.0M Aug 20 13:55 FTS_0000000000002fe2_000000000000694c_INDEX_6.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:46 FTS_0000000000002fe2_BEING_DELETED_CACHE.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:46 FTS_0000000000002fe2_BEING_DELETED.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:56 FTS_0000000000002fe2_CONFIG.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:46 FTS_0000000000002fe2_DELETED_CACHE.ibd
-rw-r----- 1 mysql mysql 96K Aug 20 13:46 FTS_0000000000002fe2_DELETED.ibd
-rw-r----- 1 mysql mysql 396M Aug 21 20:59 FTS_000000000000304c_00000000000069eb_INDEX_1.ibd
-rw-r----- 1 mysql mysql 40M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_2.ibd
-rw-r----- 1 mysql mysql 11M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_3.ibd
-rw-r----- 1 mysql mysql 10M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_4.ibd
-rw-r----- 1 mysql mysql 9.0M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_5.ibd
-rw-r----- 1 mysql mysql 10M Aug 21 20:58 FTS_000000000000304c_00000000000069eb_INDEX_6.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_1.ibd
-rw-r----- 1 mysql mysql 848M Aug 21 20:59 FTS_000000000000304c_00000000000069f2_INDEX_2.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_3.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_4.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_5.ibd
-rw-r----- 1 mysql mysql 96K Aug 21 20:32 FTS_000000000000304c_00000000000069f2_INDEX_6.ibd
and i check two of these file ,find some content , i can not know.
# strings FTS_0000000000003c97_BEING_DELETED_CACHE.ibd
infimum
supremum
# strings FTS_0000000000003c97_CONFIG.ibd
infimum
supremum
|cache_size_in_mb
1optimize_checkpoint_limit
Jsynced_doc_id
deleted_doc_count
!table_state
,use_stopword
The FTS_*.ibd files are the InnoDB FULLTEXT Search (FTS) index files. InnoDB introduced Full Text Searching from MySQL version 5.6 and onwards. They store only FTS indexing data. You possibly have some InnoDB table(s) with FTS defined on few field(s).
Indexing data is split up into 6 partitions. The ...INDEX_1.ibd to ...INDEX_6.ibd table files contain the FTS index data (6 parts).
FTS_DELETED and FTS__DELETED_CACHE
Contain the document IDs (DOC_ID) for documents that are deleted but
whose data is not yet removed from the full-text index. The
FTS_DELETED_CACHE is the in-memory version of the FTS_DELETED
table.
FTS__BEING_DELETED and FTS__BEING_DELETED_CACHE
Contain the document IDs (DOC_ID) for documents that are deleted and
whose data is currently in the process of being removed from the
full-text index. The FTS_BEING_DELETED_CACHE table is the in-memory
version of the FTS_BEING_DELETED table.
FTS_CONFIG
Stores information about the internal state of the FULLTEXT index.
From MySQL 5.6.6 and higher, InnoDB engine enabled innodb_file_per_table approach. From Docs:
Historically, InnoDB tables were stored in the system tablespace....
[Now] each InnoDB table is stored in its own tablespace data file (.ibd
file). This feature is controlled by the innodb_file_per_table
configuration option, which is enabled by default.
More from the docs:
With innodb_file_per_table enabled, you can store InnoDB tables in a
tbl_name.ibd file. Unlike the MyISAM storage engine, with its separate
tbl_name.MYD and tbl_name.MYI files for indexes and data, InnoDB
stores the data and the indexes together in a single .ibd file. The
tbl_name.frm file is still created as usual.
I am new to mariadb. Today, I was attempting to import a mysql database to mariadb and during the process the import stops when a warning is encountered as shown below.
Now, I said to myself that I should check a log file so I can see the error but I can't seem to fine any log file. I ran the query below with help from Get the error log of Mariadb:
As you can see there is no path to an error log file.
Next I checked /var/lib/mysql and below is the dir content:
-rw-rw----. 1 mysql mysql 16384 Jun 5 16:03 aria_log.00000001
-rw-rw----. 1 mysql mysql 52 Jun 5 16:03 aria_log_control
-rw-rw----. 1 mysql mysql 79691776 Jun 8 08:02 ibdata1
-rw-rw----. 1 mysql mysql 50331648 Jun 8 08:02 ib_logfile0
-rw-rw----. 1 mysql mysql 50331648 Jun 5 16:03 ib_logfile1
-rw-rw----. 1 mysql mysql 6 Jun 5 16:12 IMSPRO.pid
drwx------. 2 mysql mysql 4096 Jun 8 08:02 ecommence
-rw-rw----. 1 mysql mysql 0 Jun 5 16:12 multi-master.info
drwx--x--x. 2 mysql mysql 4096 Jun 5 16:03 mysql
srwxrwxrwx. 1 mysql mysql 0 Jun 5 16:12 mysql.sock
drwx------. 2 mysql mysql 20 Jun 5 16:03 performance_schema
-rw-rw----. 1 mysql mysql 24576 Jun 5 16:12 tc.log
No file in the above dir logs error.
Below is the content of my /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
Below is the content of /etc/my.cnf.d
drwxr-xr-x. 2 root root 117 Jun 5 16:02 .
drwxr-xr-x. 91 root root 8192 Jun 7 01:14 ..
-rw-r--r--. 1 root root 295 May 29 16:48 client.cnf
-rw-r--r--. 1 root root 763 May 29 16:48 enable_encryption.preset
-rw-r--r--. 1 root root 232 May 29 16:48 mysql-clients.cnf
-rw-r--r--. 1 root root 1080 May 29 16:48 server.cnf
-rw-r--r--. 1 root root 285 May 29 16:48 tokudb.cnf
What can I do to get error log?
The way to see the warnings is to type this immediately after receiving that "Warnings: 1":
SHOW WARNINGS;
(As soon as the next other command is run, the warnings are cleared.)
In mariadb version 10.3.29,
#show variables like 'log-error';
is showing "Empty set" output
Instead, the following command is working
show global variables like 'log_error';
In my case, I edited /etc/my.cnf and added the line log_error after [mysqld]:
[mysqld]
...
log_error
After that, the query show variables like 'log_error'; displays the following (before the change, the Value column was empty):
+---------------+--------------------------+
| Variable_name | Value |
+---------------+--------------------------+
| log_error | /var/lib/mysql/host.err |
+---------------+--------------------------+
Now the error log is being written to the above file.
The exact name of the file will vary from server to server and will take the name of the current host, so expect it to be different in your particular case.
I have Mysql DB on AWS RDS instance, and I have a slow query log with log_queries_not_using_indexes = YES
And it is working but almost every 5 seconds, this is what I am seeing in log:
SELECT value FROM mysql.rds_heartbeat2;
# Time: 150804 21:00:25
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000154 Lock_time: 0.000058 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722025;
SELECT NAME, VALUE FROM mysql.rds_configuration;
# Time: 150804 21:00:30
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000233 Lock_time: 0.000113 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722030;
SELECT count(*) from information_schema.TABLES WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'rds_heartbeat2';
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000116 Lock_time: 0.000039 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722030;
SELECT value FROM mysql.rds_heartbeat2;
# Time: 150804 21:00:45
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000238 Lock_time: 0.000116 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722045;
SELECT count(*) from information_schema.TABLES WHERE TABLE_SCHEMA = 'mysql' AND TABLE_NAME = 'rds_heartbeat2';
# User#Host: rdsadmin[rdsadmin] # localhost [127.0.0.1] Id: 1
# Query_time: 0.000112 Lock_time: 0.000036 Rows_sent: 1 Rows_examined: 1
SET timestamp=1438722045;
SELECT value FROM mysql.rds_heartbeat2;
# Time: 150804 21:01:00
What is this?
I have maybe one or two my queries which I need to optimize and rest of log file is this.
How is this related to my databases? Those queries are not mine. I believe this is something what AWS do but I don't know why and how it affects the performance.
Those database are part of the Mysql server. Although I suspect that rds_heartbeat2 and rds_configuration are specific to the AWS RDS version of mysql. You can read more about heartbeat.
From dev.mysql:
INFORMATION_SCHEMA is a database within each MySQL instance, the place that stores information about all the other databases that the MySQL server maintains. The INFORMATION_SCHEMA database contains several read-only tables. They are actually views, not base tables, so there are no files associated with them, and you cannot set triggers on them. Also, there is no database directory with that name.
You can run this command to see which databases have MyISAM Tables:
select distinct(table_schema) FROM information_schema.tables where engine = 'MyISAM';
From dev.mysql.
The mysql system database includes several grant tables that contain information about user accounts and the privileges held by them.
You can run this command to see a list of users and host:
select user, host from mysql.user;
I'm having some issues logging the slow queries in my MySQL 5.1 instance. It seems to be logging every query, not just the slow ones.
Here's a sample of the logging...
# User#Host: root[root] # localhost [127.0.0.1]
# Query_time: 0.000000 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 11
SET timestamp=1398191470;
SELECT count(distinct(user_id)) as user_id from user_sessions where role='bidder';
# User#Host: root[root] # localhost [127.0.0.1]
# Query_time: 0.000000 Lock_time: 0.000000 Rows_sent: 9 Rows_examined: 11
SET timestamp=1398191470;
SELECT user_name FROM user_sessions WHERE last_access_ts > '2014-04-22 14:30:59';
Here's the entries in my mysql.ini file....
long_query_time = 3
slow_query_log
log-queries-not-using-indexes
You have "log-queries-not-using-indexes" turned on. That causes the server to consider all queries that are not using indexes to be "slow".
To resolve your issue, either remove "log-queries-not-using-indexes" or add indexes on "role" and "last_access_ts" fields to user_sessions table.
I just installed mysql for the first time and created a databse with create database foo;
I think I have found where mysql stores the databases (/var/lib/mysql). When I try to cd to the foo directory I get permission denied. When I try with sudo nothing happens.
output of ls -l
-rw-rw----. 1 mysql mysql 16384 Feb 21 17:44 aria_log.00000001
-rw-rw----. 1 mysql mysql 52 Feb 21 17:44 aria_log_control
drwx------. 2 mysql mysql 4096 Mar 1 22:08 foo
-rw-rw----. 1 mysql mysql 18874368 Feb 21 17:44 ibdata1
-rw-rw----. 1 mysql mysql 5242880 Mar 1 16:05 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 Feb 21 17:34 ib_logfile1
drwx------. 2 mysql mysql 4096 Feb 21 17:34 mysql
srwxrwxrwx. 1 mysql mysql 0 Mar 1 16:05 mysql.sock
drwx------. 2 mysql mysql 4096 Feb 21 17:34 performance_schema
I know your meant to view the databases and stuff through that application on the command line but I am interested as to why I can't view the foo directory when i am root.
You can't view the foo directory because of the permissions:
owner - mysql - read, write, execute
group - mysql - no access
other - no access
First connect to mysql from command prompt using
[root#host]# mysql -u root -p
Enter password:******
Now select the database using
mysql> USE DB_Name
You can use belo command to have the list of databases
mysql> SHOW DATABASES;
To get the directory details you can use
mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "dir_name"