自由屋推书网—热门的小说推荐平台!

你的位置: 首页 > mysql

Mac电脑使用brew下载mysql并启动

2022-05-21 09:34:19

1.搜索mysql版本

brew search mysql 搜索一下版本,看一下自己要下载的版本。然后我下载的是mysql@5.7。

2.安装mysql

brew install mysql@5.7

3.环境变量配置

安装成功后brew会给配置环境变量的提示

在这里插入图片描述

在终端执行环境变量配置:

echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"
export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"

如果要永久生效,就把下边两个export写到~/.bash_profile文件中

4.启动服务

brew services start mysql@5.7

在这里插入图片描述

5.设置密码

总结:
1.启动服务
2.执行安全配置
3.删除匿名帐号,放开远程连接,删除test测试库,重新加载权限表
4.测试连接

//输入命令
DIDI-C02G17HXQ05P:~ didi$ 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: yes//输入yes表示设置密码

There are three levels of password validation policy:

//提示密码强度为 low、medium、strong 低中高三种
LOWLength >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionaryfile

//输入自己想要设置的密码强度等级
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

//新密码(输入不可见)
New password:Qian123@@@
//再次确认
Re-enter new password: Qian123@@@

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.

//是否删除匿名用户,y表示yes 其他表示no(百度建议删除:在mysql刚刚被安装后,存在用户名、密码为空的用户。这使得数据库服务器有无需密码被登录的可能性。为消除隐患,将匿名用户删除。)
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!

//测试数据库连接,输入命令mysql -uroot -p后输入设置的密码
DIDI-C02G17HXQ05P:~ didi$ 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.28 Homebrew

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql|
| performance_schema |
| sys|
+--------------------+
4 rows in set (0.00 sec)

至此mysql安装成功,在系统中存在mysql。

编辑推荐

热门小说