安装Mysql
$ brew install mysql
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
bootloadhid rcm tanka
==> Updated Formulae
benthos mlpack s-nail thors-serializer
file-roller mu sispmctl
lazygit nift src
libuv robotfindskitten sslmate
==> Installing dependencies for mysql: [email protected] and protobuf
==> Installing mysql dependency: [email protected]
==> Downloading https://homebrew.bintray.com/bottles/[email protected]
==> Downloading from https://akamai.bintray.com/72/724cd97c269952cdc28e24798e350
######################################################################## 100.0%
==> Pouring [email protected]
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/[email protected]/certs
and run
/usr/local/opt/[email protected]/bin/c_rehash
[email protected] is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.
If you need to have [email protected] first in your PATH run:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
==> Summary
/usr/local/Cellar/[email protected]/1.1.1f: 8,057 files, 18MB
==> Installing mysql dependency: protobuf
==> Downloading https://homebrew.bintray.com/bottles/protobuf-3.11.4.catalina.bo
==> Downloading from https://akamai.bintray.com/b6/b6eca888405b4998b1a5be7c7425d
######################################################################## 100.0%
==> Pouring protobuf-3.11.4.catalina.bottle.tar.gz
/usr/local/Cellar/protobuf/3.11.4: 268 files, 19.6MB
==> Installing mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.19.catalina.bottl
==> Downloading from https://akamai.bintray.com/22/22e86de2d5b0b2bfd7c1157c2bb36
######################################################################## 100.0%
==> Pouring mysql-8.0.19.catalina.bottle.2.tar.gz
==> /usr/local/Cellar/mysql/8.0.19/bin/mysqld --initialize-insecure --user=lucki
==> 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.19: 286 files, 289.2MB
==> Caveats
==> [email protected]
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/[email protected]/certs
and run
/usr/local/opt/[email protected]/bin/c_rehash
[email protected] is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.
If you need to have [email protected] first in your PATH run:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile
For compilers to find [email protected] you may need to set:
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/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
启动Mysql
$ mysql.server start
Starting MySQL
... SUCCESS!
创建用户
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.19 Homebrew
Copyright (c) 2000, 2020, 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> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> create user 'smilecc'@'%' identified by '1234321' ;
Query OK, 0 rows affected (0.03 sec)
没权限 给权限
mysql> show grants for 'smilecc'@'%';
+-------------------------------------+
| Grants for smilecc@% |
+-------------------------------------+
| GRANT USAGE ON *.* TO `smilecc`@`%` |
+-------------------------------------+
1 row in set (0.01 sec)
mysql> grant all privileges on *.* to "smilecc"@'%';
Query OK, 0 rows affected (0.02 sec)
Sequel Pro连接报错
mysql> alter user 'smilecc'@'%' identified with mysql_native_password by '1234321';
Query OK, 0 rows affected (0.01 sec)
mysql> select host, user, plugin from user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | smilecc | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
5 rows in set (0.00 sec)
总算连接了,看看vapor可以连接不。
项目报错 [ ERROR ] handshakeFailed(NIOSSL.BoringSSLError.sslError([Error: 268435581 error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED]))
各种查 各种翻 最后在vapor issue 里面找到解决办法
mysql> show variables like '%ssl%';
+--------------------+-----------------+
| Variable_name | Value |
+--------------------+-----------------+
| have_openssl | YES |
| have_ssl | YES |
| mysqlx_ssl_ca | |
| mysqlx_ssl_capath | |
| mysqlx_ssl_cert | |
| mysqlx_ssl_cipher | |
| mysqlx_ssl_crl | |
| mysqlx_ssl_crlpath | |
| mysqlx_ssl_key | |
| ssl_ca | ca.pem |
| ssl_capath | |
| ssl_cert | server-cert.pem |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_fips_mode | OFF |
| ssl_key | server-key.pem |
+--------------------+-----------------+
17 rows in set (0.00 sec)
% cd /etc
% sudo vim my.cnf
添加
[mysqld]
skip_ssl
保存
% mysql.server restart
Shutting down MySQL
.... SUCCESS!
Starting MySQL
.. SUCCESS!
重启项目 再次尝试总算连上mysql
但是!
报错 [ ERROR ] MySQL error: Unknown protocol error
应该是哪里代码写错了! 再说吧 再说吧 脑壳痛。
2020-4-29 更新
查来查去,发现vapor不支持mysql8
删了mysql8 安装一个[email protected]就可以跑了
而且ssl问题 代码也可以设置nil 哎~~
app.databases.use(.mysql(
hostname: "127.0.0.1",
username: "smilecc",
password: "1234321",
database: "vapor",
tlsConfiguration: nil
), as: .mysql)