mac使用homebrew安装mysql

0.下载软件包管理工具homebrew

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能
Homebrew网站链接
命令行输入homebrew安装命令

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装完成后,在命令行进行验证

$ brew --version
Homebrew 2.0.3
Homebrew/homebrew-core (git revision 4d5e6; last commit 2019-03-06)
Homebrew/homebrew-cask (git revision c2065; last commit 2019-03-07)

这就表示homebrew安装完毕

1.homebrew安装mysql

$ brew install mysql

等待下载安装结束就可以了,

2.启动mysql服务,并修改密码

待上述安装完成之后。命令行启动mysql服务,输入

$ mysql.server start
Starting MySQL
 SUCCESS!

刚刚安装完成的mysql是没有密码的,以用户名root即可进入数据库

$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15 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> show databases;
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.02 sec)

3.修改mysql密码

使用mysql_secure_installation命令

/$ 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:             <----回车
Please set the password for root here.

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) :             <----是否删除test数据库

 ... 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!
/$

密码登录

$ mysql -u root -p
Enter password:

输入密码即可登录

  • 如有不妥,请指示正,谢谢阅读!
    作者:togetlife

猜你喜欢

转载自blog.csdn.net/togetlife/article/details/88407197