Mysql安装(Mac版)

Posted by 石福鹏 on 2019-11-16

这里推荐使用homebrew安装,所以下面就按照此方式安装

一、安装

打开终端,执行命令

1
brew install mysql

如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
 ~ 
✔  brew install mysql  ✔  175  15:00:40
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 3 taps (homebrew/core, homebrew/cask and homebrew/cask-fonts).
==> New Formulae
cfn-flip easy-rsa k3sup markdownlint-cli rm-improved xbitmaps
chars fizz kube-linter mesa-glu showkey xcb-util
checkov flux lab overdrive strace xkeyboardconfig
condure glab libcap ox tree-sitter xorgrgb
dog gosec libxp phive vulture xterm
dotenv-linter isl@0.18 linux-headers regipy wangle yh
==> Updated Formulae
Updated 2775 formulae.
==> Deleted Formulae
confluent-platform fmsx ori pgplot
==> New Casks
aleo-studio flrig metaimage sky-ticket
archi font-genjyuugothic-l mmhmm spitfire-audio
caramba-switcher font-last-resort obs-ndi teamviewermeeting
coin-wallet font-last-resort-high-efficiency obs-websocket tunein
deltachat font-mamelon pitch tyme
desktoppr ibm-aspera-connect pomatez winx-hd-video-converter
deviceinfo lofi protoio-overflow wombat
electricbinary lunar-client remote-wake-up
ev3-classroom macx-video retroactive
==> Updated Casks
010-editor google-cloud-sdk qiyimedia
4k-video-downloader google-featured-photos qlcolorcode
4k-youtube-to-mp3 gotomeeting qlimagesize
5kplayer gpxsee qlmarkdown
abstract grandperspective qownnotes
acorn grandtotal qq
adguard graphicconverter qsync-client
adobe-acrobat-reader guild-wars2 querious
adobe-creative-cloud-cleaner-tool gzdoom quickbooks-online
agenda hackintool quip
aimersoft-video-converter-ultimate harmony qv2ray
airfoil hazel qview
airparrot hazeover racket
airtable hbuilderx racket-cs
ajour hiarcs-chess-explorer raindropio
alfaview hookshot rapidweaver
alfred hstracker raven-reader
alt-tab hydrogen razorsql
altair-graphql-client icab rcse
amazon-chime iconizer react-studio
amazon-music iconjar realforce
amazon-workspaces icons8 recaf
android-file-transfer icq rectangle
android-platform-tools iexplorer redcine-x-pro
android-studio iina refined-github-safari
another-redis-desktop-manager imazing regexhibit
anybar inkdrop rescuetime
anydesk insync responsively
anydo ioquake3 retrobatch
app-tamer iridient-developer retroshare
apparency iridium reunion
appcode istat-menus rhinoceros
appgate-sdp-client iterm2 ridibooks
apple-juice ithoughtsx ringcentral
appstudio itsycal ringcentral-classic
aptible itubedownloader ripcord
arq ivpn river-sparkle
astropad jabt-flow roboform
astropad-studio jalview rocket-chat
atom jamf-migrator rocket-typist
audio-hijack jami rocks-n-diamonds
audirvana jamulus rolisteam
autodesk-fusion360 jcryptool rotato
aware jetbrains-toolbox rotki
axure-rp jitouch royal-tsx
azure-data-studio joplin rsyncosx
backblaze-downloader jtool2 runjs
backuploupe julia runway
balenaetcher jumpshare sabnzbd
balsamiq-wireframes kaleidoscope sage
banking-4 karabiner-elements saoimageds9
banktivity kdiff3 scaleft
bartender keep-it scratch
base keepassxc screenflick
batteries keepingyouawake screens
battle-net keka seadrive
bbedit kext-updater second-life-viewer
beatunes keyboard-lock secretive
bettertouchtool keyboard-maestro securesafe
bibdesk keymanager segger-embedded-studio-for-arm
bilimini keysmith sequel-ace
binance kicad serial
biscuit kid3 session
bitrix24 kite sherlock
bitwarden kitty shift
blitz klokki shotcut
blobby-volley2 knime shutter-encoder
blocs kodelife sia-ui
bloomrpc ksdiff sidenotes
bluefish kubernetic sidequest
blueharvest lark sigil
bluejeans lastpass signal
bluestacks lego-mindstorms-ev3 silentknight
bonitastudiocommunity lehreroffice simplenote
boost-note lens sipgate-softphone
bootstrap-studio liclipse sitebulb
bot-framework-emulator lidarr sizzy
boxcryptor lifesize skim
boxy-suite lingo skitch
brave-browser lingon-x skyfonts
breaktimer listen1 skype
bricklink-partdesigner little-snitch slack
bricklink-studio loaf slite
brooklyn local smoothscroll
buildsettingextractor localizationeditor snagit
burp-suite lockrattler softorino-youtube-converter
busycal logdna-agent solar2d
busycontacts loom sonic-visualiser
cacher loopback soulver
calibre lrtimelapse soundsource
camo-studio lulu spires
camunda-modeler lumen splice
cctalk lx-music spotify
charles maccy sqlectron
checkra1n macdive sqlpro-for-postgres
chromium macjournal stack-stack
chronosync macpilot standard-notes
cinebench mactracker staruml
cityofzion-neon mailbutler stats
ckan mailplane steam
clamxav malus steermouse
clash-for-windows mamp stella
clashx manico strawberry
cleanmymac marathon2 streamlabs-obs
cleanshot marsedit stretchly
clip-studio-paint mater subethaedit
clipgrab matterhorn subler
cljstyle mcreator sublercli
clockify medibangpaintpro sublime-merge
coconutbattery meetingbar subsurface
coderunner megasync surge
codespace melodics swiftformat-for-xcode
colorpicker-materialdesign memo swifty
colorpicker-propicker mendeley-reference-manager swinsian
colorsnapper menubar-stats swish
colour-contrast-analyser menumeters switchhosts
coteditor merlin-project symboliclinker
craftmanager metabase sysex-librarian
crossover metasploit tableau
crystalmaker mgba tableau-public
curio mi tableau-reader
cyberduck mia-for-gmail tagspaces
cytoscape microsoft-auto-update tandem
daedalus-mainnet microsoft-azure-storage-explorer taskpaper
dangerzone microsoft-edge tastyworks
dash-dash microsoft-excel teamspeak-client
db-browser-for-sqlite microsoft-office techsmith-capture
dbeaver-community microsoft-outlook telavox-flow
dbschema microsoft-powerpoint telegram
dcommander microsoft-teams telegram-desktop
dcv-viewer microsoft-word tempo
debookee middle tencent-lemon
deezer midi-monitor texmacs
default-folder-x miktex-console texmaker
dictionaries min texpad
difffork minecraftpe texshop
disk-drill minishift the-clock
displays minizincide thingsmacsandboxhelper
docker missive thonny-xxl
dosbox-x mochi thunderbird
dotnet-sdk mockoon ticktick
drawio modern-csv tiger-trade
drivedx monero-wallet tiles
dropbox-passwords mongodb-compass timche-gmail-desktop
droplr mongodb-compass-isolated-edition timemator
dropshare mongodb-compass-readonly timing
eaglefiler mongodb-realm-studio tipp10
electerm moom toggl-track
electronmail morpheus tongbu
element mountain-duck toolreleases
eloston-chromium movist-pro tor-browser
endurance mqttx touchdesigner
epic mtgaprotracker touchosc-bridge
epichrome mudlet touchosc-editor
eset-cyber-security-pro multipass tower
eudic multiscan-3b trailer
eul multitouch transcribe
eurkey mumu transmit
evernote murus transnomino
exodus musaicfm trezor-bridge
extraterm musicbrainz-picard trilium-notes
fantastical muzzle trim-enabler
feishu neo4j tripmode
final-cut-library-manager netnewswire tunnelblick
find-any-file netron tuple
fing network-radar turbo-boost-switcher
firefox nextcloud ultimaker-cura
fission nightowl unetbootin
fl-studio nordvpn uninstallpkg
flash-npapi nosqlbooster-for-mongodb unite
flash-player nova unity
flash-player-debugger novabench unity-android-support-for-editor
flash-player-debugger-npapi nvidia-geforce-now unity-hub
flash-player-debugger-ppapi obsidian unity-ios-support-for-editor
flash-ppapi octoscreen unity-lumin-support-for-editor
fldigi odrive unity-webgl-support-for-editor
flightgear omnidb unity-windows-support-for-editor
flipper omnifocus universal-media-server
flock omnigraffle unnaturalscrollwheels
flutter omnioutliner upic
fme omniplan upwork
font-iosevka omnipresence usb-overdrive
font-iosevka-aile onedrive use-engine
font-iosevka-curly openoffice usenapp
font-iosevka-curly-slab openrct2 uu-booster
font-iosevka-etoile openvanilla v2rayx
font-iosevka-slab openvpn-connect vagrant
font-iosevka-sparkle opera vagrant-vmware-utility
font-iosevka-ss01 opera-gx vanilla
font-iosevka-ss02 orange vassal
font-iosevka-ss03 osxfuse vellum
font-iosevka-ss04 outline vienna
font-iosevka-ss05 overdrive-media-console virtualbox
font-iosevka-ss06 owasp-zap virtualc64
font-iosevka-ss07 pacifist viscosity
font-iosevka-ss08 pagico visual-paradigm
font-iosevka-ss09 panoply visual-paradigm-ce
font-iosevka-ss10 pdf-expert visual-studio
font-iosevka-ss11 pdf-squeezer visual-studio-code
font-iosevka-ss12 pdfsam-basic vitamin-r
font-iosevka-ss13 peakhour vivaldi
font-iosevka-ss14 perimeter81 vrew
font-jetbrains-mono pext vscodium
font-juliamono pgadmin4 vuescan
font-league-gothic photosweeper-x vyprvpn
font-source-sans-pro piezo webcatalog
font-stix plex wechatwork
font-urw-base35 plex-media-server welly
font-xits plexamp whalebird
fontforge pocket-casts whatsapp
fork poedit wickrme
forklift polycom-realpresence wifi-explorer
franz popo winclone
freac portfolioperformance windows95
free-download-manager posterazor wingpersonal
freecad postgres wire
freeplane power-manager wireshark
freetube powerphotos wondershare-filmora
freeyourmusic powershell wondershare-uniconverter
frhelper praat wordpresscom
fsnotes printopia workflowy
futuniuniu pritunl wormhole
garagebuy private-internet-access wrike
garagesale pro-fit xamarin-ios
geany profind xamarin-mac
geekbench propresenter xscope
gemini protonmail-bridge yate
ghidra protonvpn yed
ghost-browser protopie youku
gifox prowritingaid yyets
gitfinder proxifier zalo
github proxyman zeplin
glyphs prudent zipcleaner
gns3 psychopy zoc
go64 publii zoom-for-it-admins
gobdokumente pulse-sms zoomus
golly pycharm-ce-with-anaconda-plugin zotero
goodsync pycharm-with-anaconda-plugin zprint
google-chrome pyfa
==> Deleted Casks
aliwangwang aspera-connect blizz daedalus docear yandexradio zoomin

