Aruba-MySQL: can't create/change table to engine=INNODB - mysql

We have our database stored in aruba (mysql.aruba.it) where there is a table called "task". Because of many changes in the requirements we decided to drop the table and create it again from 0 with different fields and constraints. The problem is that MySQL/Aruba won't let us create the table anymore. Or better, we can create another task table only with engine MyISAM but we need INNODB because we will use contraints and foreign keys in the table. So I have tried to create a MyISAM table and then convert it into INNODB but I get an error like this:
ALTER TABLE `task` ENGINE = INNODB
#1025 - Error on rename of './Sql689345_4/#sql-6962_1891f' to './Sql689345_4/task' (errno: -1)
I don't know why there is this problem with this table: for other tables we have we can drop them and re-create them as many times as we want.
Is there a way to fix it?

Not all Aruba databases accept InnoDB tables; verify on the "Engine" link inside the control panel if INNODB is in white (engaged) or in grey (disengaged); if your database does not support InnoDB tables you can ask a new database supporting InnoDB for free, opening an assistance ticket.
In order to convert a table from MyIsam to InnoDB, is not a good practice to use the command ALTER TABLE, I suggest to export your table in a .sql file, CREATE a new table with the required structure and the InnoDB engine, and then import the data from .sql file.

Related

How to move InnoDB table to another drive?

I have MySQL running on SSDs, SSDs that I'm about to run out of space on. My webhost overcharges for SSDs and the majority of the data in MySQL is "archived" data (i.e. data that isn't actively used). I have larger HDDs that can hold this data. As such, I want to be able to move specific InnoDB tables from the SSDs to the HDDs.
One solution I've thought about and researched is moving the individual .ibd files (I have innodb_file_per_table enabled) for the specific tables in question to the HDDs and then symlink. However, researching this, it looks like that is a bad idea for InnoDB.
I've also seen that since 5.6, MySQL supports the DATA DIRECTORY command:
To create a new InnoDB file-per-table tablespace in a specific
location outside the MySQL data directory, use the DATA DIRECTORY =
absolute_path_to_directory clause of the CREATE TABLE statement.
Plan the location in advance, because you cannot use the DATA
DIRECTORY clause with the ALTER TABLE statement. The directory you
specify could be on another storage device with particular performance
or capacity characteristics, such as a fast SSD or a high-capacity
HDD.
The problem is, it looks like this is only supported for new tables. I want to do it for existing tables. Any tips on how? I'm running Percona MySQL, if it helps.
Thanks!
UPDATE: Here is what I tried, but I'm getting a syntax error:
CREATE TABLE abc_2 LIKE abc ENGINE=InnoDB DATA DIRECTORY='/xxx/mysql/archive/'
Apparently CREATE ... LIKE ... DATA DIRECTORY ... is a combination that is not supported.
Do SHOW CREATE TABLE to get the current definition. Edit it to add DATA DIRECTORY and INDEX_DIRECTORY. Then use the edited text to create the new table.
Then INSERT INTO new_tbl SELECT * FROM real_tbl; and shuffle the names: RENAME TABLE real_tbl TO old_tbl, new_tbl TO real_tbl;.
Verify the results and finally DROP old_tbl;
I have dealt with this problem myself, and eventually found a more elegant solution than 'create new - copy - switch': detaching, moving and re-importing the underlying tablespace files. This is much more efficient on large and/or heavily indexed tables as MySQL does not have to redo work it has already done.
In short, it comes down to the following steps:
FLUSH TABLES `table_name` FOR EXPORT;
While keeping the connection open, move the tablespace files in a shell:
$ mv /var/lib/mysql/database_name/table_name.{ibd,cfg} ~
Now back in MySQL release the lock, drop the table, re-create it with the correct DATA DIRECTORY and discard its tablespace:
UNLOCK TABLES;
SHOW CREATE TABLE `table_name`;
DROP TABLE `table_name`;
CREATE TABLE `table_name` /* ... */ DATA DIRECTORY='/path/to/desired/location';
ALTER TABLE `table_name` DISCARD TABLESPACE;
Now copy the moved tablespace files to the desired location:
$ cp -a ~/table_name.{ibd,cfg} /path/to/desired/location
And import them:
ALTER TABLE `table_name` IMPORT TABLESPACE;
More background and motivation for why 'create new - copy - switch' is inefficient can be found in a blogpost I wrote on this topic: https://www.moxio.com/blog/28/moving-individual-mysql-tables-on-disk.

MySQL 5.6.10 InnoDB cannot create table as table already exists

