MySQL and MariaDB Chatsheet For DBA Queries-3
MySQL and MariaDB Chatsheet For DBA Queries-3
Database Size
Table Size
All Objectes Rows count
SHOW Commands with few Parameters
Index Related
Processlist and Queries
Killing the process / Sessions by using concatination Script
MySQL Users information SQL Queries
CHARSET and COLLATIONS
Troubleshooting Locks and Waits
InnoDB related DB Queries
Performance_schema Related Database Queries
WATCH Commands
Top Queries for Security Checking in MySQL
Connections
InnoDB Table Fragmentation and Defragmentation, Free Space, Within MySQL Server
Notes
Types of fragmentation
Free space
Combined defragmentation for all causes
Fragmentation within the shared tablespace, mainly if not using innodb_file_per_table
Fragmentation within the filesystem when using innodb_file_per_table
Encryption Queries
MySQL Transaction Reporting
Report latest query for transactions active longer than 1 second
Report transaction summary
Report transaction history
Report basic metrics for committed transactions
All tables rows count by using Store Procedure
Database Size
Description SQL Statement - Queries
Database Size by DB wise SELECT table_schema AS "Database", ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024,
2) AS "Size (GB)" FROM information_schema.TABLES GROUP BY table_schema;
All Databases together in SELECT table_schema "DB Name",ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024 , 1)
Single Column "DB Size in GB" FROM information_schema.tables;
Table Size
Description SQL Statement - Queries
Table Size in SELECT table_name AS Table Name , ROUND(((data_length + index_length) / 1024 / 1024 / 1024), 2) AS Size
given Daatabase in GB FROM information_schema.tables WHERE table_schema = 'your_database_name' ORDER BY
Name (data_length + index_length) DESC;
Or
Or
Or
SELECT
CASE
WHEN table_type IS NOT NULL THEN 'TABLE'
WHEN routine_type = 'PROCEDURE' THEN 'PROCEDURE'
WHEN routine_type = 'FUNCTION' THEN 'FUNCTION'
WHEN event_type IS NOT NULL THEN 'EVENT'
WHEN trigger_type IS NOT NULL THEN 'TRIGGER'
END AS DB,
COALESCE(table_type, routine_type, event_type, trigger_type) AS OBJECT,
COUNT(*) AS cnt,
'<dbname>' AS DB_name
FROM (
SELECT TABLE_TYPE AS table_type, NULL AS routine_type, NULL AS event_type, NULL AS
trigger_type
FROM information_schema.TABLES
WHERE TABLE_SCHEMA='<dbname>'
UNION ALL
SELECT NULL, ROUTINE_TYPE, NULL, NULL
FROM information_schema.ROUTINES
WHERE ROUTINE_SCHEMA='<dbname>'
UNION ALL
SELECT NULL, NULL, 'EVENT', NULL
FROM information_schema.EVENTS
WHERE EVENT_SCHEMA='<dbname>'
UNION ALL
SELECT NULL, NULL, NULL, 'TRIGGER'
FROM information_schema.TRIGGERS
WHERE TRIGGER_SCHEMA='<dbname>'
) AS combined_data
GROUP BY COALESCE(table_type, routine_type, event_type, trigger_type);
1 Note : - MariaDB has some functions that are not present in MySQL, like JSON_DETAILED, which is called JSON_PRET
2 in MySQL 8.0.
3
4 The list of those functions is present in MariaDB’s documentation, however check it twice as some information
5 regarding MySQL 8.0 is sometimes outdated, especially on this page, (like invisible columns, virtual columns,
6 wait, intersect, except, …).
7
8 This is not a blocking factor for migration, unless these functions are present in the default values of columns
9 But of course, if your application uses some of these functions, it may be necessary to modify it to use the
10 appropriate one in MySQL 8.0.
11
12 To illustrate this, let’s use the ADD_MONTHS function.
13
14 First let’s see if we have this function as default for some columns:
15
16 SELECT TABLE_NAME, COLUMN_NAME FROM information_schema.COLUMNS WHERE COLUMN_NAME LIKE 'ADD_MONTHS%';
17 +------------+-------------+
18 | TABLE_NAME | COLUMN_NAME |
19 +------------+-------------+
20 | date1 | ADD_MONTHS |
21 +------------+-------------+
22 1 row in set (0.06 sec)
23
24 Great !…. But I’m sure I’ve created a table with that specific function as default. This is what I did:
25
26 ALTER TABLE t6 ADD COLUMN future DATETIME DEFAULT (ADD_MONTHS(NOW(), 2));
27
28 In fact, several functions are acting like aliases. If we check the output of SHOW CREATE TABLE statement,
29 we can see that the function is translated:
30
31 SHOW CREATE TABLE t6\G
32 *************************** 1. row ***************************
33 Table: t6
34 Create Table: CREATE TABLE t6 (
35 id int(11) NOT NULL DEFAULT nextval(mydatabase.s3),
36 b int(11) DEFAULT NULL,
37 future datetime DEFAULT (current_timestamp() + interval 2 month),
38 PRIMARY KEY (id)
39 ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
40 1 row in set (0.000 sec)
SELECT VERSION(); SHOW VARIABLES LIKE 'lower_case_table_names'; SHOW VARIABLES LIKE '%char%'; SHOW
VARIABLES LIKE '%collat%'; SHOW DATABASES;
show variables like '%slow_query%'; show variables like 'log_bin_trust_function_creators'; show variables like 'long_query_time';
Index Related
Description SQL Statement - Queries
Find tables with non-integer SELECT table_schema, table_name, column_name, data_type, character_maximum_length FROM
PK’s information_schema.columns WHERE column_key IN ('PRI','UNI')
AND ordinal_position=1 AND data_type NOT IN ('tinyint', 'smallint', 'mediumint', 'int', 'bigint',
'timestamp', 'datetime') AND table_schema NOT IN ('mysql', 'information_schema', 'sys',
'performance_schema');
Find tables and indexes with The overall performance improvement gained by optimizing a single part of a system, is limited by the
the most latency fraction of time that the improved part is actually used -
Find tables whose indexes > SELECT table_schema, table_name, index_length, data_length, index_length/data_length AS
data by 50% index_to_data_ratio FROM information_schema.tables
WHERE table_schema NOT IN ('mysql', 'information_schema', 'sys', 'performance_schema') AND
INDEX_LENGTH > DATA_LENGTH*1.5;
Find unused indexes SELECT * FROM sys.schema_unused_indexes WHERE object_schema NOT IN ('mysql',
‘information_schema', ‘sys', ‘performance_schema’);
After analyze table (analyze table command: “ analyze table <tablename> for all; “ )
Getting the index related SELECT distinct table_name, index_name, column_name from information_schema.statistics where
information by providing the table_schema = '<dbname>' and index_name not like 'SYS%' and index_name != 'PRIMARY' order
given DB name by 1, 2, seq_in_index;
List of Users , Host , DB count from current Processlist SELECT USER,HOST, DB,COUNT(*) from information_schema.processlist
group by user, db order by 4;
List of Users , Host , DB , Queries count from current SELECT id,HOST,PROGRESS,user,time,substr(info, 1, 100) FROM
Processlist information_schema.processlist where command != 'Sleep' order by time;
Display number of connections for each user SELECT USER, COUNT(*) FROM information_schema.processlist GROUP
BY USER ;
Display number of connections for each host SELECT HOST, COUNT(*) FROM information_schema.processlist GROUP
BY HOST;
Display root user activity SELECT * FROM information_schema.processlist WHERE USER = 'root';
Display processes associated with SELECT queries SELECT * FROM information_schema.processlist WHERE INFO LIKE
'SELECT %';
Display average query time for each database SELECT DB, AVG(TIME) FROM information_schema.processlist GROUP BY
DB;
Stop/Kill Queries using the Transaction IDs taken from CALL mysql.rds_kill(processID);
the PROCESS LIST commands
Find Waiting Transactions and the Locks SELECT r.trx_id waiting_trx_id, r.trx_mysql_thread_id waiting_thread, r.trx_query
blocking the resource required waiting_query, b.trx_id blocking_trx_id, b.trx_mysql_thread_id blocking_thread,
b.trx_query blocking_query FROM information_schema.innodb_lock_waits w INNER
[ MySQL 5.7 DB Version ]
JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id INNER JOIN
information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id;
Find Waiting Transactions and the Locks SELECT r.trx_id waiting_trx_id,r.trx_mysql_thread_id waiting_thread,r.trx_query
blocking the resource required waiting_query, b.trx_id blocking_trx_id, b.trx_mysql_thread_id blocking_thread,
b.trx_query blocking_query FROM performance_schema.data_lock_waits w INNER
[ MySQL 8 DB Version ]
JOIN information_schema.innodb_trx b ON b.trx_id =
w.blocking_engine_transaction_id INNER JOIN information_schema.innodb_trx r ON
r.trx_id = w.requesting_engine_transaction_id;
Query that you can use to verify the Storage Engines SELECT COUNT(*) as '# TABLES', CONCAT(ROUND(sum(data_length) / (
actually used on your database 1024 * 1024 * 1024 ), 2), 'G') DATA,CONCAT(ROUND(sum(index_length) / (
1024 * 1024 * 1024 ), 2), 'G') INDEXES,CONCAT(sum(ROUND(( data_length
+ index_length ) / ( 1024 * 1024 * 1024 ), 2)), 'G') 'TOTAL SIZE', ENGINE
FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN
('mysql', 'information_schema', 'performance_schema', 'sys') GROUP BY
engine;
Display the Storage Engines other than MyISAM and SELECT TABLE_SCHEMA, TABLE_NAME, ENGINE FROM
InnoDB information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('mysql',
'information_schema', 'performance_schema', 'sys') AND engine NOT IN
('MyISAM','InnoDB');
Note :- If we see any Engine = aria or any other Engines , from above
command ,
There are two ways to fix this, either we modify the engine directly on the
MariaDB server (recommended), or we modify the engine when loading the
data on MySQL 8.0.
Recommended way:
I will illustrate the dump in the next part without first changing the storage
engine to InnoDB, but be aware that sometimes there may be limitations
related to the size of the rows, it also depends on the character set used.
The MySQL DBA has also access to the disk space select * from health_block_device order by timestamp desc limit 10;
usage via the SQL interface using
Performance_Schema. In MySQL Database Service,
Performance_Schema provides some extra tables that
are part of the Health Monitor:
Using performance_schema you can also find the size SELECT format_bytes(sum(data_length)) DATA_SIZE,
of your dataset and the space used on disk: format_bytes(sum(index_length)) INDEX_SIZE,
format_bytes(sum(data_length+index_length)) TOTAL_SIZE,
format_bytes(sum(data_free)) DATA_FREE, format_bytes(sum(FILE_SIZE))
FILE_SIZE, format_bytes((sum(FILE_SIZE)/10 - (sum(data_length)/10 +
sum(index_length)/10))*10) WASTED_SIZE FROM
information_schema.TABLES as t JOIN
information_schema.INNODB_TABLESPACES as it ON it.name =
concat(table_schema,"/",table_name) ORDER BY (data_length +
index_length);
In the result of the previous SQL statement, we can SELECT NAME, TABLE_ROWS, format_bytes(data_length) DATA_SIZE,
see in the last column (WASTED_SIZE) that there are format_bytes(index_length) INDEX_SIZE,
almost 650MB of wasted disk space. This column format_bytes(data_length+index_length) TOTAL_SIZE,
represents gaps in tablespaces. Let’s find out for format_bytes(data_free) DATA_FREE, format_bytes(FILE_SIZE) FILE_SIZE,
which tables and how to recover it: format_bytes((FILE_SIZE/10 - (data_length/10 + index_length/10))*10)
WASTED_SIZE FROM information_schema.TABLES as t JOIN
information_schema.INNODB_TABLESPACES as it ON it.name =
Disk Space Utilization concat(table_schema,"/",table_name) ORDER BY (data_length +
index_length) desc LIMIT 10;
set information_schema_stats_expiry=0;
SELECT NAME, TABLE_ROWS, format_bytes(data_length) DATA_SIZE,
format_bytes(index_length) INDEX_SIZE,
format_bytes(data_length+index_length) TOTAL_SIZE,
format_bytes(data_free) DATA_FREE, format_bytes(FILE_SIZE) FILE_SIZE,
format_bytes((FILE_SIZE/10 - (data_length/10 + index_length/10))*10)
WASTED_SIZE FROM information_schema.TABLES as t JOIN
information_schema.INNODB_TABLESPACES as it ON it.name =
concat(table_schema,"/",table_name) ORDER BY (data_length +
index_length) desc LIMIT 10;
Note that in order for this query to work, you need to have the Performance
Schema enabled in your MySQL installation, and you need to have the
appropriate privileges to access the performance_schema database.
WATCH Commands
1 watch -n 1 'mysql --defaults-file=/etc/my.cnf -h 127.0.0.1 -P 6032 -t -e "select b.weight, c.* from
2 stats_mysql_connection_pool c left JOIN runtime_mysql_servers b ON c.hostgroup=b.hostgroup_id and
3 c.srv_host=b.hostname and c.srv_port = b.port where hostgroup in( 50,52,70,71) order by hostgroup,
4 srv_host desc;" -e " select srv_host,command,avg(time_ms), count(ThreadID) from stats_mysql_processlist
5 group by srv_host,command;" -e "select * from stats_mysql_users;";
6 mysql --defaults-file=~/.my.cnf -h 127.0.0.1 -P 6032 -t -e "select * from stats_mysql_global "|egrep -i
7 "(mirror|memory|stmt|processor)"'
8
9 +--------+-----------+--------------------------------------------------------------------------+----------+----
10 | weight | hostgroup | srv_host | srv_port | STA
11 +--------+-----------+--------------------------------------------------------------------------+----------+----
12 | 1000 | 70 | proxysqltestdb.c7wzm8xxmrze.eu-central-1.rds.amazonaws.com | 3306 | ONL
13 | 1000 | 71 | proxysqltestdb2.c7wzm8xxmrze.eu-central-1.rds.amazonaws.com | 3306 | ONL
14 | 1000 | 71 | proxysqltestdb.c7wzm8xxmrze.eu-central-1.rds.amazonaws.com | 3306 | ONL
15 | 1 | 71 | proxysqltestdb-eu-central-1b.c7wzm8xxmrze.eu-central-1.rds.amazonaws.com | 3306 | ONLI
16 +--------+-----------+--------------------------------------------------------------------------+----------+----
17 +----------+----------------------+--------------------------+
18 | username | frontend_connections | frontend_max_connections |
19 +----------+----------------------+--------------------------+
20 | m8_test | 0 | 10000 |
21 +----------+----------------------+--------------------------+
22 | Query_Processor_time_nsec | 0 |
23 | Com_backend_stmt_prepare | 0 |
24 | Com_backend_stmt_execute | 0 |
25 | Com_backend_stmt_close | 0 |
26 | Com_frontend_stmt_prepare | 0 |
27 | Com_frontend_stmt_execute | 0 |
28 | Com_frontend_stmt_close | 0 |
29 | Mirror_concurrency | 0 |
30 | Mirror_queue_length | 0 |
31 | SQLite3_memory_bytes | 2652288 |
32 | ConnPool_memory_bytes | 712720 |
33 | Stmt_Client_Active_Total | 0 |
34 | Stmt_Client_Active_Unique | 0 |
35 | Stmt_Server_Active_Total | 0 |
36 | Stmt_Server_Active_Unique | 0 |
37 | Stmt_Max_Stmt_id | 1 |
38 | Stmt_Cached | 0 |
39 | Query_Cache_Memory_bytes | 0 |
40
41 Reference Links :-
42
43 https://www.tusacentral.com/joomla/index.php/mysql-blogs/199-how-to-implement-proxysql-with-aws-aurora
44 https://www.tusacentral.com/joomla/index.php/mysql-blogs/168-how-to-mess-up-your-data
45 -using-one-command-in-mysqlgalera
Find the Tables without SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND
Primary Key table_name NOT IN ( SELECT DISTINCT table_name FROM information_schema.statistics WHERE
index_name = 'PRIMARY');
Top 10 Large Tables SELECT table_name AS TABLE_NAME round(((data_length + index_length) / 1024 / 1024), 2)
Table_Size_MB FROM information_schema.TABLES WHERE
table_schema = "<your_database_name>” ORDER BY (data_length + index_length) DESC LIMIT 10
;
Top 10 Fragmented Tables SELECT table_name AS Table_Name, round((data_free / 1024 / 1024), 20 Free_Space_MB FROM
information_schema.TABLES WHERE table_schema =”<your_database_name>" AND data_free > 0
ORDER BY data_free DESC LIMIT 10;
Duplicate Index SELECT GROUP_CONCAT(DISTINCT(index_name) SEPARATOR ', ') AS Duplicate_Indexes FROM
information_schema.statistics WHERE table_schema = '<Your_database_name>' AND non_unique = 0
GROUP BY table_name, index_name HAVING COUNT(*) > 1;
Or
Or
Reference Link :- Take This Unique Quiz About Duplicate Indexes In MySQL | pt-duplicate-key-chec
ker
Connections
Description SQL Statement - Queries
Checking the Secure The first thing we can check is that all our clients encrypt their connection to the MySQL server.
Connections
We use again Performance_Schema to retrieve the relevant information:
Note :- If we want to force the user to use encrypted connections to our MySQL DB system, we modify the
user like this:
Failed Connections As a DBA, you also need to verify who is trying to connect unsuccessfully to your database server. It could be
a user without the right credentials, using a non supported TLS or cipher version or eventually a malicious
person/program.
The plugin library is connection_control.so that is installed in the plugin directory. On Oracle Linux/RedHat
Enterprise/CentOS/Fedora the default path, if MySQL Server was installed via RPM, is:
/usr/lib64/mysql/plugin/connection_control.so.
It’s possible to install the plugin in my.cnf, see the manual, but we will see how to use it interactively:
Now, let’s configure the plugin. We will set the threshold of consecutive failed connection tentative to 4 and
add a minimum of 1,5 seconds:
If there are failed login attempts, we will be able to list them in Information_Schema using the table
connection_control_failed_login_attempts, for the moment it’s still empty:
memory tracking The current global memory consumption (including background threads and admin) can be returned by the
following query:
Error Logging select * from (select * from performance_schema.error_log order by logged desc limit 10) a order by logged\G
The error log provides a lot of information about how healthy is your system, about health monitor, InnoDB,
replication, authentication failures, etc…
For example, we can see the disk usage (see the previous post) in the error_log table too:
select * from error_log where subsystem="Health" and data like 'DISK:%' order by logged desc limit 4\G
select * from (select * from performance_schema.error_log order by logged desc limit 10) a order by logged\G
Notes
1
2 --> It is not necessary for the proper functioning of MySQL or InnoDB to do any defragmentation.
3 --> It is solely a possible performance or free space effect.
4 --> Usually it is just a waste of time and resources to even consider it. But not always.
5 --> There can be significant benefits for table or index scans.
6 --> The first defragmentation of a table will normally take much more time than later ones when the bulk of the
7 table is already defragmented.
8
9 --> From MySQL 5.6.17 OPTIMIZE TABLE, ALTER TABLE FORCE or ALTER TABLE ENGINE=INNODB for a table that is already
10 InnoDB will use online DDL to allow DML during the operation if possible.
11 --> This makes it far more practical to carry out the internal defragmentation since you can just use
12 OPTIMIZE TABLE and then perform filesystem defragmentation.
13 --> This is the preferred way if you are using a suitable version of the server. You should still try to
14 carry out the operation at a low load time because the disk I/O will slow the server significantly.
15 --> Ensure that innodb_online_alter_log_max_size is large enough to hold all DML on the table during the
16 online operation.
17 --> Use innodb_sort_buffer_size to improve the speed of index rebuilding during the operation; the default
18 of 1M is quite small and some tens or hundreds of megabytes can be useful for larger indexes to reduce the
19 number of sort merge passes used.
20 --> The non-blocking inplace method will not be used if old_alter_table is on, the table contains fulltext index
21 skip-new is enabled and you are using OPTIMIZE TABLE or if you use COPY to force a copy instead of inplace;
22 in these cases the instructions below may be more suitable and you cannot carry out the operation without
23 blocking all DML during it.
Types of fragmentation
There are several things that may be called fragmentation that can be of interest. There is no single definition of the word fragmentation that
applies to InnoDB since the term is used to refer to many different things.
Free space
Sometimes people think of fragmentation as free space that could be reused. Mostly you should ignore this but sometimes it is of use to try
to make the free space available to the filesystem or other tables. Any rebuilding of a table will do this, a null ALTER TABLE, say. If you want
to check the free space you can do queries like
1 SELECT table_schema, table_name, data_free / 1024 / 1024 AS data_free_in_MB FROM information_schema.tables WHERE
2 engine LIKE 'InnoDB' AND data_free > 5000*1024*1024;
This will return tables with more than five thousand megabytes of reported fee data space. It requires MySQL 5.1.21 or later. Freeing disk
space can be useful for many reasons so this can be more useful than other things that are called fragmentation.
1
2 --> From version 5.6.17 and later OPTIMIZE TABLE will use online DDL with algorithm=inplace to leave the table
3 modifiable during the operation. You should still try to carry out the task at a low load time.
4 --> Before 5.6.17, if you want to reduce all of the types of fragmentation and are using innodb_file_per_table
5 you can do this:
6
7 1. Optional, defragment within the filesystem using a filesystem defragmentation tool or copying the *.ibd files
8 somewhere and back to the original place.
9 2. ALTER TABLE tablename DROP INDEX index1, DROP INDEX index2 etc. to drop all of the non-unique secondary index
10 Skip this if not using MySQL 5.5 or later.
11 3. ALTER TABLE tablename ENGINE = InnoDB or OPTIMIZE TABLE tablename or in MySQL 5.5 and later ALTER TABLE
12 tablename FORCE to rebuild the clustered index and data rows.
13 4. ALTER TABLE tablename ADD INDEX index1 and its details, ADD INDEX index2 and its details etc. to add back the
14 dropped indexes. Skip this if not using MySQL 5.5 or later.
15 5. Optional, there may now be some filesystem fragmentation, consider whether it is worth using a filesystem
16 defragmentation tool.
17
18 You should not expect to be able to have the server in production service when you do this work. It is extremely
19 diskintensive and makes very heavy use of the buffer pool so performance for other work will be severely
20 impacted unless the tables are small.
21
22 If a table is changed after this work the fragmentation will gradually return. The effect will be greatest for
23 secondary indexes or for a clustered/primary index where rows are not inserted in primary key order.
24
25 A clustered/primary index will remain well defragmented for existing data if new data is added sequentially and
26 no deletes or updates are done.
27
28 There is no specific schedule for doing this work. You can schedule all or some of it based on your observation
29 of the rates at which each individual table becomes fragmented enough to make a difference. It is normal for
30 different tables and indexes to be affected at different rates and to benefit to different degrees.
1 If not using innodb_file_per_table (manual), space is allocated within the shared tablespace: the ibdata1 file
2 and others you may have allocated. Any ALTER TABLE operation with COPY algorithm will reduce this fragmentation.
3
4 It can be quite significant for performance when doing table scans. This cannot affect you for a table that is
5 using innodb_file_per_table, except that the undo log can cause the file to grow and that can sometimes cause a
6 little fragmentation.
7
8 If doing this defragmenting you should do the smaller tables before the larger ones because a copy of the table
9 is made within the shared tablespace. That copy will increase the shared tablespace size. If you do the small
10 tables first, the space freed by rebuilding them will be available to later tables and this will reduce the
11 amount of growth or possibly eliminate it.
12
13 Alternatively, if no foreign keys will be affected, you could alter the table to MyISAM and back to InnoDB.
14 The conversion to MyISAM will free the space within the shared tablespace and the conversion back to InnoDB
15 will be able to reuse that space, usually preventing growth. If you want to use the MyISAM method use:
16
17 1. ALTER TABLE tablename ENGINE=MyISAM;
18 2. ALTER TABLE tablename ENGINE=InnoDB;
1 This is the most serious form and can cause significant performance issues, most visible when dropping a table.
2 To check the amount of fragmentation use filefrag on Linux, chkdsk on Windows with FAT32 or the defragmentation
3 tool in other Windows filesystems. If you find that you have fragmented tables the best way to defragment them
4 without using a defragmentation tool is to:
5
6 1. Shut down mysqld
7 2. Make a copy of the *.ibd file.
8 3. Delete the original *.ibd file.
9 4. Move the copied file to the location of the original
10
11 The *.ibd files are located in the sub-directory that normally has the same name as the database the table
12 belongs to. If you do have a defragmentation tool, it is better to use that.
13
14 This is likely to be much faster than the other steps and is likely to deliver the greatest benefit
15 if there is significant filesystem fragmentation.
Encryption Queries
1 SELECT NAME, CURRENT_KEY_VERSION from information_schema.INNODB_TABLESPACES_ENCRYPTION;
2
3 To see, which users are using an encrypted connection, run the following query
4 --------------------------------------------------------------------------------
5
6 Note :- performance_schema variable should be turned "ON"
7
8 SELECT sbt.variable_value AS tls_version, t2.variable_value AS cipher, processlist_user AS user,
9 processlist_host AS host FROM performance_schema.status_by_thread AS sbt JOIN
10 performance_schema.threads AS t ON t.thread_id = sbt.thread_id JOIN
11 performance_schema.status_by_thread AS t2 ON t2.thread_id = t.thread_id WHERE
12 sbt.variable_name = 'Ssl_version' and t2.variable_name = 'Ssl_cipher' ORDER BY tls_version;