{"id":238866,"date":"2022-04-05T10:27:23","date_gmt":"2022-04-05T02:27:23","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=238866"},"modified":"2022-03-28T10:28:01","modified_gmt":"2022-03-28T02:28:01","slug":"docker-mysqld","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/docker-mysqld.html","title":{"rendered":"docker\u5b89\u88c5mysql"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4eca\u5929\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e0bdocker\u5b89\u88c5mysql\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5b89\u88c5\u597ddocker\u73af\u5883\u540e\u64cd\u4f5c<\/strong><\/div>\n
1.\u67e5\u627e\u955c\u50cf<\/strong><\/span><\/div>\n
docker search mysql\r\ndocker search mysql:5.7<\/pre>\n
2.\u62c9\u53d6\u955c\u50cf<\/strong><\/span><\/div>\n
docker pull mysql<\/pre>\n
3.\u8fd0\u884c\u5bb9\u5668<\/strong><\/span><\/div>\n
docker run -p 3306:3306 --name chengleimysql -v \/data\/mysql\/conf:\/etc\/mysql\/con.d -v \/data\/mysql\/logs:\/logs -v \/data\/mysql\/data:\/var\/lib\/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql  \r\n<\/pre>\n
\u547d\u4ee4\u8bf4\u660e<\/strong><\/span><\/div>\n
-p 3306:3306                                  \u6620\u5c04\u7aef\u53e3 \u4e3b\u673a:\u5bb9\u5668\r\n--name chengleimysql                           \u8fd0\u884c\u7684\u670d\u52a1\u540d\r\n-v \/data\/mysql\/conf:\/etc\/mysql\/con.d   \u5c06\u4e3b\u673a\u7684conf\u76ee\u5f55\u6302\u8f7d\u5230\u5bb9\u5668\u7684conf.d\u76ee\u5f55\uff08\u4e4b\u540e\u4f1a\u5728\u4e3b\u673a\u7684conf\u91cc\u5efa\u7acb\u4e00\u4e2a\u6587\u4ef6my.cnf\uff09 \r\n -v \/data\/mysql\/logs:\/logs              \u4e3b\u673a\u7684logs\u6587\u4ef6\u5939\u6302\u8f7d\u5230\u5bb9\u5668\u7684logs\u4e2d\r\n -v \/data\/mysql\/data:\/var\/lib\/mysql     \u5c06\u4e3b\u673a\u7684data\u76ee\u5f55\u6302\u8f7d\u5bb9\u5668\u91cc\u7684mysql \r\n -e MYSQL_ROOT_PASSWORD=123456           \u521d\u59cb\u5316\u7684mysql ROOT\u7528\u6237\u5bc6\u7801        \r\n -d mysql                                \u540e\u53f0\u8fd0\u884c \u5e76\u4f7f\u7528mysql\u955c\u50cf\r\n<\/pre>\n
\u9a8c\u8bc1<\/strong><\/span><\/div>\n

\u8fdb\u5165\u65b0\u5efa\u7acb\u7684mysql \u5bb9\u5668<\/p>\n

 docker esec -it faf90769b373 \/bin\/bash<\/pre>\n

\u8fdb\u5165 MYSQL \u5bb9\u5668\u91cc\u7684\u6570\u636e\u5e93<\/p>\n

 mysql -uroot -p<\/pre>\n
\u663e\u793a\u5982\u4e0b \u6210\u529f<\/strong><\/span><\/div>\n
  root@faf90769b373:\/# mysql -uroot -p\r\nEnter password: \r\nWelcome to the MySQL monitor.  Commands end with ; or \\g.\r\nYour MySQL connection id is 8\r\nServer version: 8.0.28 MySQL Community Server - GPL\r\n\r\nCopyright (c) 2000, 2022, Oracle and\/or its affiliates.\r\n\r\nOracle is a registered trademark of Oracle Corporation and\/or its\r\naffiliates. Other names may be trademarks of their respective\r\nowners.\r\n\r\nType 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.\r\n\r\nmysql> \r\n<\/pre>\n
  docker ps<\/pre>\n
\u663e\u793a\u5982\u4e0b<\/strong><\/span><\/div>\n
 [root@localhost mysql]# docker ps\r\nCONTAINER ID   IMAGE                        COMMAND                  CREATED             STATUS             PORTS                                                  NAMES\r\nfaf90769b373   mysql                        \"docker-entrypoint.s\u2026\"   20 minutes ago      Up 20 minutes      0.0.0.0:3306->3306\/tcp, :::3306->3306\/tcp, 33060\/tcp\r\n<\/pre>\n
docker\u4e2dMYSQL\u6570\u636e\u5907\u4efd<\/strong><\/div>\n
1.\u8fdb\u5165\u65b0\u5efa\u7acb\u7684mysql \u5bb9\u5668 <\/strong><\/span><\/div>\n
 docker esec -it faf90769b373 \/bin\/bash<\/pre>\n
2.\u8fdb\u5165 MYSQL \u5bb9\u5668\u91cc\u7684\u6570\u636e\u5e93<\/strong><\/span><\/div>\n
 mysql -uroot -p<\/pre>\n
3.\u5efa\u7acb\u6570\u636e\u5e93\u53ca\u8868<\/strong><\/span><\/div>\n
 create database db01;\r\n use db01;\r\n create table t_book(id int not null primary key,bookName varchar(20) );\r\n show tables; \r\ninsert into t_book values(1,'java'); \r\nselect * from t_book;<\/pre>\n
\u5b8c\u6210<\/strong><\/span><\/div>\n

\u4f7f\u7528windows\u7684SQLyog\u8f6f\u4ef6 \u6d4b\u8bd5\u8fde\u63a5
\n\u5982\u679c\u51fa\u73b02058\u9519\u8bef \u8bf7\u5728\u5bb9\u5668\u4e2d \u6267\u884c\u4e0b\u9762\u547d\u4ee4<\/p>\n

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';<\/pre>\n
4.\u628adocker\u91cc\u7684\u6570\u636e\u5e93\u5907\u4efd\u81f3\u672c\u5730<\/strong><\/span><\/div>\n
docker exec df6f2a96626f sh -c ' exec mysqldump --all-databases -uroot -p \"123456\" ' > \/data\/all-databases.sql<\/pre>\n","protected":false},"excerpt":{"rendered":"

docker search mysql docker search mysql:5.7 docker pull […]<\/p>\n","protected":false},"author":1469,"featured_media":238875,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-238866","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/238866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=238866"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/238866\/revisions"}],"predecessor-version":[{"id":238876,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/238866\/revisions\/238876"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/238875"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=238866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=238866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=238866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}