create db as innodb in mysql - mysql

I knew that we can set innodb as engine tables. But can we add this same create database query.I tried this:create database 'mydb' set engine='Innodb' but it throws error. Thanks.

That concept does not exist: databases don't have engines; tables do.
Update:
The closest you can achieve is to change the default engine for CREATE TABLE statements that don't specify one, it's explained at: http://dev.mysql.com/doc/refman/5.1/en/storage-engine-setting.html

Related

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

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.

Table storage engine for <TABLE> doesn't have this option on order by query (ERROR 1031)

Table storage engine for <TABLE> doesn't have this option.
This is the error returned by MySQL on an order by query. The column type is varchar(2000).
Query:
select * from `dbo.table_1` order by textT;
Error returned:
ERROR 1031 (HY000): Table storage engine for 'dbo.table_1' doesn't have this option.
Why does this happen? And how can I fix it?
This problem appears to occur when you're importing a table definition that had been created with MyISAM but later was switched to InnoDB; the resulting ROW_FORMAT options appear to be invalid.
If you're trying to import an exported database and encounter this problem, you can simply search and replace ROW_FORMAT=FIXED with nothing.
I used the following to do so really quickly:
sed -ie 's/ROW_FORMAT=FIXED//g' backup.sql
Problem solved! Thanks to jbrahy for pointing out that it was the ROW_FORMAT that was the problem.
EDIT: Updated to work for more platforms as per #seven's suggestion
EDIT2: Also note, as per #Steen-Schütt, this may be a safer fix
sed -ie 's/ROW_FORMAT=FIXED/ROW_FORMAT=COMPACT/g' backup.sql
You can also try this:
ALTER TABLE `dbo.table_1` ROW_FORMAT = DEFAULT ;
I get the same error when I import a table definition that's InnoDB with ROW_FORMAT=DYNAMIC in it. The table was created with a MyISAM engine but I later switched it to InnoDB. When I removed the ROW_FORMAT=DYNAMIC from the create table statement and recreated the table it worked fine. My solution to your problem would be this.
show create table `dbo.table_1`;
then take the output from that command and remove the ROW_FORMAT=DYNAMIC then rename the table to dbo.table_1_old
rename table `dbo.table_1` to `dbo.table_1_old`;
Then execute the create table statement from the first step i.e.
-- don't use this create as there are missing columns use yours
create table `dbo.table_1` (textT VARCHAR(255));
Then repopulate your table with the old data.
insert into `dbo.table_1` select * from `dbo.table_1_old`;
Then you should be able to execute your original SQL
select * from `dbo.table_1` order by textT;
This problem appears to occur when you're importing a table definition to MySQL 5.7 that had been created with MySQL 5.6 and earlier. The same error can produceb by option KEY_BUFFER_SIZE=8192 and similar sizes defined in bytes for INNODB ENGINE.
I had this error when I'm importing base from sql-dump.
Decision: sed -ie 's/KEY_BLOCK_SIZE=16384//g' my-file-sql_dump.sql
I was facing this problem and my backup file was encrypted .zsql file. So I modified my.cnf by adding innodb_strict_mode = off. It worked fine

How do I know if a mysql table is using myISAM or InnoDB Engine?

In MySQL, there is no way to specify a storage engine for a certain database, only for single tables. However, you can specify a storage engine to be used during one session with:
SET storage_engine=InnoDB;
So you don't have to specify it for each table.
How do I confirm, if indeed all the tables are using InnoDB?
If you use SHOW CREATE TABLE, you have to parse the engine out of the query.
Selecting from the INFORMATION_SCHEMA database is poor practice, as the devs reserve the right to change its schema at any time (though it is unlikely).
The correct query to use is SHOW TABLE STATUS - you can get information on all the tables in a database:
SHOW TABLE STATUS FROM `database`;
Or for a specific table:
SHOW TABLE STATUS FROM `database` LIKE 'tablename';
One of the columns you will get back is Engine.
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'db name' AND ENGINE != 'InnoDB'
show create table <table> should do the trick.

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.

what to do when ' repair table ' query won't work in mysql?

i got this error : "The storage engine for the table doesn't support repair"
when i tried to repair the table using the query repair table tbl_college_master
table is of innodb type, but i dont know y i'm getting this error?
See the manual—REPAIR TABLE is only applicable to MyISAM, ARCHIVE and CSV storage engines.
With InnoDB you don't need this anyway, as the storage engine can't go into an inconsistent state unlike MyISAM and others.
I think you should try mysql repair tool . . . it's a great tool that can repair any type of mysql data or table containing any data. and i am sure that it will definetely repair the table using the query repair table tbl_college_master.