I have a very interesting case. Several of my InnoDB tables got somehow corrupted. The .frm files of the tables disappeared and only the .ibd files were left.
I thought no problem, I will restore these tables from the backup, so I deleted the .frm files and try to create the new tables with the same name, but every time I get "the table already exists", the .ibd file gets created, but the .frm not.
Basically now I cannot create InnoDB tables with the given names in the given database. My only solution was to create MyISAM tables instead, but I would still like to know how to resolve this.
Below is a detailed log of the events:
Try to create the table:
CREATE TABLE employee
( employee_id varchar(20) NOT NULL,
PRIMARY KEY (employee_login_id) USING BTREE )
ENGINE=InnoDB DEFAULT
CHARSET=utf8 PACK_KEYS=1 ROW_FORMAT=COMPRESSED
table already exists
Try to drop the table to show that it doesn't exist:
DROP TABLE employee
table doesn't exist
I manually deleted the employee.ibd file (there is no employee.frm file)
Try #1 again and receive the "table already exists" again
I have restarted MySQL, no change.
I have restarted the whole server, no change.
I cannot create an InnoDB table with the name "employee" in this tablespace anymore.
Any idea?
Information about a table is stored in two places:
Server-wide table.frm file
Storage-engine specific InnoDB dictionary
These two must be in-sync, but there is no reliable mechanism to enforce this consistency. Due to number of reasons InnoDB dictionary gets out of sync.
In your case there is an orphaned record in the dictionary. You need to delete it.
InnoDB doesn't provide any way to manually modify the dictionary records. But you can craft a fake table.frm (if innodb_file_per_table=ON then table.ibd too) files, put it into the database directory and drop the table.
Old versions of InnoDB might complain about mismatching SPACENO. Then check how to fix InnoDB dictionary

How to fix The used table type doesn't support FULLTEXT indexes without loosing data?

Today I try to convert my wordpress blog MySQL database table (only wordpress system table) engines from MyISAM to InnoDB. I can convert all the wordpress system tables, except _posts table. When I run this command,
ALTER TABLE table_prefix_here_posts ENGINE=InnoDB;
I get following error.
#1214 - The used table type doesn't support FULLTEXT indexes
I search on Google and found that I can fix it by doping the table. But in my situation, as far as I know, if I drop the _posts table, I lose all my blog posts. Therefore are there anyway to convert my _posts table to InnoDB without loosing my posts (data)?
FULLTEXT indexes are supported in InnoDB tables only starting from MYSQL 5.6 so try to update MYSQL and after that alter table's engine

Changing storage engine of table in Mysql

Currently the storage type of table is innodb , i want to add full text search on the table which is only possible on MYISAM engine.
I tried using the command => alter table film engine = myisam;
and got the error:
1217 - Cannot delete or update a parent row: a foreign key constraint fails
Help Please!!
Thanks.
You must find the tables in the database that refer to this table through a FK constraint:
Identify the foreign key constraints for the table. Either use
SHOW CREATE TABLE `table_in_db_film`\G;
or
USE db_of_film_table;
SHOW TABLE STATUS LIKE 'film'\G
afterwards execute the necessary statements
ALTER TABLE film DROP FOREIGN KEY `ibfk_something`;
until you drop all constraints (of course replace ibfk_something with your constraint names). After this you should be able to alter the table engine.
You can't change the table's engine to MyISAM without removing the Foreign Key constraints and thus losing integrity.
It would be better to use both engines, MyISAM and InnoDB. Keep all data in InnoDB and duplicate the table (or just the columns you want to be full-text searching) in MyISAM. This will need some mechanism (triggers) for the data duplication to be automated.
Other options here: MySQL storage engine dilemma

Changing Table Engine in MySQL

I am using mysql and mysql workbench. I created 5 tables with innodb engine. I checked their engine and it was innodb before I insert data into them. I inserted data from 5 MyISAM tables and now my innodb tables are MyISAM. I can't change them. I used the alter table engine=innodb but it doesn't work.
From the manual: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
For example, to convert a table to be an InnoDB table, use this statement:
ALTER TABLE t1 ENGINE = InnoDB;
The outcome of attempting to change a table's storage engine is affected by whether the desired storage engine is available and the setting of the NO_ENGINE_SUBSTITUTION SQL mode, as described in Section 5.1.11, “Server SQL Modes”.
https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sqlmode_no_engine_substitution
When you create the table do you get any warning about the Engine type being unavailable?
It's not obvious. If you edit the table and then select the column tab the engine widget is not immediately visible. On the upper right of the edit window you will see two down pointing chevrons. Select the arrow once and additional widgets will appear. In the upper right hand corner there will now be widgets for the schema and engine.