{"id":622,"date":"2025-01-01T10:26:56","date_gmt":"2025-01-01T02:26:56","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=622"},"modified":"2025-01-01T10:26:56","modified_gmt":"2025-01-01T02:26:56","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-mac-%e4%b8%8a%e5%ae%89%e8%a3%85-mysql-%ef%bc%9f%e5%88%86%e4%ba%ab%e4%b8%80%e4%ba%9b%e5%ae%9e%e7%94%a8%e7%9a%84%e6%8a%80%e5%b7%a7%e5%92%8c%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/01\/01\/%e5%a6%82%e4%bd%95%e5%9c%a8-mac-%e4%b8%8a%e5%ae%89%e8%a3%85-mysql-%ef%bc%9f%e5%88%86%e4%ba%ab%e4%b8%80%e4%ba%9b%e5%ae%9e%e7%94%a8%e7%9a%84%e6%8a%80%e5%b7%a7%e5%92%8c%e6%96%b9%e6%b3%95\/","title":{"rendered":"\u5982\u4f55\u5728 mac \u4e0a\u5b89\u88c5 mysql \uff1f\u5206\u4eab\u4e00\u4e9b\u5b9e\u7528\u7684\u6280\u5de7\u548c\u65b9\u6cd5"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u6709\u4e9b\u670b\u53cb\u4eec\u7ecf\u5e38\u95ee\u5230\uff0c\u600e\u6837\u5728 macOS \u4e0a\u5b89\u88c5 MySQL\uff0c\u5176\u5b9e\u6709\u591a\u79cd\u65b9\u6cd5\u3002\u8fd9\u91cc\u6211\u4f1a\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u4e14\u5b9e\u7528\u7684\u5b89\u88c5\u65b9\u5f0f\uff0c\u5305\u62ec\u901a\u8fc7 Homebrew \u5b89\u88c5\u3001\u901a\u8fc7 MySQL \u5b98\u65b9\u5b89\u88c5\u5305\u5b89\u88c5\uff0c\u4ee5\u53ca\u4f7f\u7528 Docker \u7684\u65b9\u5f0f\u3002\u5982\u679c\u4f60\u6709\u504f\u597d\uff0c\u53ef\u4ee5\u9009\u62e9\u6700\u9002\u5408\u81ea\u5df1\u7684\u65b9\u6cd5\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u901a\u8fc7 Homebrew \u5b89\u88c5 MySQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Homebrew \u662f macOS \u4e0a\u7684\u4e00\u4e2a\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u80fd\u591f\u975e\u5e38\u65b9\u4fbf\u5730\u5b89\u88c5\u548c\u7ba1\u7406\u5404\u79cd\u8f6f\u4ef6\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b65\u9aa4\uff1a<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5b89\u88c5 Homebrew<\/strong>\uff08\u5982\u679c\u8fd8\u6ca1\u6709\u5b89\u88c5\uff09\uff1a<br>\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5 Homebrew\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   \/bin\/bash -c \"$(curl -fsSL https:\/\/raw.githubusercontent.com\/Homebrew\/install\/HEAD\/install.sh)\"<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u66f4\u65b0 Homebrew<\/strong>\uff08\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\uff09\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   brew update<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u5b89\u88c5 MySQL<\/strong>\uff1a<br>\u4f7f\u7528 Homebrew \u5b89\u88c5 MySQL\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   brew install mysql<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>\u542f\u52a8 MySQL<\/strong>\uff1a<br>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8 MySQL\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   brew services start mysql<\/code><\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>\u767b\u5f55 MySQL<\/strong>\uff1a<br>\u542f\u52a8\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u5165 MySQL shell\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   mysql -u root<\/code><\/pre>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li><strong>\u8bbe\u7f6e root \u5bc6\u7801<\/strong>\uff1a<br>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0croot \u7528\u6237\u6ca1\u6709\u5bc6\u7801\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u4e3a root \u8bbe\u7f6e\u5bc6\u7801\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';<\/code><\/pre>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li><strong>\u505c\u6b62 MySQL<\/strong>\uff1a<br>\u82e5\u9700\u8981\u505c\u6b62 MySQL \u670d\u52a1\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   brew services stop mysql<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u901a\u8fc7 MySQL \u5b98\u65b9\u5b89\u88c5\u5305\u5b89\u88c5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7 MySQL \u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5 MySQL\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5b8c\u6574\u7684\u5b89\u88c5\u5305\uff0c\u5305\u62ec\u56fe\u5f62\u754c\u9762\u7ba1\u7406\u5de5\u5177\uff08MySQL Workbench\uff09\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b65\u9aa4\uff1a<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u8bbf\u95ee <a href=\"https:\/\/dev.mysql.com\/downloads\/mysql\/\">MySQL \u5b98\u65b9\u4e0b\u8f7d\u9875\u9762<\/a>\u3002<\/li>\n\n\n\n<li>\u9009\u62e9 macOS \u64cd\u4f5c\u7cfb\u7edf\uff0c\u5e76\u4e0b\u8f7d <code>.dmg<\/code> \u5b89\u88c5\u5305\u3002<\/li>\n\n\n\n<li>\u6253\u5f00\u4e0b\u8f7d\u7684 <code>.dmg<\/code> \u6587\u4ef6\uff0c\u5e76\u6309\u7167\u63d0\u793a\u5b8c\u6210\u5b89\u88c5\u3002<\/li>\n\n\n\n<li>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>System Preferences<\/code> \u4e2d\u7684 MySQL \u63a7\u5236\u9762\u677f\u542f\u52a8\u548c\u505c\u6b62 MySQL \u670d\u52a1\u3002<\/li>\n\n\n\n<li>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u8fdb\u5165 MySQL shell\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   mysql -u root -p<\/code><\/pre>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li>\u4f7f\u7528 <code>MySQL Workbench<\/code>\uff08\u53ef\u9009\uff09\uff1a<br>MySQL Workbench \u662f\u4e00\u4e2a\u56fe\u5f62\u5316\u7684\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u7ba1\u7406\u4f60\u7684\u6570\u636e\u5e93\u3002\u53ef\u4ee5\u4ece MySQL \u5b98\u7f51\u4e0b\u8f7d\u5e76\u5b89\u88c5\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u4f7f\u7528 Docker \u5b89\u88c5 MySQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u4e0d\u60f3\u76f4\u63a5\u5b89\u88c5 MySQL \u5230\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u9009\u62e9\u901a\u8fc7 Docker \u6765\u8fd0\u884c MySQL\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b65\u9aa4\uff1a<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5b89\u88c5 Docker<\/strong>\uff1a<br>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5 Docker\uff0c\u53ef\u4ee5\u4ece <a href=\"https:\/\/www.docker.com\/products\/docker-desktop\">Docker \u5b98\u65b9\u7f51\u7ad9<\/a> \u4e0b\u8f7d\u5e76\u5b89\u88c5 Docker Desktop\u3002<\/li>\n\n\n\n<li><strong>\u62c9\u53d6 MySQL \u955c\u50cf<\/strong>\uff1a<br>\u6253\u5f00\u7ec8\u7aef\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u62c9\u53d6\u5b98\u65b9 MySQL \u955c\u50cf\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   docker pull mysql:latest<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u8fd0\u884c MySQL \u5bb9\u5668<\/strong>\uff1a<br>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c MySQL \u5bb9\u5668\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest<\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>\u8fde\u63a5 MySQL \u5bb9\u5668<\/strong>\uff1a<br>\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230 MySQL\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   docker exec -it mysql-container mysql -u root -p<\/code><\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>\u505c\u6b62 MySQL \u5bb9\u5668<\/strong>\uff1a<br>\u5982\u679c\u9700\u8981\u505c\u6b62\u5bb9\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   docker stop mysql-container<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. MySQL \u914d\u7f6e\u5c0f\u6280\u5de7<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u65e0\u8bba\u4f60\u9009\u62e9\u54ea\u79cd\u5b89\u88c5\u65b9\u5f0f\uff0c\u8fd9\u91cc\u6709\u4e00\u4e9b MySQL \u914d\u7f6e\u7684\u5c0f\u6280\u5de7\uff0c\u5e2e\u52a9\u4f60\u66f4\u9ad8\u6548\u5730\u4f7f\u7528 MySQL\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u4fee\u6539\u9ed8\u8ba4\u7aef\u53e3<\/strong>\uff1a<br>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cMySQL \u4f7f\u7528\u7aef\u53e3 3306\u3002\u5982\u679c\u4f60\u9700\u8981\u4fee\u6539\u7aef\u53e3\uff0c\u53ef\u4ee5\u7f16\u8f91 <code>my.cnf<\/code> \u914d\u7f6e\u6587\u4ef6\uff0c\u627e\u5230 <code>port<\/code> \u8bbe\u7f6e\u5e76\u4fee\u6539\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   &#91;mysqld]\n   port = 3307<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u542f\u7528\u8fdc\u7a0b\u8bbf\u95ee<\/strong>\uff1a<br>\u5982\u679c\u4f60\u5e0c\u671b MySQL \u5141\u8bb8\u8fdc\u7a0b\u8fde\u63a5\uff0c\u53ef\u4ee5\u7f16\u8f91 <code>my.cnf<\/code> \u6587\u4ef6\uff0c\u627e\u5230\u5e76\u4fee\u6539\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   bind-address = 0.0.0.0<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>\u81ea\u52a8\u542f\u52a8 MySQL \u670d\u52a1<\/strong>\uff1a<br>\u5728 macOS \u4e0a\u4f7f\u7528 Homebrew \u5b89\u88c5\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>brew services<\/code> \u542f\u52a8 MySQL\uff0c\u5e76\u4f7f\u5176\u968f\u7cfb\u7edf\u542f\u52a8\u81ea\u52a8\u542f\u52a8\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 MySQL \u914d\u7f6e\u5de5\u5177<\/strong>\uff1a<br>\u5982\u679c\u4f60\u901a\u8fc7 MySQL \u5b98\u65b9\u5b89\u88c5\u5305\u5b89\u88c5\uff0c\u53ef\u4ee5\u5728 macOS \u7cfb\u7edf\u504f\u597d\u8bbe\u7f6e\u4e2d\u627e\u5230 MySQL \u63a7\u5236\u9762\u677f\uff0c\u8f7b\u677e\u542f\u52a8\u548c\u505c\u6b62\u670d\u52a1\u3002<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u5e38\u89c1\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6848<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u65e0\u6cd5\u542f\u52a8 MySQL \u670d\u52a1<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u68c0\u67e5 MySQL \u9519\u8bef\u65e5\u5fd7\uff08\u901a\u5e38\u5728 <code>\/usr\/local\/var\/mysql<\/code> \u76ee\u5f55\u4e0b\uff09\uff0c\u67e5\u770b\u662f\u5426\u6709\u6743\u9650\u6216\u78c1\u76d8\u7a7a\u95f4\u95ee\u9898\u3002<\/li>\n\n\n\n<li>\u91cd\u65b0\u542f\u52a8 MySQL \u670d\u52a1\uff1a<code>brew services restart mysql<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>MySQL \u5bc6\u7801\u4e22\u5931<\/strong>\uff1a<br>\u5982\u679c\u5fd8\u8bb0\u4e86 root \u5bc6\u7801\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b89\u5168\u6a21\u5f0f\u91cd\u7f6e\u5bc6\u7801\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   sudo mysql.server stop\n   sudo mysqld_safe --skip-grant-tables &amp;\n   mysql -u root\n   UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';\n   FLUSH PRIVILEGES;\n   sudo mysql.server start<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0a\u662f\u51e0\u79cd\u5728 macOS \u4e0a\u5b89\u88c5 MySQL \u7684\u65b9\u6cd5\uff0c\u5e76\u4e14\u5305\u542b\u4e86\u4e00\u4e9b\u5b9e\u7528\u7684\u914d\u7f6e\u6280\u5de7\u3002\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u4e9b\u670b\u53cb\u4eec\u7ecf\u5e38\u95ee\u5230\uff0c\u600e\u6837\u5728 macOS \u4e0a\u5b89\u88c5 MySQL\uff0c\u5176\u5b9e\u6709\u591a\u79cd\u65b9\u6cd5\u3002\u8fd9\u91cc\u6211\u4f1a\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u4e14\u5b9e\u7528\u7684\u5b89\u88c5\u65b9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-622","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/622","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=622"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/622\/revisions"}],"predecessor-version":[{"id":623,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/622\/revisions\/623"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=622"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=622"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=622"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}