{"id":813,"date":"2021-12-13T04:11:00","date_gmt":"2021-12-13T04:11:00","guid":{"rendered":"https:\/\/262235.xyz\/?p=813"},"modified":"2021-12-13T04:11:00","modified_gmt":"2021-12-13T04:11:00","slug":"813","status":"publish","type":"post","link":"https:\/\/lyvba.com\/index.php\/2021\/12\/13\/813\/","title":{"rendered":"\u4f7f\u7528Docker\u90e8\u7f72MYSQL\u548c\u5efa\u7acb\u6570\u636e\u8868\uff0c\u4f7f\u7528php\u8fdc\u7a0b\u8bbf\u95ee\u5b66\u4e60\u793a\u4f8b"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/12\/1342246453.webp\" alt=\"mysql.webp\" title=\"mysql.webp\"><\/p>\n<h2>\u4f7f\u7528Docker\u90e8\u7f72MYSQL\u548c\u5efa\u7acb\u6570\u636e\u8868\uff0c\u4f7f\u7528php\u8fdc\u7a0b\u8bbf\u95ee\u5b66\u4e60\u793a\u4f8b<\/h2>\n<h3>\u547d\u4ee4: vim <code>docker-compose.yml<\/code>  # \u5efa\u7acb <code>docker-compose<\/code> \u90e8\u7f72\u6587\u4ef6<\/h3>\n<pre><code>version: '3.1'\nservices:\n  db:\n    image: mysql\n    command: --default-authentication-plugin=mysql_native_password\n    restart: always\n    environment:\n      MYSQL_ROOT_PASSWORD: test-mysql@2022\n    ports:\n      - 53306:3306\n\n  adminer:\n    image: adminer\n    restart: always\n    ports:\n      - 10086:8080<\/code><\/pre>\n<h3>\u4f7f\u7528 <code>linuxserver\/docker-compose<\/code> \u90e8\u7f72 MYSQL \u548c adminer \u670d\u52a1<\/h3>\n<pre><code>docker run --rm \\r\n  -v \/var\/run\/docker.sock:\/var\/run\/docker.sock \\r\n  -v \"$PWD:$PWD\" \\r\n  -w=\"$PWD\" \\r\n  linuxserver\/docker-compose \\r\n  up<\/code><\/pre>\n<h3>\u90e8\u7f72\u5b8c\u6210\uff0c\u6d4f\u89c8\u5668\u8bbf\u95ee  <code>http:\/\/ip:10086<\/code> \u767b\u9646\u7ba1\u7406\u5efa\u7acb\u6570\u636e\u5e93<\/h3>\n<ul>\n<li>\u53ef\u4ee5web-ui\u5efa\u7acb\u6570\u636e\u5e93\u548c\u6dfb\u52a0\u7528\u6237\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6267\u884c sql \u547d\u4ee4\u5b8c\u6210\u521b\u5efa\u7528\u6237<\/li>\n<\/ul>\n<pre><code># \u521b\u5efa\u6570\u6570\u636e\u5e93: world\nCREATE DATABASE \"world\" COLLATE 'utf8mb4_bin';\n\n# \u521b\u5efa\u7528\u6237\u5bc6\u7801\nCREATE USER 'test'@'%' IDENTIFIED BY 'NSbgs4Z8nYAnqhW';\n\n# \u4fee\u6539\u7528\u6237\u5bc6\u7801\nSET PASSWORD FOR 'test'@'localhost' = 'test@localhost';\n\n# \u4fee\u6539\u8fdc\u7a0b\u94fe\u63a5\u7684\u7528\u6237\nCREATE USER 'test22'@'%' IDENTIFIED BY 'NSbgs4Z8nYAnqhW';\nGRANT ALL PRIVILEGES ON \"world\".* TO 'test22'@'%';<\/code><\/pre>\n<p>SQL\u547d\u4ee4\u4e2d\u7684 'test22'@'%' \u53ef\u4ee5\u8fd9\u6837\u7406\u89e3: test22\u662f\u7528\u6237\u540d\uff0c%\u662f\u4e3b\u673a\u540d\u6216IP\u5730\u5740\uff0c\u8fd9\u91cc\u7684%\u4ee3\u8868\u4efb\u610f\u4e3b\u673a\u6216IP\u5730\u5740\uff0c<br \/>\u4f60\u4e5f\u53ef\u66ff\u6362\u6210\u4efb\u610f\u5176\u5b83\u7528\u6237\u540d\u6216\u6307\u5b9a\u552f\u4e00\u7684IP\u5730\u5740\uff1b'MyPassword'\u662f\u7ed9\u6388\u6743\u7528\u6237\u6307\u5b9a\u7684\u767b\u5f55\u6570\u636e\u5e93\u7684\u5bc6\u7801<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/12\/1011972683.png\" alt=\"111.png\" title=\"111.png\"><\/p>\n<h3><code>CREATE TABLE<\/code> \u521b\u5efa <code>City<\/code> \u6570\u636e\u8868\uff0c\u5982\u679c\u5df2\u7ecf\u5b58\u5728\uff0c\u4f7f\u7528 <code>DROP TABLE<\/code> \u5148\u5220\u9664<\/h3>\n<pre><code># DROP TABLE IF EXISTS \"City\";\nCREATE TABLE \"City\" ( \"ID\" int, \"Name\" text, \"CountryCode\" text,\n\"District\" text, \"Population\" int );<\/code><\/pre>\n<h3><code>INSERT INTO<\/code> \u5411 <code>City<\/code> \u6570\u636e\u8868\u63d2\u5165\u6570\u636e\uff0c\u6216\u8005\u4f7f\u7528\u5907\u4efd\u7684\u51fa\u6765\u7684\u6570\u636e\u5bfc\u5165 <code>City.sql.gz<\/code> <a href=\"https:\/\/github.com\/hongwenjun\/vps_setup\/raw\/remove\/mysql\/City.sql.gz\">\u4e0b\u8f7d<\/a><\/h3>\n<ul>\n<li><code>City.sql.gz<\/code> <a href=\"https:\/\/github.com\/hongwenjun\/vps_setup\/raw\/remove\/mysql\/City.sql.gz\">\u4e0b\u8f7d<\/a><\/li>\n<\/ul>\n<pre><code>INSERT INTO \"City\" (\"ID\", \"Name\", \"CountryCode\", \"District\", \"Population\") VALUES\n(1,    'Kabul',    'AFG',    'Kabol',    1780000),\n(2,    'Qandahar',    'AFG',    'Qandahar',    237500),\n(3,    'Herat',    'AFG',    'Herat',    186800),\n(4,    'Mazar-e-Sharif',    'AFG',    'Balkh',    127800),\n(5,    'Amsterdam',    'NLD',    'Noord-Holland',    731200),\n\n(4078,    'Nablus',    'PSE',    'Nablus',    100231),\n(4079,    'Rafah',    'PSE',    'Rafah',    92020);\n<\/code><\/pre>\n<h2>\u4f7f\u7528php\u8fdc\u7a0b\u8bbf\u95ee\u5b66\u4e60\u793a\u4f8b<\/h2>\n<h3>\u5728\u5efa\u7acbphp\u73af\u5883\u7684\u673a\u5668\u4e0a\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u6d4b\u8bd5<\/h3>\n<pre><code>docker exec -it  nginx-php bash\nphp -a\n\n$link = mysqli_connect(\"18.18.18.18\", \"test22\", \"NSbgs4Z8nYAnqhW\", \"world\",\"53306\");\n$result = mysqli_query($link, \"SELECT * FROM City LIMIT 10\");\n$rows = mysqli_fetch_all($result);\nvar_dump($rows);\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/lyvba.com\/wp-content\/uploads\/2021\/12\/925080225.png\" alt=\"test.php.png\" title=\"test.php.png\"><\/p>\n<h3><code>test.php<\/code> \u6e90\u7801, \u6f14\u793a\u7ad9 <a href=\"https:\/\/lyvba.com\/test\/test.php\">https:\/\/lyvba.com\/test\/test.php<\/a>  (php\u670d\u52a1\u56fd\u5185\uff0cmysql\u5728\u7f8e\u897f)<\/h3>\n<pre><code>&lt;?php\n\/\/ $link = mysqli_connect(\"localhost\", \"my_user\", \"my_password\", \"world\");\n$link = mysqli_connect(\"18.18.18.18\", \"test22\", \"NSbgs4Z8nYAnqhW\", \"world\",\"53306\");\n\n\/* check connection *\/\nif (mysqli_connect_errno()) {\n    printf(\"Connect failed: %s\n\", mysqli_connect_error());\n    exit();\n}\n\n\/* Create table doesn't return a resultset *\/\nif (mysqli_query($link, \"CREATE TEMPORARY TABLE myCity LIKE City\") === TRUE) {\n    printf(\"Table myCity successfully created.\n\");\n}\n\n\/* Select queries return a resultset *\/\nif ($result = mysqli_query($link, \"SELECT * FROM City LIMIT 10\")) {\n  printf(\"Select returned %d rows.\n\", mysqli_num_rows($result));\n\n  $rows = mysqli_fetch_all($result, MYSQLI_ASSOC);\n  var_dump($rows);\n\n  \/* free result set *\/\n  mysqli_free_result($result);\n}\n\n$result = mysqli_query($link, \"SELECT * FROM City LIMIT 10\");\n$rows = mysqli_fetch_all($result);\nvar_dump($rows);\n\nmysqli_close($link);\n?&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Docker\u90e8\u7f72MYSQL\u548c\u5efa\u7acb\u6570\u636e\u8868\uff0c\u4f7f\u7528php\u8fdc\u7a0b\u8bbf\u95ee\u5b66\u4e60\u793a\u4f8b \u547d\u4ee4: vim docker [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[34,59],"class_list":["post-813","post","type-post","status-publish","format-standard","hentry","category-learn","tag-php","tag-sql"],"_links":{"self":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/comments?post=813"}],"version-history":[{"count":0,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/posts\/813\/revisions"}],"wp:attachment":[{"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/media?parent=813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/categories?post=813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lyvba.com\/index.php\/wp-json\/wp\/v2\/tags?post=813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}