I want to recreate mysql database
- Stop mysql server, delete all data file and
- Recreate mysql database
sudo scripts/mysql_install_db --user=mysql --datadir=/data
- Restart mysql database
sudo bin/mysqld_safe --user=mysql --default-character-set=utf8
- The ibdata1, ibdata2 recreate and mysql start
- I create table in innodb, but table appear in myisam
CREATE TABLE `staff` (
`staff_id` int(10) unsigned NOT NULL auto_increment,
`staff_name` varchar(300) NOT NULL,
PRIMARY KEY (`staff_id`)
) ENGINE=innodb DEFAULT CHARSET=utf8 ;
it become
CREATE TABLE `staff` (
`staff_id` int(10) unsigned NOT NULL auto_increment,
`staff_name` varchar(300) NOT NULL,
PRIMARY KEY (`staff_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;
- Run show engines in mysql, and it show
InnoDB | DISABLED | Supports transactions, row-level locking, and foreign keys
- Check mysql error file
InnoDB: Error: all log files must be created at the same time.
InnoDB: All log files must be created also in database creation.
InnoDB: If you want bigger or smaller log files, shut down the
InnoDB: database and make sure there were no errors in shutdown.
InnoDB: Then delete the existing log files. Edit the .cnf file
InnoDB: and start the database again.
Finding:
- When delete file, I forgot delete ib_logfile0 and ib_logfile1
Solution
- Stop mysqlserver
mysqladmin -uroot -ppassword shutdown
- Delete ibdata1, ibdata2, ib_logfile0,ib_logfile1
- restart mysqlserver again
sudo bin/mysqld_safe --user=mysql --default-character-set=utf8
- ibdata1, ibdata2, ib_logfile0,ib_logfile1 rebuild
- Create innodb table success
- Run show engines in mysql, and it show
show engines
- It return
InnoDB | Yes | Supports transactions, row-level locking, and foreign keys