工作生活

mac os 安装 MySQL

2019-07-03  本文已影响0人  陈嘻嘻啊
mysql

业务需要最近需要用nodejs爬数据,并把数据存储在数据库。于是选择了mysql,在官网一顿下载,搞了半天没下载下来。 学习到一种快速便捷的方式。 homebrew 是个不错的工具

1. 使用Homebrew进行安装

homebrew 是一款 Mac OS 平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷.

下载 homebrew 复制以下代码复制以下代码直接在终端回车执行即可;如果已有homebrew请忽略。

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

2. 安装mysql

  brew install mysql
......
==> 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

3. mysql 初始化

  mysql_secure_installation

可能会出现这样的问题

Securing the MySQL server deployment.

Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

先执行一下 mysql.server start 然后再执行 mysql_secure_installation 即可

4. All done!

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: N
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) : 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) : y
 - 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!

5. mysql

  # 登录mysql
  mysql -u root -p
  # 然后输入密码,我的密码是123456
  123456
  # 退出mysql
  exit
  # 启动mysql
  brew services start mysql
  # 停止mysql
  brew services stop mysql
  # mysql 8.0 修改密码
  ALTER user 'root'@'localhost' IDENTIFIED BY '111111';

好了什么都不说了,我要去撸*了😊

雅蠛蝶

报错1: MYSQL:ER_NOT_SUPPORTED_AUTH_MODE:Client does not support authentication protocol

报错2:[解决MySQL8.0报错:Unknown system variable 'validate_password_policy'](https://www.bbsmax.com/A/ke5j2ml95r/

)

上一篇下一篇

猜你喜欢

热点阅读