手动启动mysql 服务
打开终端
***@huahuapro ~ % mysql --version
zsh: command not found: mysql
***@huahuapro ~ % PATH="$PATH":/usr/local/mysql/bin
***@huahuapro ~ % mysql --version
mysql Ver 8.0.27 for macos11 on arm64 (MySQL Community Server - GPL)
***@huahuapro ~ % mysql -uroot -ph*****
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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 databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
查看是否启动
***@huahuapro ~ % ps -ef | grep mysqld
74 1401 1 0 二02下午 ?? 0:34.23 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --keyring-file-data=/usr/local/mysql/keyring/keyring --early-plugin-load=keyring_file=keyring_file.so
501 50208 49815 0 2:29下午 ttys000 0:00.00 grep mysqld
***@huahuapro ~ %
开机自启动mysql 服务
- 配置mysql。 环境变量
- 查看当前系统默认的
- 打开终端,默认shell是dash(10.15默认是zsh),可以用下行 代码更换成zsh,( 之前的绝大多数命令使用方法不变 )
chsh -s /bin/zsh
- 如果想要换回来,使用下行 代码,换回bash
chsh -s /bin/bash
- 需要注意的是,替换过后,要把终端退出再打开才生效
查看MacOS现在使用的shell,输入并执行下行 代码
echo $SHELL
# 如果你的输出结果是 /bin/zsh,参考 zsh 终端操作方式
# 如果你的输出结果是 /bin/bash,参考 bash 终端操作方式
- 如果shell更改为zsh 打开终端,输入并执行下行 代码:
vim ~/.zshrc
- 如果未更改,使用的是默认的bash
输入并执行下行 代码:
vim ~/.bash_profile
10.然后会到vim编辑的配置界面,键入 i,注意左下角,现在进入INSERT输入模式。 然后输入以下 代码,将MySQL安装路径加入环境变量。
export PATH=$PATH:/usr/local/mysql/bin
- 与此同时,也可以将以下两行 代码添加进去,设置快捷指令来开启或关闭MySQL服务端
alias mysqlstart='sudo /usr/local/mysql/support-files/mysql.server start'
alias mysqlstop='sudo /usr/local/mysql/support-files/mysql.server stop'
- 之后,按esc退出插入模式,并输入:wq
##立即生效
source ~/.zshrc
- 如果未更改,使用的是默认的bash
输入并执行下行 代码
source ~/.bash_profile
- echo $PATH
- 如果添加成功,会出现/usr/local/mysql/bin这一句
ps -ef | grep mysqld
这篇博客介绍了如何在Mac操作系统中手动启动MySQL服务以及设置开机自启动。首先,通过终端检查MySQL服务状态。接着,为了实现开机自启动,需要配置环境变量,这可能涉及将shell从dash切换到zsh。在修改shell后,使用vim编辑配置文件,将MySQL安装路径添加到环境变量,并可选地添加快捷指令以方便启动或停止MySQL服务。确认环境变量设置成功后,通过命令检查mysqld进程以验证配置是否生效。

4123

被折叠的 条评论
为什么被折叠?



