一、Mac下安装&连接mysql
1、下载
MySQL :: Download MySQL Community Server
进入下载页面,选择对应的版本,mac上选择第一个,dmg安装包即可
2、安装
下载后,双击打开,按提示下一步安装完成
command+空格,输入mysql,点击设置中的mysql,如下所示:
出现如下页面,表示安装成功
3、启动、停止mysql服务
点击上图中的Start MySQL Server,启动服务
服务启动后,按钮变成Stop MySQL Server,点击,停止服务
4、连接
1、使用mysql 可视化工具,比如MySQL Workbench、navicat
2、使用命令行连接
安装后直接输入mysql命令,提示zsh: command not found: mysql
需要将mysql 安装路径加到系统变量中
(1).打开.bash_profile 文件
open -e ~/.bash_profile
(2)将mysql路径添加进去
export PATH=${PATH}:/usr/local/mysql/bin
(3)配置立即生效
source ~/.bash_profile
(4) 连接
mysql -h xxx -u root -p
输入密码
-h xxx 可以省略,如果是本机,可以输入localhost或者127.0.0.1
wyl@WYLdeMacBook-Air bin % mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.3.0 MySQL Community Server - GPL
Copyright (c) 2000, 2024, 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>
二、linux 下连接mysql
1、连接前,查看下mysql服务是否启动: ps -ef | grep mysql
2、连接:mysql -u 用户名 -p 回车,然后输入密码
如果提示:Access denied for user 'beta'@'localhost' (using password: YES),表示账号权限不够
三、启动停止
service mysql(d) start/stop/restart
systemctl mysql(d) start/stop/restart
启动/停止/重启
mysql或者mysqld
systemctl status mysql(d)
查看mysql 启动状态
[root@VM-100-3-centos ~]# service mysqld stop
Redirecting to /bin/systemctl stop mysqld.service
[root@VM-100-3-centos ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Sun 2024-02-18 09:07:07 CST; 2s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 22874 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 22845 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 22874 (code=exited, status=0/SUCCESS)
Status: "Server shutdown complete"
Feb 18 09:06:48 VM-100-3-centos systemd[1]: Starting MySQL Server...
Feb 18 09:06:48 VM-100-3-centos systemd[1]: Started MySQL Server.
Feb 18 09:07:06 VM-100-3-centos systemd[1]: Stopping MySQL Server...
Feb 18 09:07:07 VM-100-3-centos systemd[1]: Stopped MySQL Server.
[root@VM-100-3-centos ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@VM-100-3-centos ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2024-02-18 09:01:43 CST; 51s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 21275 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 21303 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─21303 /usr/sbin/mysqld
Feb 18 09:01:42 VM-100-3-centos systemd[1]: Starting MySQL Server...
Feb 18 09:01:43 VM-100-3-centos systemd[1]: Started MySQL Server.
四、查看版本
连接mysql,输入:
1、status;
2、select version();
mysql> status;
--------------
mysql Ver 8.0.32 for Linux on x86_64 (MySQL Community Server - GPL)
Connection id: 8
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.32 MySQL Community Server - GPL
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/lib/mysql/mysql.sock
Binary data as: Hexadecimal
Uptime: 19 sec
Threads: 2 Questions: 5 Slow queries: 0 Opens: 119 Flush tables: 3 Open tables: 38 Queries per second avg: 0.263
--------------
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.32 |
+-----------+
1 row in set (0.00 sec)