==> Downloading https://homebrew.bintray.com/bottles/openssl%401.1-1.1.1h.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/4e5357c0cfd55cfa4ef0b632c6fc9f49d39337dd070dc12d3c862e28bd28f079?response-c
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/protobuf-3.13.0_1.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/10df8a94c8077b4d2578e4db9410b586b865e4299cd6e7199993ca1c5a88af97?response-c
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.22.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/b56dd0f401abab4a2dff51706e78b7b7fedb2d4bf747b24e45bbcd4418d13eec?response-c
######################################################################## 100.0%
==> Installing dependencies for mysql: openssl@1.1 and protobuf
==> Installing mysql dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1h.catalina.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs

and run
/usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> Summary
🍺 /usr/local/Cellar/openssl@1.1/1.1.1h: 8,067 files, 18.5MB
==> Installing mysql dependency: protobuf
==> Pouring protobuf-3.13.0_1.catalina.bottle.tar.gz
==> Caveats
Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/protobuf
==> Summary
🍺 /usr/local/Cellar/protobuf/3.13.0_1: 266 files, 19.8MB
==> Installing mysql
==> Pouring mysql-8.0.22.catalina.bottle.tar.gz
==> /usr/local/Cellar/mysql/8.0.22/bin/mysqld --initialize-insecure --user=steven --basedir=/usr/local/Cellar/mysql/8.0.22 --datadir=/
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
mysql -uroot

