Mac安装MySQL+初始配置


作者:夕夕石(硕爷)


原文网址:https://blog.csdn.net/liuxy_236/article/details/90408253

一、安装mysql

brew install mysql
[mtdp@shuoDeMBP:py01]$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.18.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/0b/0bddb035ea8098a4eb0a9d76afae97a077f517bdb0592a4edae828a566470236?__gda__=exp=1574908733~hmac=ddd6c186284d
#####################################################                     73.9%
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
######################################################################## 100.0%
==> Pouring mysql-8.0.18.mojave.bottle.tar.gz
==> /usr/local/Cellar/mysql/8.0.18/bin/mysqld --initialize-insecure --user=mtdp --basedir=/usr/local/Cellar/mysql/8.0.18 --datadir=/usr/local/var/mysql --tm
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation // 注意这句,说现在mysql没有密码,如果创建密码,需要输入:mysql_secure_installation 

MySQL is configured to only allow connections from localhost by default // mysql现在只允许本地访问,不允许远程访问

To connect run:
    mysql -uroot // 要想进入mysql,需要运行:mysql -uroot

To 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服务
==> Summary
🍺  /usr/local/Cellar/mysql/8.0.18: 293 files, 280.9MB
[mtdp@shuoDeMBP:py01]$

二、如果需要创建密码

任意路径执行命令:mysql_secure_installation,交互过程中不断输入y或者n

Securing the MySQL server deployment.

 

Connecting to MySQL using a blank password.

 

VALIDATE PASSWORD COMPONENT 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 component?

 

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          // 输入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      // 不接受root远程登录账号?输入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     // 删除text数据库?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 // 输入y,代表重新加载配置过的特权

Success.

 

All done!

三、控制mysql命令

1、启动mysql服务

mysql.server start
[mtdp@shuoDeMBP:py01]$ mysql.server start
Starting MySQL
. SUCCESS!
[mtdp@shuoDeMBP:py01]$

2、停止mysql服务

mysql.server stop
[mtdp@shuoDeMBP:py01]$ mysql.server stop
Shutting down MySQL
. SUCCESS!
[mtdp@shuoDeMBP:py01]$

3、查看mysql服务状态

mysql.server status
[mtdp@shuoDeMBP:py01]$ mysql.server status
 ERROR! MySQL is not running
[mtdp@shuoDeMBP:py01]$

4、进入mysql

无密码的情况下:

mysql -uroot
[mtdp@shuoDeMBP:py01]$ mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 Homebrew

Copyright (c) 2000, 2019, 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> 

5、允许远程登录

进入mysql后输入:

use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

其中'password'指的是你root账号的密码,如果为空,就写'',即空。

之后再去navicat连接,就会成功

6、退出mysql

mysql> \q
Bye
[mtdp@shuoDeMBP:py01]$

作者:夕夕石(硕爷)


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,839评论 6 482
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,543评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 153,116评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,371评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,384评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,111评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,416评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,053评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,558评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,007评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,117评论 1 334
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,756评论 4 324
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,324评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,315评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,539评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,578评论 2 355
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,877评论 2 345

推荐阅读更多精彩内容