{"id":24379793,"url":"https://github.com/zjkal/mysql-helper","last_synced_at":"2025-08-14T12:35:05.538Z","repository":{"id":191911899,"uuid":"685869516","full_name":"zjkal/mysql-helper","owner":"zjkal","description":"一个便捷的MySQL导入导出的助手类库。 a mysql import and export helper library.","archived":false,"fork":false,"pushed_at":"2024-12-05T12:00:33.000Z","size":47,"stargazers_count":71,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T20:06:25.992Z","etag":null,"topics":["composer","export","helpers","import","libraries","mysql","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zjkal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-01T07:39:59.000Z","updated_at":"2024-12-06T03:28:55.000Z","dependencies_parsed_at":"2023-09-01T13:46:28.940Z","dependency_job_id":"70254b1c-5e28-467e-9b8c-a11ec87ff26d","html_url":"https://github.com/zjkal/mysql-helper","commit_stats":null,"previous_names":["zjkal/mysql-helper"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjkal%2Fmysql-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjkal%2Fmysql-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjkal%2Fmysql-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zjkal%2Fmysql-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zjkal","download_url":"https://codeload.github.com/zjkal/mysql-helper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399877,"owners_count":20932876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","export","helpers","import","libraries","mysql","php"],"created_at":"2025-01-19T07:20:14.093Z","updated_at":"2025-04-05T21:07:42.720Z","avatar_url":"https://github.com/zjkal.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cbr/\u003e\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://cdn.0x1.site/logo-mysql-helper.svg\" alt=\"MysqlHelper\" width=\"180\" /\u003e\n    \u003cbr/\u003e\n    \u003cbr/\u003e\n    中文 | \u003ca href=\"https://github.com/zjkal/mysql-helper/blob/main/README_EN.md\" target=\"_blank\"\u003eEnglish\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/zjkal/mysql-helper/blob/main/LICENSE\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://poser.pugx.org/zjkal/mysql-helper/license\" alt=\"License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/zjkal/mysql-helper\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://poser.pugx.org/zjkal/mysql-helper/require/php\" alt=\"PHP Version Require\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/zjkal/mysql-helper\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://poser.pugx.org/zjkal/mysql-helper/v\" alt=\"Latest Stable Version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/zjkal/mysql-helper\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://poser.pugx.org/zjkal/mysql-helper/downloads\" alt=\"Total Downloads\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/zjkal/mysql-helper\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/zjkal/mysql-helper/.github/workflows/php.yml?branch=main\" alt=\"GitHub Workflow Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n`MysqlHelper` 是一个便捷的`通过PHP导入和导出Mysql数据库表结构和数据`的工具,可以快速实现mysql的数据库的导入和导出. 此类库旨在提供轻量化便捷的mysql导入导出, 开发初衷是web应用安装程序和插件类应用的数据结构导入. 因此没有做数据分批, 大量数据的导入导出并不适合.\n\n## 🧩特性\n\n- 简单易用: 仅依赖`mysqlli`扩展,`开箱即用`\n- 灵活操作: 兼容主流框架,使用更方便\n- 长期维护: 作者为自由职业者,保证项目的`长期稳定`和`持续更新`\n\n## 🚀安装\n\n通过Composer导入类库\n\n```bash\ncomposer require zjkal/mysql-helper\n```\n\n## 🌈使用文档\n\n### 1. 实例化\n\n*方式一: 常规方法*\n\n```php\nuse zjkal\\MysqlHelper;\n\n$mysql = new MysqlHelper('root', 'passwd', 'dbname', '127.0.0.1', '3306', 'utf8mb4', 'wp_');\n```\n\n*方式二: 实例化后,通过setConfig方法设置数据库配置*\n\n```php\n$mysql = new MysqlHelper();\n$mysql-\u003esetConfig(['username' =\u003e 'root', 'password' =\u003e 'passwd', 'database' =\u003e 'dbname']);\n```\n\nMysqlHelper针对常用的框架做了兼容,可以直接使用框架的数据库配置, 比如`ThinkPHP`框架或`Laravel`框架\n\n```php\n$mysql = new MysqlHelper();\n$config = config('database.connections.mysql');\n$mysql-\u003esetConfig($config);\n```\n\n### 2. 导出数据\n\n* 如果实例化时, 已经设置了表前缀,导出的表名可以不用带前缀\n\n```php\n//导出数据库(包含表结构和数据)\n$mysql-\u003eexportSqlFile('test.sql');\n\n//仅导出数据库表结构\n$mysql-\u003eexportSqlFile('test.sql', false);\n\n//导出指定表的结构和数据\n$mysql-\u003eexportSqlFile('test.sql', true, ['table1', 'table2']);\n\n//导出数据库所有表,并且添加禁用外键检查的SQL语句\n$mysql-\u003eexportSqlFile('test.sql', true, [], true);\n//php8以上可以更简洁的写法:\n$mysql-\u003eexportSqlFile('test.sql', disableForeignKeyChecks: true);\n```\n\n### 3. 导入数据\n\n* 如果需要在导入过程中自定义表前缀, 则sql文件中的表前缀需要使用`__PREFIX__`占位符代替\n* 如果实例化时, 已经设置了表前缀, 则可以不用传入第二个参数\n* 增加了数据导入时的参数, 用于设置是否删除已存在的表, 默认不删除, 一般用于数据恢复.\n\n```php\n//导入数据库\n$mysql-\u003eimportSqlFile('test.sql');\n\n//导入数据库,并自动替换表前缀\n$mysql-\u003eimportSqlFile('test.sql', 'wp_');\n\n//导入数据库,不替换前缀, 并且如果表已经存在,则先删除\n$mysql-\u003eimportSqlFile('test.sql', '', true);\n//php8以上可以更简洁的写法:\n$mysql-\u003eimportSqlFile('test.sql', dropTableIfExists: true);\n```\n\n## 📃更新日志\n\n\u003e v1.0.9 2024年12月5日\n\u003e * 增加了数据导入时的参数, 用于设置是否删除已存在的表\n\n\u003e v1.0.8 2024年11月23日\n\u003e * 修复了导入表时重复替换忽略语句的BUG\n\n\u003e v1.0.7 2024年10月4日\n\u003e * 增加导入的稳定性:过滤空行\n\n\u003e v1.0.6 2024年8月27日\n\u003e * 导入时增加了判断是否存在同名表的逻辑\n\n\u003e v1.0.5 2024年6月14日\n\u003e * 增加了在导出时可以设置禁用外键检查的参数\n\n\u003cdetails\u003e\u003csummary\u003e点击查看更多\u003c/summary\u003e\n\n\u003e v1.0.4 2024年4月19日\n\u003e * 优化了.sql文件中注释的过滤规则\n\n\u003e v1.0.3 2023年12月9日\n\u003e * 实例化时如果已经设置了表前缀,导出的表名可以不包含前缀\n\n\u003e v1.0.2 2023年9月23日\n\u003e * 增加了数据导出的稳定性\n\n\u003e v1.0.1 2023年9月10日\n\u003e * 修复了在Thinkphp框架下端口识别错误的BUG\n\u003e * 增加了导入的稳定性\n\n\u003e v1.0.0 2023年9月2日\n\u003e * 首次发布\n\u003c/details\u003e\n\n## 😎开发者们\n\n\u003c!-- readme: contributors -start --\u003e\n\u003ctable\u003e\n\t\u003ctbody\u003e\n\t\t\u003ctr\u003e\n            \u003ctd align=\"center\"\u003e\n                \u003ca href=\"https://github.com/zjkal\"\u003e\n                    \u003cimg src=\"https://avatars.githubusercontent.com/u/15082976?v=4\" width=\"100;\" alt=\"zjkal\"/\u003e\n                    \u003cbr /\u003e\n                    \u003csub\u003e\u003cb\u003ezjkal\u003c/b\u003e\u003c/sub\u003e\n                \u003c/a\u003e\n            \u003c/td\u003e\n            \u003ctd align=\"center\"\u003e\n                \u003ca href=\"https://github.com/fedsin\"\u003e\n                    \u003cimg src=\"https://avatars.githubusercontent.com/u/179591768?v=4\" width=\"100;\" alt=\"fedsin\"/\u003e\n                    \u003cbr /\u003e\n                    \u003csub\u003e\u003cb\u003efedsin\u003c/b\u003e\u003c/sub\u003e\n                \u003c/a\u003e\n            \u003c/td\u003e\n\t\t\u003c/tr\u003e\n\t\u003ctbody\u003e\n\u003c/table\u003e\n\u003c!-- readme: contributors -end --\u003e\n\n## 🐧QQ频道\n\n\u003ca href=\"https://pd.qq.com/s/7h2hvcuxs\"\u003e\n  \u003cimg src=\"https://cdn.0x1.site/qrcode-qqpd.png\"  alt=\"QQ频道-世界上最好的编程语言\"/\u003e\n\u003c/a\u003e\n\n## 📖开源协议\n\nMysqlHelper遵循[MIT开源协议](https://github.com/zjkal/mysql-helper/blob/main/LICENSE), 意味着您无需任何授权, 即可免费将MysqlHelper应用到您的项目中\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjkal%2Fmysql-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzjkal%2Fmysql-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzjkal%2Fmysql-helper/lists"}