最新Mac10.14.6安装MySQL5.7教程

2019-08-18  本文已影响0人  Michaelhbjian

找了一圈的Mac中如何安装mysql的教程,真的还不如官网来的简洁明了。其中包含了安装地址、启动方式、密码、/etc/my.cnf配置文件的介绍、使用mysql需要配置哪些东西都讲的很清楚,目前遇到就这些问题。以后在遇到其他的问题在做添加。

1、安装信息

$ brew install mysql@5.7
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/mysql@5.7-5.7.26.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/81/815ae8aa8c765f57e806ff9197eaa5783b138c493d68333c553b25f441b6af3e?__gda__=exp=1566115290~hmac=87fb7905ec6171d16bdd67f705c5c8f58eb5372623ca6086dfcd74110251
######################################################################## 100.0%
==> Pouring mysql@5.7-5.7.26.mojave.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.26/bin/mysqld --initialize-insecure --user=dxm --basedir=/usr/local/Cellar/mysql@5.7/5.7.26 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> 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

A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

mysql@5.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

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

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


To have launchd start mysql@5.7 now and restart at login:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysql.server start
==> Summary
  /usr/local/Cellar/mysql@5.7/5.7.26: 320 files, 231.8MB
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/dxm/Library/Caches/Homebrew/gettext--0.19.8.1.mojave.bottle.tar.gz... (7.9MB)
Removing: /Users/dxm/Library/Caches/Homebrew/git--2.21.0.mojave.bottle.tar.gz... (16.0MB)
Removing: /Users/dxm/Library/Caches/Homebrew/hugo--0.55.6.mojave.bottle.tar.gz... (19.4MB)
Removing: /usr/local/Cellar/openssl/1.0.2r... (1,795 files, 12.1MB)
Removing: /Users/dxm/Library/Caches/Homebrew/openssl--1.0.2r.mojave.bottle.tar.gz... (3.7MB)
Removing: /Users/dxm/Library/Caches/Homebrew/postgresql--11.3.mojave.bottle.tar.gz... (10MB)
Removing: /Users/dxm/Library/Logs/Homebrew/scala... (64B)
Removing: /Users/dxm/Library/Logs/Homebrew/zsh-syntax-highlighting... (64B)
Pruned 0 symbolic links and 3 directories from /usr/local

2、mysql_secure_installation的配置

# dxm @ baidudeMacBook-Pro-29 in /usr/local/Cellar/mysql@5.7/5.7.26/bin [17:42:44] C:127
$ sudo ./mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN 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 plugin?

Press y|Y for Yes, any other key for No:
Please set the password for root here.

New password:

Re-enter new password:
Sorry, passwords do not match.

New password:

Re-enter new password:
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) :

 ... skipping.


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) :

 ... skipping.
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) :

 ... skipping.
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) :

 ... skipping.
All done!

3、配置环境变量以及启动方式

echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
brew services start mysql@5.7
image.png

4、错误信息排查

如碰下下面错误问题可以参考相应的链接:
问题1:

mac Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

https://stackoverflow.com/questions/15450091/for-a-newbie-error-2002-hy000-cant-connect-to-local-mysql-server-through-so

问题2:

$ mysql -uroot
zsh: no such file or directory: /usr/local/mysql/bin/mysql

进入到/usr/local/Cellar/mysql@5.7/5.7.26/bin这个目录下执行下图的命令:

image.png
上一篇下一篇

猜你喜欢

热点阅读