Mac 使用Homebrew 安装mysql (如果不知道如何使用Homebrew 请参照链接)
steve@bogon ~ % brew install mysql
==> **Downloading https://homebrew.bintray.com/bottles/openssl%401.1-1.1.1g.catali**
==> **Downloading from https://akamai.bintray.com/19/1926679569c6af5337de812d86f4d**
\######################################################################## 100.0%
==> **Downloading https://homebrew.bintray.com/bottles/protobuf-3.12.3.catalina.bo**
==> **Downloading from https://akamai.bintray.com/3c/3ced83651f35574357814e547e6d8**
\######################################################################## 100.0%
==> **Downloading https://homebrew.bintray.com/bottles/mysql-8.0.19_1.catalina.bot**
==> **Downloading from https://akamai.bintray.com/e5/e5a5455d254260e9ca9821cb9c5e9**
\######################################################################## 100.0%
==> **Installing dependencies for mysql:** **openssl@1.1** **and** **protobuf**
==> **Installing mysql dependency:** **openssl@1.1**
==> **Pouring openssl@1.1-1.1.1g.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.1g: 8,059 files, 18MB
==> **Installing mysql dependency:** **protobuf**
==> **Pouring protobuf-3.12.3.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.12.3: 267 files, 19.8MB
==> **Installing** **mysql**
==> **Pouring mysql-8.0.19_1.catalina.bottle.tar.gz**
==> **/usr/local/Cellar/mysql/8.0.19_1/bin/mysqld --initialize-insecure --user=ste**
==> **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_1: 286 files, 288.8MB
==> **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
启动mysql
mysql.server start
Starting MySQL
.. SUCCESS!
添加密码及安全设置
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: 0 //密码验证策略等级 建议选择0
Please set the password for root here.
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 // 确认是否继续使用提供的密码?输入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 // 允许root远程登录
... 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) : y // 移除test数据库
\- 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!
MySql8.0 版本和 5.0 的加密规则不一样,有的可视化工具可能不支持,所以推荐使用Navicat;也可以使用一下命令修改加密规则。所以设置远程登录的权限
mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.01 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
如果不设置远程登录那么将会出现如下错误
1045 - Access denied for user 'root'@'localhost' (using password:YES)
![截屏2020-07-07 下午9.56.49.png](https://img.haomeiwen.com/i15063932/5f6916596ac3edad.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
网上有些人说的是什么密码错误,我也是醉了,明显是误人子弟
设置远程登录之后就能连接成功了
截屏2020-07-07 下午9.56.49.png如果真的忘记了自己的密码这么办
1.打开终端,进入mysql的bin目录下:/usr/local/Cellar/mysql/8.0.19_1/bin
2.输入:mysqld --skip-grant-tables (跳过密码检测)
3.原窗口不关闭,新打开一个,转入mysql的bin目录下
4.输入:mysql -u root
5.刷新权限 FLUSH PRIVILEGES
6.修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword' PASSWORD EXPIRE NEVER;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
7.退出mysql重新登录
8.mysql -u root -p 输入刚刚更新的 密码,登录成功
网友评论