¿Cómo generar un script de crear tabla para una tabla existente en phpmyadmin?


¿Cómo puedo generar un script de crear tabla para una tabla existente en phpmyadmin?

Author: Eric Leschinski, 2012-07-31

7 answers

Utilice la siguiente consulta en la pestaña sql:

SHOW CREATE TABLE tablename

Para ver la consulta completa Hay este Hipervínculo llamado + Opciones a la izquierda arriba, Allí seleccione Textos completos

 342
Author: Karan Punamiya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-28 06:59:43

Ejecute la consulta SHOW CREATE TABLE <table name>.

 27
Author: Devart,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-31 11:28:28

Mysqladmin puede hacer el trabajo de guardar el script create table.

Paso 1 crear una tabla, insertar algunas filas:

create table penguins (id int primary key, myval varchar(50))
insert into penguins values(2, 'werrhhrrhrh')
insert into penguins values(25, 'weeehehehehe')
select * from penguins

Paso 2, utilice el comando mysql dump:

mysqldump --no-data --skip-comments --host=your_database_hostname_or_ip.com -u your_username --password=your_password your_database_name penguins > penguins.sql

Paso 3, observe la salida en pingüinos.sql:

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
DROP TABLE IF EXISTS `penguins`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `penguins` (
  `id` int(11) NOT NULL,
  `myval` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

La salida está saturada por una serie de tokens de condición ejecutiva por encima y por debajo. Puedes filtrarlos si no los quieres en el siguiente paso.

Paso 4 (Opcional), filtra los extra condición de ejecución tokens de esta manera:

mysqldump --no-data --skip-comments --compact --host=your_database_hostname_or_ip.com -u your_username --password=your_password your_database_name penguins > penguins.sql

Que produce la salida final:

eric@dev /home/el $ cat penguins.sql

DROP TABLE IF EXISTS `penguins`;
CREATE TABLE `penguins` (
  `id` int(11) NOT NULL,
  `myval` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 15
Author: Eric Leschinski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-18 17:11:25

Consulta information_schema.columnas directamente:

select * from information_schema.columns 
where table_name = 'your_table' and table_schema = 'your_database'
 7
Author: Eric Leschinski,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-18 17:36:28

Esta puede ser una respuesta tardía. Pero puede ayudar a otros. Es muy simple en MI SQL Workbench ( estoy usando Workbench versión 6.3 y Mi SQL Versión 5.1 Community edition): Haga clic derecho en la tabla para la que desea crear script, seleccione la opción 'Copiar al Portapapeles > > Crear Instrucción'. Simplemente pegue en cualquier editor de texto que desee obtener el script de creación.

 2
Author: Narasimman V,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-09 08:32:38

Ejecutar consulta es sql tab

MOSTRAR CREAR TABLA Nombre de tabla

Haga clic en

+ Opciones - > Elija textos completos - > Haga clic en Ir

Copie la consulta Crear tabla y pegue donde desea crear una nueva tabla.

 0
Author: Samir Mangroliya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-24 10:59:33

Una forma más. Seleccione la tabla de destino en el panel izquierdo en phpMyAdmin, haga clic en la pestaña Exportar, deseleccione el bloque de datos y haga clic en el botón Ir.

 -2
Author: BJ_,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-01 15:59:02