本文共 5622 字,大约阅读时间需要 18 分钟。
mysql> show engines;+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+| Engine | Support | Comment | Transactions | XA | Savepoints |+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES
查看 MySQL 支持的引擎以及默认存储引擎 。
show table status from 库名 where name='表名';
mysql> show table status from jdy where name='test';+------+--------+---------+------------+------+| Name | Engine | Version | Row_format | Rows |+------+-------------+-----------------+--------------+| test | InnoDB | 10 | Dynamic | 0 | # 表的存储引擎 InnoDB
show create table 表名;
mysql> use jdy; # 进入查看表的数据库Database changedmysql> show create table test;+-------+---------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+---------------------------------------------------------------------------------------------------------------------------+| test | CREATE TABLE "test" ( "name" varchar(10) DEFAULT NULL, "id" int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 | # 表的存储引擎 InnoDB
mysql> use jdy; # 进入查看表的数据库Database changedmysql> show create table test;+-------+---------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+---------------------------------------------------------------------------------------------------------------------------+| test | CREATE TABLE "test" ( "name" varchar(10) DEFAULT NULL, "id" int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 | # 表的存储引擎 InnoDB#命令: alter table 表名 engine=引擎; mysql> alter table test engine=MyISAM; #修改表的存储引擎为 MyISAMQuery OK, 0 rows affected (0.39 sec)Records: 0 Duplicates: 0 Warnings: 0mysql> show create table test;+-------+---------------------------------------------------------------------------------------------------------------------------+| Table | Create Table |+-------+---------------------------------------------------------------------------------------------------------------------------+| test | CREATE TABLE "test" ( "name" varchar(10) DEFAULT NULL, "id" int(11) DEFAULT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8 | #修改成功
vim /etc/my.cnf[mysqld]default-storage-engine=MyISAM #添加指定默认存储引擎
mysql> create table test01 (id int ); #创建表Query OK, 0 rows affected (0.00 sec)mysql> show create table test01;+--------+------------------------------------------------------------------------------------------+| Table | Create Table |+--------+------------------------------------------------------------------------------------------+| test01 | CREATE TABLE "test01" ( "id" int(11) DEFAULT NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8 | #创建的新表默认 MyISAM
设置默认存储引擎 ,创建的新表将使用 MyISAM 存储引擎 。
mysql> create table test02 (id int ) engine=InnoDB;Query OK, 0 rows affected (0.35 sec)mysql> show create table test02;+--------+------------------------------------------------------------------------------------------+| Table | Create Table |+--------+------------------------------------------------------------------------------------------+| test02 | CREATE TABLE "test02" ( "id" int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 | #新表存储引擎是 InnoDB
[root@localhost ~]#mysql_convert_table_format --host=localhost --user=root --password=abc123 --socket=/tmp/mysql.scok --engine=InnoDB jdy test01 test02
yum install perl perl-DBD-MySQL -y
vim /usr/local/mysql/bin/mysql_convert_table_format #修改命令脚本$opt_help=$opt_version=$opt_verbose=$opt_force=0;$opt_user=$opt_database=$opt_password=undef;$opt_host="localhost";$opt_socket="";$opt_engine="MYISAM";$opt_port=0;$exit_status=0;GetOptions("e|engine|type=s" => \$opt_type, #把type修改成engine"f|force" => \$opt_force,"help|?" => \$opt_help,"h|host=s" => \$opt_host,"p|password=s" => \$opt_password,"u|user=s" => \$opt_user,"v|verbose" => \$opt_verbose,"V|version" => \$opt_version,"S|socket=s" => \$opt_socket, "P|port=i" => \$opt_port) || usage(0);
ps: 第四种方法只适合MySQL 5.5版本 。MySQL 5.5 默认存储引擎MyISAM 5.7 默认存储引擎 InnoDB。
转载于:https://blog.51cto.com/13640803/2136468