Mac 安装MySQL(Homebrew)

tangjianft 2020-06-26

Mac 安装MySQL(Homebrew)

一、安装

安装Homebrew

参见: Mac安装Homebrew

1、执行安装命令
brew install mysql
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.
2、启动mysql
mysql.server start
2.1、首次连接:
mysql -uroot
3、停止mysql
mysql.server stop
4、修改root密码:
/usr/local/bin/mysqladmin -u root password 1234567890(root的新密码)
# /usr/local/bin/mysqladmin -> ../Cellar/mysql/8.0.19_1/bin/mysqladmin
5、执行安全设置
mysql_secure_installation

显示如下

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

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

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

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

三、建表

CREATE TABLE `xmind2chandaocase` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` int(11) NOT NULL COMMENT ‘上传xmind文件进行解析:upload=1;\n从禅道导出未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;

四、检查mysql状态

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 %

相关推荐