本文是Mac配置系列之一:MAC下MYSQL8的安装配置。用来记录MySQL的安装配置,流水账,记录备查。
强烈建议使用Homebrew进行安装,轻松加愉快,否则各种依赖的坑必须再趟一遍,没有必要。具体安装过程如下:
george@GeorgeMBP ~ brew install mysql
==> Installing dependencies for mysql: openssl
==> Installing mysql dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2s.mojave.bottl
==> Downloading from https://akamai.bintray.com/c4/c4a762d719c2be74ac686f1aafabb
######################################################################## 100.0%
==> Pouring openssl-1.0.2s.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
==> Summary
🍺 /usr/local/Cellar/openssl/1.0.2s: 1,795 files, 12.0MB
==> Installing mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.16.mojave.bottle.
==> Downloading from https://akamai.bintray.com/65/65e6629740ca75ceaae575b4cc68f
######################################################################## 100.0%
==> Pouring mysql-8.0.16.mojave.bottle.tar.gz
==> /usr/local/Cellar/mysql/8.0.16/bin/mysqld --initialize-insecure --user=george --basedir=/usr/local/Cellar/mysql/8.0.16 --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
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.16: 275 files, 269.8MB
==> Caveats
==> openssl
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
==> 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
george@GeorgeMBP ~
以上,MySQL就安装好了,重点看看安装成功的后的提示,进行用户密码和权限的设置。
启动及查看进程:
george@GeorgeMBP ~ mysql.server start
Starting MySQL
. SUCCESS!
george@GeorgeMBP ~
✘ george@GeorgeMBP ~ ps -ef | grep mysql
501 10850 10846 0 11:55上午 ?? 0:00.15 /usr/bin/ssh -n -N -v -lsimuser -L50639:rm-uf672yzo3c5l1n0y3.mysql.rds.aliyuncs.com:3306 -p22 47.103.35.122 -oPreferredAuthentications password,keyboard-interactive -oNumberOfPasswordPrompts 1
501 14225 10846 0 3:40下午 ?? 0:00.04 /usr/bin/ssh -n -N -v -lroot -L52503:rm-uf6yw866b6z8mu197.mysql.rds.aliyuncs.com:3306 -p22 47.103.35.122 -oPreferredAuthentications password,keyboard-interactive -oNumberOfPasswordPrompts 1
501 15300 1 0 3:58下午 ttys001 0:00.02 /bin/sh /usr/local/Cellar/mysql/8.0.16/bin/mysqld_safe --datadir=/usr/local/var/mysql --pid-file=/usr/local/var/mysql/GeorgeMBP.pid
501 15400 15300 0 3:58下午 ttys001 0:01.47 /usr/local/Cellar/mysql/8.0.16/bin/mysqld --basedir=/usr/local/Cellar/mysql/8.0.16 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/8.0.16/lib/plugin --log-error=GeorgeMBP.err --pid-file=/usr/local/var/mysql/GeorgeMBP.pid
501 15446 14298 0 3:59下午 ttys001 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mysql
george@GeorgeMBP ~
下面设置跟用户密码:
george@GeorgeMBP ~ mysql_secure_installation
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: 1
Please set the password for root here.
New password:
Re-enter new password:
Estimated strength of the password: 100
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) : n
... 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) : n
... 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) : y
Success.
All done!
george@GeorgeMBP ~
george@GeorgeMBP ~ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.16 Homebrew
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)
mysql> exit;
Bye
george@GeorgeMBP ~ mysql.server stop
Shutting down MySQL
... SUCCESS!
george@GeorgeMBP ~
使用Navcat客户端链接的时候,弹出一个错误(Client does not support authentication protocol requested by server),需要设置一下。下面设置客户端链接权限:
george@GeorgeMBP ~ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.16 Homebrew
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql>
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '12345678';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> exit;
Bye
以上,客户端可以连接MySQL服务器了。