MySQL Mac 安装与简单配置

本文最后更新于:2021年1月6日 晚上

homebrew安装mysql

使用brew命令安装mysql

1
mb:~ rustfisher$ brew install mysql

启动停止mysql服务

启动服务 mysql.server start
安装时没有设置密码,可以直接mysql -uroot登入。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
mb:~ rustfisher$ mysql.server start
Starting MySQL
. SUCCESS!

mb:~ rustfisher$ mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.12 Homebrew

Copyright (c) 2000, 2018, 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> exit;
Bye

输入mysql指令遇到错误

1
2
mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1

指令输入错误,修正一下

1
2
3
4
5
6
7
8
9
10
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)

停止mysql服务的命令 mysql.server stop

1
2
3
mb:anindexserver rustfisher$ mysql.server stop
Shutting down MySQL
... SUCCESS!

简单操作

更改密码

1
2
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpwd';
Query OK, 0 rows affected (0.05 sec)

设定了密码后,登录需要输入密码

1
2
3
4
mb:anindexserver rustfisher$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.

参考:

可视化工具 mysql workbench

官方文档请参考 https://dev.mysql.com/downloads/workbench/

mysql workbench 需要primary key

需要有primary key才能编辑内容

https://stackoverflow.com/questions/10815029/mysql-workbench-edit-table-data-is-read-only

配置文件

mac中配置文件默认路径为 /usr/local/etc/my.cnf

可以修改port。

1
2
3
4
5
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
port=9527
bind-address = 127.0.0.1

这里限制了连接的端口。

参考: https://www.cyberciti.biz/faq/change-default-mysql-port-under-linuxunix/


MySQL Mac 安装与简单配置
https://blog.rustfisher.com/2019/02/26/Database/MySQL-install_and_config_Mac/
作者
Rust Fisher
发布于
2019年2月26日
许可协议