can mysql.user table's engine be converted from MyISAM to InnoDb? - mysql

I ran the following query on my production MySQL database:
SELECT CONCAT('`', table_schema,'`.`', table_name, '`') AS schema_tables
FROM information_schema.tables AS tb
WHERE `ENGINE` = 'MyISAM'
AND `TABLE_TYPE` = 'BASE TABLE'
ORDER BY table_name DESC;
It returned all the tables from mysql schema, some of them are:
`mysql`.`user`
`mysql`.`time_zone_transition_type`
`mysql`.`time_zone_transition`
`mysql`.`time_zone_name`
`mysql`.`time_zone_leap_second`
`mysql`.`time_zone`
`mysql`.`tables_priv`
`mysql`.`servers`
`mysql`.`proxies_priv`
...
My queries are:
1. Can these be converted to innodb safely?
2. Why were they in MyISAM engine in the first place? Did I change it by mistake or were they default?
Server version: 5.6.22-log MySQL Community Server (GPL)
PS: I know InnoDb is default engine from 5.6 and I never ran any query to convert to MyISAM.

No, you can't!
As the docs say:
Important
Do not convert MySQL system tables in the mysql database (such as user or host) to the InnoDB type. This is an unsupported operation. The system tables must always be of the MyISAM type.

Related

pass max_execution_time through mysql engine

Its error when I send a query to mysql from clickhouse server.
Mysql can't understand query like
SELECT /*+ MAX_EXECUTION_TIME(1000) */ column1, column2
from mysql_tables.table1
from clickhouse through a table created with the mysql engine.
How to correctly enter the MAX_EXECUTION_TIME() constraint? to the mysql engine when creating a table like
CREATE TABLE mysql_tables.table1
(
`id` Int32,
`status` Int32
)
ENGINE = MySQL('host',
'db',
'table1',
'user',
'password',
)
SETTINGS [MAX_EXECUTION_TIME=1000]
or to the query itself?
Unfortunately, you can't pass comment to MySQL
According to
https://clickhouse.com/docs/en/engines/table-engines/integrations/mysql/#read-write-timeout
you can set up SETTINGS read_write_timeout=XXX
Unfortunately, this is not max execution time, and query still run on MySQL side
but if you will use ProxySQL, and setup default_query_timeout
https://proxysql.com/documentation/global-variables/mysql-variables/
it could work

Error Importing SQL To MySQL Cluster. Missing Primary Key

I hope someone can help me with this. I'm moving a MySQL database (WordPress) to a MySQL Cluster running Master-Master replication. When I'm trying to import the SQL to the database I get the following error message;
Plugin group_replication reported: 'Table wpmk_actionscheduler_actions does not have any PRIMARY KEY. This is not compatible with Group Replication.'
Ok, so I know what this means or I thought I did. When I inspect this table in PHPmyAdmin, I can see this table does have a primary key. I ran the following command to find the tables without a primary key;
SELECT
tab.table_schema AS database_name,
tab.table_name AS table_name,
tab.table_rows AS table_rows
FROM information_schema.tables tab
LEFT JOIN information_schema.table_constraints tco
ON (tab.table_schema = tco.table_schema
AND tab.table_name = tco.table_name
AND tco.constraint_type = 'PRIMARY KEY')
WHERE
tab.table_schema NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')
AND tco.constraint_type IS NULL
AND tab.table_type = 'BASE TABLE';
But this doesn't return any tables (because they all have keys). And yet, my damn cluster is saying a key is missing when importing the SQL. I'm totally stuck.
I attached a screenshot of the table before I exported it. What am I missing here?
I fixed this myself by downloading MySQL Workbench, opening the .SQL and editing the create statements to include an ID column and set it as the primary key. Then I removed the alter statements which were supposed to add primary keys. I guess these are updates from developers.

What is the equivalent of sqlite_master System Table in mysql?

My goal is just to use that SQL command but to traduct it from sqlite to mysql :
cursor.execute(f"SELECT count(*) FROM sqlite_master WHERE type='table' AND name='{ctx.guild.id}_counters'")
In MySQL things are different i saw that on internet so is there an equivalent of FROM sqlite_master that means FROM every table of the database in MySQL.
It would be something like this:
SELECT COUNT(*)
FROM information_schema.TABLES t
WHERE t.TABLE_NAME = 'myname'
information_schema is an internal MySQL database that has metadata about your databases. The TABLES and COLUMNS tables are probably of most interest to you.

MYSQL query Alter table engine only if engine not innodb

I would like to run one query that alter table's engine (ALTER TABLE table1 ENGINE = INNODB) only if the current engine is not INNODB.
How can I do that?
Update:
I got a case of a query trying to alter the table's engine while its already innodb.
You can use
ALTER TABLE t ENGINE = InnoDB;
You can use this query. If db engine already InnoDB then nothing will happen.
Output will be
MySQL returned an empty result set (i.e. zero rows)
if engine not in InnoDB, then it will convert to InnoDB.
The command has no effect if the table is already on InnoDB.
You can query the table engine from information_schema:
SELECT `ENGINE` from `information_schema`.`TABLES`
WHERE `TABLE_SCHEMA`='my_schema' AND `TABLE_NAME`='table1';
http://mysql.rjweb.org/doc.php/myisam2innodb#generating_alters provides several tips about converting from MyISAM to InnoDB, including:
To generate all the ALTERs to convert all the MyISAM tables to InnoDB:
SELECT CONCAT('USE ', table_schema, '; ALTER TABLE ', table_name, ' ENGINE=InnoDB;')
FROM information_schema.tables
WHERE engine = 'MyISAM'
AND table_schema NOT IN ('mysql', 'information_schema', 'performance_schema');
Then copy and paste the output into the mysql commandline tool.

Convert MyISAM to InnoDB database

I'm trying to convert a whole database from MyISAM to InnoDB with this statement:
use information_schema;
SELECT CONCAT('ALTER TABLE ',table_schema,'.',table_name,' ENGINE=InnoDB;')
FROM information_schema.tables
WHERE engine = "MyISAM" AND table_type = "BASE TABLE" AND table_schema = "database";
and while I get a result that every table is changed for example:
ALTER TABLE database.action ENGINE=InnoDB;
when I check the table engines they're still MyISAM. The weird thing is that if I run the command separately
ALTER TABLE action ENGINE='InnoDB';
it works fine for that table.
Any tips on how to do the conversion for the whole database?
The SELECT statement you are running only generates strings; the strings it generates are not being executed as SQL statements. You'd need to take the resultset from that query, and then actually execute those statements as a separate step.