1、先查找下mysql
➜ ~ brew search mysql
automysqlbackup mysql-cluster mysql-sandbox
mysql mysql-connector-c mysql-search-replace
mysql++ mysql-connector-c++ mysqltuner
homebrew/php/php53-mysqlnd_ms homebrew/versions/mysql56
homebrew/php/php54-mysqlnd_ms Caskroom/cask/mysql-connector-python
homebrew/php/php55-mysqlnd_ms Caskroom/cask/mysqlworkbench
homebrew/php/php56-mysqlnd_ms Caskroom/cask/navicat-for-mysql
homebrew/versions/mysql55 Caskroom/cask/sqlpro-for-mysql
2、看一下mysql的版本信息
➜ ~ brew info mysql
mysql: stable 5.7.16 (bottled)
Open source relational database management system
# 下面信息省略
下面就用brew install mysql安装下吧,安装时的消息有这么一句话We’ve installed your MySQL database without a root password. To secure it run:mysql_secure_installation,那就来设置下root的密码
安装后直接在命令行输入mysql会提示mysql: command not found,需要先将其添加到环境变量:
vim ~/.bash_profile
添加以下指令:
export PATH=${PATH}:/usr/local/Cellar/mysql/5.7.18_1/bin
保存后立即使其生效:
source ~/.bash_profile
# 第一步:打开mysql服务
mysql.server start
# 第二步:执行mysql_secure_installation
mysql_secure_installation # 执行后按照提示信息进行设置,慢慢看下英文,都能看懂的
如果中间出现错误
Your password does not satisfy the current policy requirements
则是密码太过简单导致的
默认是要求: 8位以上、大小写字母、特殊字符的
我这里设置的密码是 Liuming@8023
接下来设置可以参照
cometdeMacBook-Pro:~ comet$ mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN 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 plugin?
Press y|Y for Yes, any other key for No: N // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
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!
好了,进入mysql看下
~ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.16 Homebrew
Copyright (c) 2000, 2016, 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.00 sec)
mysql>
输入exit 退出