To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary
🍺 /usr/local/Cellar/mysql/8.0.22: 294 files, 296.5MB
==> Caveats
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs

and run
/usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> protobuf
Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/protobuf
==> mysql
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
mysql -uroot

To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start

~ 

安装成功,其实在上面的日志中,也会看到许多配置的方法,就按照它所提示的方式进行配置

二、配置

  1. 配置环境变量
    直接在命令行输入

    1
    echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

    由于我的mac系统是 ,所以终端默认的是zsh,而不再是bash,所以配置文件是.zshrc,具体参考macOS Catalina下安装nvm、node及每次需要重载配置文件问题解决,

  2. 初始化

    1
    mysql_secure_installation

    提示需要设置密码,设置密码后,继续,报错了:

    1
    Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

    这是环境中安装数据库中经常出现的错误
    解决方案:

    先执行mysql.server start启动一下服务,然后再次执行mysql_secure_installation,重新设置密码
    设置密码的时候,注意密码的强度设置,否则容易失败

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 ~/GitRepository/order   dev 
✔  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc  ✔  175  15:00:39

~/GitRepository/order   dev 
✔  mysql_secure_installation  ✔  177  15:03:56

Securing the MySQL server deployment.

Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

~/GitRepository/order   dev 
↵ 1  mysql.server start  1 ↵  178  15:04:38
Starting MySQL
. SUCCESS!

~/GitRepository/order   dev 
✔  mysql_secure_installation  ✔  179  15:04:56

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
... Failed! Error: Your password does not satisfy the current policy requirements

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
- Dropping test database...
Success.

- Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

三、重启服务

1
mysql.server start
1
2
3
4
5
 ~/GitRepository/order   dev 
✔  mysql.server start  ✔  180  15:12:45
Starting MySQL
SUCCESS!
2020-11-16T07:13:25.6NZ mysqld_safe A mysqld process already exists

至此,安装完毕