phpmyadmin에서 기존 테이블에 대한 테이블 생성 스크립트를 생성하는 방법은 무엇입니까?
phpmyadmin에서 기존 테이블에 대한 테이블 생성 스크립트를 생성하려면 어떻게해야합니까?
SQL 탭에서 다음 쿼리를 사용하십시오.
SHOW CREATE TABLE tablename
전체 쿼리를 보려면 위의 + Options라는 하이퍼 링크가 있습니다. 전체 텍스트를 선택하십시오.
SHOW CREATE TABLE <table name>
쿼리를 실행하십시오 .
Mysqladmin은 테이블 생성 스크립트를 저장하는 작업을 수행 할 수 있습니다.
1 단계, 테이블을 만들고 행을 삽입하십시오.
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
2 단계 : 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
3 단계 : penguins.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 */;
출력은 위와 아래의 여러 실행 조건 토큰에 의해 복잡해집니다. 다음 단계에서 원하지 않으면 필터링 할 수 있습니다.
4 단계 (선택 사항)에서 이러한 추가 실행 조건 토큰을 다음과 같이 필터링하십시오.
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
최종 출력을 생성합니다.
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;
information_schema.columns를 직접 쿼리하십시오.
select * from information_schema.columns
where table_name = 'your_table' and table_schema = 'your_database'
쿼리 실행은 SQL 탭입니다
CREATE TABLE 테이블 이름 표시
클릭
+Options -> Choose Full texts -> Click on Go
Copy Create Table query and paste where you want to create new table.
This may be a late reply. But it may help others. It is very simple in MY SQL Workbench ( I am using Workbench version 6.3 and My SQL Version 5.1 Community edition): Right click on the table for which you want the create script, select 'Copy to Clipboard --> Create Statement' option. Simply paste in any text editor you want to get the create script.
Using PHP Function.
Of course query function ($this->model) you have to change to your own.
/**
* Creating a copy table based on the current one
*
* @param type $table_to_copy
* @param type $new_table_name
* @return type
* @throws Exception
*/
public function create($table_to_copy, $new_table_name)
{
$sql = "SHOW CREATE TABLE ".$table_to_copy;
$res = $this->model->queryRow($sql, PDO::FETCH_ASSOC);
if(!filled($res['Create Table']))
throw new Exception('Could not get the create code for '.$table_to_copy);
$newCreateSql = preg_replace(array(
'@CREATE TABLE `'.$table_to_copy.'`@',
'@KEY `'.$table_to_copy.'(.*?)`@',
'@CONSTRAINT `'.$table_to_copy.'(.*?)`@',
'@AUTO_INCREMENT=(.*?) @',
), array(
'CREATE TABLE `'.$new_table_name.'`',
'KEY `'.$new_table_name.'$1`',
'CONSTRAINT `'.$new_table_name.'$1`',
'AUTO_INCREMENT=1 ',
), $res['Create Table']);
return $this->model->exec($newCreateSql);
}
I found another way to export table in sql file.
Suppose my table is abs_item_variations
abs_item_variations ->structure -> propose table structure -> export -> Go
Export whole database select format as SQL. Now, open that SQL file which you have downloaded using notepad, notepad++ or any editor. You will see all the tables and insert queries of your database. All scripts will be available there.
One more way. Select the target table in the left panel in phpMyAdmin, click on Export tab, unselect Data block and click on Go button.
'Programing' 카테고리의 다른 글
파이썬에서 예외 값 얻기 (0) | 2020.04.28 |
---|---|
Json Serialization에서 속성을 제외하는 방법 (0) | 2020.04.28 |
foreach와지도 사이에 차이가 있습니까? (0) | 2020.04.28 |
우분투에서 postgresql을 완전히 제거하고 다시 설치하는 방법은 무엇입니까? (0) | 2020.04.28 |
Laravel 레코드가 있는지 확인 (0) | 2020.04.28 |