作者:夕夕石(硕爷)
原文网址: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]$
作者:夕夕石(硕爷)