Change MySQL default table engine from MyISAM to InnoDB - mysql

I have MySQL running on my machine configured with MyISAM as its default tables.
Now I want to ask few of questions:
1) If I change the default table to InnoDB in the configuration file (my.conf), clear the log file and restart mysql, would that harm any of my previous database or tables?
2) If I alter few tables' engine to InnoDB using the following command, would that affect its data at all?
ALTER TABLE table_name ENGINE = InnoDB;
3) Is it a good idea to keep few tables as MyISAM (for read and write) and the rest as InnoDB (more for selecting data) or is it preferred to select one engine for all the tables in the database?

2) It will only affect the internal representation. Nothing that you will notice on the outside.
3) It is a perfectly good idea, if it enhances performance.

2) You can mix database types. i.e. innoDB and MyISAM.
3) innoDB supposedly keeps data safer. I think it is the default on latest versions of mySQL.

Related

Do tables with InnoDB engines can be corrupted when the default storage engine database is MyIsam?

I am developing a website for ecommerce and I'm using foreign keys for my tables relationship in my database. So I decided to use InnoDB engine for all of my tables in MySQL. But my hosting server used MyIsam for default storage engine databases and I cannot change it to InnoDB. One day, one table in my database with InnoDB engine is being corrupted and error. It says " table does not exists in engine ".
I have asked hosting customer service but they can't give me solutions.
Does my table cannot be accessed because of different engine between table and database? Because all of my tables are using InnoDB as engine but my database default storage engine is using MyIsam.
Please give me some explanation about how and maybe the solution to my problem. Thank you.
The default storage engine is relevant only if you create a table, but you don't declare the engine explicitly.
// uses the default storage engine:
CREATE TABLE mytable ( ... );
// uses innodb storage engine, regardless of default:
CREATE TABLE mytable ( ... ) ENGINE=InnoDB;
If you declare your table with ENGINE=InnoDB, it stays that way. Changing the default storage engine to MyISAM should not have any effect on existing tables. It only affects tables created subsequently, and only if they don't specify the engine.
The error "table does not exist in engine" happens when you try to query a table but the tablespace has been discarded with ALTER TABLE mytable DISCARD TABLESPACE, or if the .ibd file has been deleted from the filesystem.
This means someone destroyed your data. Unless you have a backup, there is no way to recover it now.
InnoDB has been the default storage engine since 2010. It's time to treat it as the primary way to take care of data in MySQL.
I hope you will find a new hosting provider.

Using ALTER for Table Optimization (MySql)

ALTER TABLE [tbl_name] TYPE=innodb
I have just read somewhere that using above alter table statement will optimize an existing table. I am not very sure that this would work and if yes, does it work even if table type is already InnoDB?
InnoDB:
The InnoDB storage engine in MySQL.
Support for transactions (giving you support for the ACID property).
Row-level locking. Having a more fine grained locking-mechanism gives you higher concurrency compared to, for instance, MyISAM.
Foreign key constraints. Allowing you to let the database ensure the integrity of the state of the database, and the relationships between tables.
InnoDB is more resistant to table corruption than MyISAM.
Support for large buffer pool for both data and indexes. MyISAM key buffer is only for indexes.
Another point is that MyISAM is stagnant; all future enhancements will be in InnoDB
InnoDB Limitations:
No full text indexing (Below-5.6 mysql version)
Cannot be compressed for fast, read-only
For more info on this:
http://www.kavoir.com/2009/09/mysql-engines-innodb-vs-myisam-a-comparison-of-pros-and-cons.html
When to use MyISAM and InnoDB?
http://dev.mysql.com/doc/refman/5.0/en/innodb-file-defragmenting.html
If your DB is already a innoDB you do not need to make that statement again. As for other suggestions you should use ENGINE instead of TYPE.
ALTER TABLE `table_name` ENGINE = InnoDB;
I am not sure for optimizing existing table but I can corrected your query.
ALTER TABLE `mytable` ENGINE = InnoDB;
Use the ENGINE keyword since TYPE is not supported any more
As of MySQL 5.1.8, TYPE = engine_name is still accepted as a synonym for the ENGINE = engine_name table option but generates a warning. You should note that this option is not available in MySQL 5.1.7, and is removed altogether in MySQL 5.5 and produces a syntax error.
After that your query should work and change the engine for an existing table.

If i change mysql engine from Myisam to innodb, will it affect on my data

