当前位置:首页 > 操作系统 > MacOs

Mac 安装MySQL(Homebrew)

Mac 安装MySQL(Homebrew)

一、安装

安装Homebrew

参见: Mac安装Homebrew

1、执行安装命令
<code>brew install mysql
</code>
<code>localhost:~ local$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.6.26.yosemite.bottle.1.tar.gz
Already downloaded: /Library/Caches/Homebrew/mysql-5.6.26.yosemite.bottle.1.tar.gz
==> Pouring mysql-5.6.26.yosemite.bottle.1.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
</code>
2、启动mysql
<code>mysql.server start
</code>
2.1、首次连接:
<code> mysql -uroot
</code>
3、停止mysql
<code>mysql.server stop
</code>
4、修改root密码:
<code>/usr/local/bin/mysqladmin -u root password 1234567890(root的新密码)
# /usr/local/bin/mysqladmin -> ../Cellar/mysql/8.0.19_1/bin/mysqladmin
</code>
5、执行安全设置
<code>mysql_secure_installation
</code>

显示如下

<code>There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file
</code>

按照提示选择密码等级,并设置root密码

二、创建新的数据库、用户并授权

1、登录mysql
<code>mysql -u root -p
</code>
按提示输入root密码
<code>local:~# mysql -u root -p
Enter password: 
</code>
2、创建数据库
<code>CREATE DATABASE IF NOT EXISTS `allinone` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
</code>
3、创建用户
<code>create user ‘adminuser‘@‘%‘ identified by ‘test2020‘;
</code>
4、授权用户
<code>grant all privileges on allinone.* to ‘adminuser‘@‘%‘;
</code>
<code>flush privileges;
</code>
5、查看数据库列表
<code>show databases;
</code>
6、切换数据库;
<code>use allinone;  # allinone 为数据库名称
</code>
7、显示当前数据库所有的表
<code>show tables
</code>

三、建表

<code>CREATE TABLE `xmind2chandaocase` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` int(11) NOT NULL COMMENT ‘上传xmind文件进行解析:upload=1;
从禅道导出未xmind用例:export=2;‘,
  `fire_time` datetime NOT NULL,
  `ip` varchar(18) NOT NULL,
  `mac` varchar(48) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
</code>

四、检查mysql状态

<code>local % mysql.server status
 SUCCESS! MySQL running (60677)
local % mysql.server stop  
Shutting down MySQL
.. SUCCESS! 
local % mysql.server status
 ERROR! MySQL is not running
local % mysql.server start            
Starting MySQL
. SUCCESS! 
local % mysql.server status
 SUCCESS! MySQL running (60992)
local % 
</code>

Mac 安装MySQL(Homebrew)

标签:修改   download   etc   nod   安全   another   ODB   usr   名称   

本文系统来源:https://www.cnblogs.com/haojile/p/13193861.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