MySQL Install Tutorial

41 阅读1分钟

MySQL Install Tutorial

特此声明,未经授权不得转载

www.sjkjc.com/mysql/

1 安装

MacOS 安装MySQL

仅需执行

brew install mysql

即可完成MySQL的安装,安装好的提示

==> mysql
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -u root

To start mysql now and restart at login:
  brew services start mysql
==> redis
To start redis now and restart at login:
  brew services start redis  

2 启动

MySQL分为服务端和客户端,刚才安装好的是服务端,客户端不需额外安装

启动服务端

在一个命令行窗口

➜  ~ brew services start mysql
==> Successfully started `mysql` (label: homebrew.mxcl.mysql

MySQL服务端就启动了,它是一个在后台运行的项目

启动客户端

在另一个命令行窗口

➜  ~ mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 Homebrew

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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 database显示当前服务器的所有数据库,系统会自动创建一些数据库?因为从我下载以后没有进行过多余的操作

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>

提示:一定是先启动服务端再启动客户端,否则提示

➜  ~ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

3 关闭

关闭服务端

➜  ~ brew services stop mysql
Stopping `mysql`... (might take a while)
==> Successfully stopped `mysql` (label: homebrew.mxcl.mysql)
➜  ~

关闭客户端不需要特殊命令

直接control+Z暴力杀死进程退出即可