安装MySQL

通过Homebrew安装,执行brew install mysql即可。

安装完成后会显示Caveats 警告,如下所示:

We've installed your MySQL database without a root password. To secure it run:mysql_secure_installationMySQL is configured to only allow connections from localhost by defaultTo connect run:mysql -urootTo 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_secure_installation

使用brew命令安装完mysql后,根据提示我们可以知道当前root是没有密码的,我们可以通过执行mysql_secure_installation命令来进行安全设置。

同时这种方法也同样可以用来解决使用mysql -u root -p登录时的Access denied 问题。

首先执行命令mysql_secure_installation,会出现如下的错误:

Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

当前/tmp/ 目录下并没有mysql.sock这个文件,它在mysql服务启动时才会创建,所以需要提前执行mysql.server start 命令。提示如下:

Starting MySQL
. SUCCESS!

这时候就可以正常执行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: y

选择密码规则

There are three levels of password validation policy:LOW    Length >= 8
#长度大于等于8
MEDIUM Length >= 8, numeric, mixed case, and special characters
#长度大于等于8,数字、大小写字母、特殊符号
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file
#长度大于等于8,数字、大小写字母、特殊符号和字典文件(慎选!)Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
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

删除匿名用户

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) : y
Success.

删除测试数据表

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.

Done

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 -u root -p进行密码链接了。

可能会出现的问题

Your password does not satisfy the current policy requirements.

如果你在选择密码规则的时候不小心选择了2,也就是数字、大小写字母、特殊符号和字典文件的组合。这时候设置密码会出现如下提示:

Your password does not satisfy the current policy requirements.

这时候重新运行mysql_secure_installation也不会再给你机会重新设置了。手动微笑,mmp。

解决方案如下:

使用命令mysql -uroot登陆,执行:

set global validate_password_policy=0;
#将密码规则设置为LOW,就可以使用纯数字纯字母密码

LOW强度下密码位数的最低要求为8位,如果你想用诸如123456这类的密码,执行:

set global validate_password_length=4;
#最低位数为4位

这个时候重新运行mysql_secure_installation就可以安心设置了。

相关参数

validate_password_dictionary_file:插件用于验证密码强度的字典文件路径。validate_password_length:密码最小长度。validate_password_mixed_case_count:密码至少要包含的小写字母个数和大写字母个数。validate_password_number_count:密码至少要包含的数字个数。validate_password_policy:密码强度检查等级,0/LOW、1/MEDIUM、2/STRONG。validate_password_special_char_count:密码至少要包含的特殊字符数。

MySQL安全设置命令mysql_secure_installation相关推荐

  1. mysql的设置更改root密码、连接、常用命令

    13.1 设置更改root密码 更改环境变量PATH ,增加mysql绝对路径 首次直接使用mysql会提示'该命令不存在',原因是还没有将该命令加入环境变量,如果要使用该命令,需要使用其绝对路径:/ ...

  2. mysql快捷键设置_MySQL快捷命令

    下表列出了各个提示符并简述它们所表示的mysql的状态: 提示符 含义 mysql> 准备好接受新命令. -> 等待多行命令的下一行. '> 等待下一行,等待以单引号("' ...

  3. vba mysql 没有为命令对象设置命令_怎样解决“没有为命令对象设置命令”的错误? - .Net论坛 - 51CTO技术论坛_中国领先的IT技术社区...

    复制内容到剪贴板 代码:Private Sub dataQuery_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) H ...

  4. MySQL数据库相关命令

    MySQL数据库 1.MySQL导出命令 mysqldump -h IP -u 用户名 -p 数据库名 > 导出的文件名 注:mysqldump命令是在cmd窗口初始目录下的命令,不是进入mys ...

  5. MySQL 数据库常用命令—where like union 排序 分组 连接

    引言 本篇博客对 MySQL 数据库的一些命令进行分享. where 语句 基本语法规则: select field1, field2,...fieldN from table_name1, tabl ...

  6. 【网站建设】Linux上安装MySQL - 12条命令搞定MySql

    从零开始安装mysql数据库 : 按照该顺序执行 :  a. 查看是否安装有mysql:yum list installed mysql*, 如果有先卸载掉, 然后在进行安装; b. 安装mysql客 ...

  7. MySQL 数据库常用命令小结

    MySQL 数据库常用命令 1.MySQL常用命令 create database name; 创建数据库 use databasename; 选择数据库 drop database name 直接删 ...

  8. mysql 配置文件设置最大链接数 max_connections不生效

    mysql 配置文件设置最大链接数 max_connections不生效 文章目录 mysql 配置文件设置最大链接数 max_connections不生效 参考链接 1.临时设置最大链接数为1000 ...

  9. php mysql修改命令_PHP编程:mysql alter table命令修改表结构实例详解

    <PHP编程:mysql alter table命令修改表结构实例详解>要点: 本文介绍了PHP编程:mysql alter table命令修改表结构实例详解,希望对您有用.如果有疑问,可 ...

最新文章

  1. Android问题-DelphiXE5编义时提示找不到“连接器(arm-linux-androideabi-ld.exe)
  2. python 引用传递和值传递(实参,形参)
  3. 汇编中的字符串操作指令
  4. 【联盟】三星大容量MLC FLASH 换代信息(小心现在自己计划的产品哦)
  5. java如何保证类不被回收_垃圾回收机制保证了Java程序不会出现内存溢出。( )
  6. 如何下载百度文库文章
  7. C#中使用ribbon界面
  8. 实现写邮箱html页面,HTML写的第一个邮箱登陆界面
  9. nanomsg接口函数以及功能列举大全
  10. 系统设计.如何设计一个秒杀系统(完整版)
  11. PS使用:利用PS去除图片中的多余文字
  12. 千兆网线交叉线接法(有图)
  13. Java SE第10章 异常处理
  14. html与css编程证书,利用CSS布局做一个简单的荣誉证书(代码示例)
  15. excel快速把公式应用到一整列
  16. 个税继续教育证书有哪些 计算机,个税专项附加扣除中继续教育哪些证书可以扣除呢?...
  17. 哈工大软件构造Lab2
  18. 智能语音交互:阿里的研究和实践
  19. 厦门感恩回馈一线职工 为其开启“新年旅程”
  20. html5 java 实现微信公众号自动分享功能(自定义文案和图标)

热门文章

  1. 《数学建模:基于R》——1.1 数据的描述性分析
  2. Linux日志系统小记
  3. LNMT/LAMT实现动静分离、负载均衡和会话保持
  4. react-native ListView 封装 实现 下拉刷新/上拉加载更多
  5. codevs——1742 爬楼梯
  6. 【bzoj2281】[Sdoi2011]黑白棋
  7. Sqli-labs less 40
  8. iptables 开启3306端口
  9. 创意十足!25个服饰行业的网站设计作品
  10. 上一季诺基亚销售下跌28%