I am new to Mysql .
will it affect my data on server if i change mysql engine from Myisam to innodb.
Thanks
Changing engine from MyISAM to INNODB should not affect your data, but safe side you can easily take backup of your table before changine engine.
Taking backup:
CREATE TABLE backup_table LIKE your_table;
INSERT INTO backup_table SELECT * FROM your_table;
It may affect the performance of your queries. You need to configure Innodb specific System variables. e.g.
innodb_buffer_pool_size = 16G
innodb_additional_mem_pool_size = 2G
innodb_log_file_size = 1G
innodb_log_buffer_size = 8M
Changing engine to INNODB:
ALTER TABLE table_name ENGINE=INNODB;
I found two caveats when converting MyISAM tables to InnoDB: row size and support for full-text indexes
I ran into an issue converting some tables from an off-the-shelf application from MyISAM to InnoDB because of the maximum record size. MyISAM supports longer rows than InnoDB does. The maximum in a default InnoDB installation is about 8000 bytes. You can work around this by TRUNCATE'ing a table that fails, but this will bite you later on the INSERT. You might have to break your data up into multiple tables or restructure it with variable length column types such as TEXT (which can be slower).
A stock Innodb installation doesn't support FULLTEXT indexes. This may or may not impact your application. For one application's table I was converting, we decided to look in other fields for the data we needed rather than doing full text scans. (I did an "ALTER TABLE DROP INDEX..." on it to remove the FULLTEXT index before converting to InnoDB.) I wouldn't recommend full-text indexes for a write-heavy table anyway.
If converting a big table full of data with "ALTER TABLE..." works on the first try, you're probably okay.
http://dev.mysql.com/doc/refman/5.5/en/innodb-restrictions.html
Lastly, if you want to convert from MyISAM to InnoDB on a running system that is read heavy (where UPDATEs and INSERTs are rare), you can run this without interrupting your users. (The RENAME runs atomically. It will back out all of the changes if any of them don't work.)
CREATE TABLE mytable_ind AS SELECT * FROM mytable;
ALTER TABLE mytable_ind ENGINE=InnoDB;
RENAME TABLE mytable TO mytable_myi, mytable_ind TO mytable;
DROP TABLE mytable_myi;

MySQL shared hosting: db is MyISAM, although all created tables are InnoDB. Can I switch? Should I?

My question is about the Type of db that is on a shared hosting Linux server. phpMyAdmin shows that db has MyISAM Type. I don't think I can change it. I mean I don't know.
All tables in that db have InnoDB type.
Does it make sense to change db type to InnoDB? Should I? (I don't know if I can choose a db type on a shared hosting server).
Of course I can contact a customer support and ask them to switch if they can, but I don't know if it makes any sense and has any pros.
Should I take care of it?
Thank you.
Added: The image above is a screenshot from phpMyAdmin.
This is the default storage engine of the server. If you do not specify a storage engine when creating a table then the server picks MyISAM as the default
For example on my server InnoDB is the default.
mysql> show engines\G
*************************** 1. row ***************************
Engine: InnoDB
Support: DEFAULT
Comment: Supports transactions, row-level locking, and foreign keys
Transactions: YES
XA: YES
Savepoints: YES
Also in answer to your second question. Yes you can change the storage engine. You can do this with the ALTER TABLE command.
ALTER TABLE mytable ENGINE=MYISAM;
I suggest not to change storage engines unless you have a specific need for a feature in an engine.
You might misunderstanding, database does not have a storage engine.
The storage engine is meant for table.
You can only switch the storage engine for tables.
However, myisam does not support transactional,
and innodb (mysql version <5.6) does not support full-text search.
Without knowing which tables in which database,
my guess is you should not change the storage engine.
Example :-
http://demo.phpmyadmin.net/STABLE/index.php?lang=en&collation_connection=utf8_general_ci
The bottom row showing in phpmyadmin is the equivalent of :-
show create database YOUR_DATABASE;
when you create new table without specify a storage engine,
the default storage engine type on the database will apply to it.
for mysql version 5.5, default storage engine is change to innodb.
there is no direct way to change database default storage engine after you have create a database
the workaround is create a new database with you desired default storage engine,
then rename all the tables currently reside in the existing database to this database.

Is there an issue using two types of tables engine into one database

I have one database with wordpress and other site installed into it, they uses same database but since the wordpress table engine is INNODB and my site is using MyISAM. Is there an issue with diff. table engine?
It's not a problem having tables with different table engines - not even in the same schema.
MyISAM is good for tables that are heavily read. InnoDB is good for tables that are heavily inserted/updated to, because it supports row-level locking. (MyISAM locks the whole table.) InnoDB also has foreign key contraints, which MyISAM does not. I could go on...
The only drawback I can think of is to that you have to manage more database settings in the MySQL configuration file (my.cnf). InnoDB and MyISAM have different setttings, like innodb_buffer_pool_size (for InnoDB) and key_buffer_size (for MyISAM).
MyISAM and InnoDB have different properties, but using them together should not be an issue. You may need to do a little more legwork when it comes to tuning your database configuration a little more (InnoDB has it's own set of configuration variables).