在 Mac OS Lion 上从命令行启动 MySQL 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7927854/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
start MySQL server from command line on Mac OS Lion
提问by vietstone
I installed mySQL for my Mac. Beside starting the SQL server with mySQL.prefPane tool installed in System Preference, I want to know the instruction to start from command-line. I do as follow:
我为我的 Mac 安装了 mySQL。除了使用安装在系统偏好设置中的 mySQL.prefPane 工具启动 SQL 服务器之外,我想知道从命令行启动的指令。我做如下:
After
后
su root
苏根
I start the mySQL server by command-line, it produce error as below:
我通过命令行启动 mySQL 服务器,它产生如下错误:
sh-3.2#/usr/local/mysql/bin/mysqld
111028 16:57:43[Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql-5.5.17-osx10.6-x86_64/data/ is case insensitive
111028 16:57:43[ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
111028 16:57:43[ERROR] Aborting
111028 16:57:43[Note] /usr/local/mysql/bin/mysqld: Shutdown complete
sh-3.2#/usr/local/mysql/bin/mysqld
111028 16:57:43[警告] 设置lower_case_table_names=2 因为/usr/local/mysql-5.5.17-osx10.6-x86_64/data/ 的文件系统不区分大小写
111028 16:57:43[ERROR] 致命错误:请阅读手册的“安全”部分以了解如何以 root 身份运行 mysqld!
111028 16:57:43[错误] 中止
111028 16:57:43[注意] /usr/local/mysql/bin/mysqld:关闭完成
Please help me!
请帮我!
EDIT:
编辑:
The reason is here: http://dev.mysql.com/doc/refman/5.5/en/changing-mysql-user.html
原因在这里:http: //dev.mysql.com/doc/refman/5.5/en/changed-mysql-user.html
A solution is described in the xdazz's answer below.
下面的 xdazz 的回答中描述了一个解决方案。
回答by user2792249
Simply:
简单地:
mysql.server start
mysql.server start
mysql.server stop
mysql.server stop
mysql.server restart
mysql.server restart
回答by xdazz
Try /usr/local/mysql/bin/mysqld_safe
尝试 /usr/local/mysql/bin/mysqld_safe
Example:
例子:
shell> sudo /usr/local/mysql/bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
shell> bg
(Press Control-D or enter "exit" to exit the shell)
You can also add these to your bash startup scripts:
您还可以将这些添加到 bash 启动脚本中:
export MYSQL_HOME=/usr/local/mysql
alias start_mysql='sudo $MYSQL_HOME/bin/mysqld_safe &'
alias stop_mysql='sudo $MYSQL_HOME/bin/mysqladmin shutdown'
回答by Eddie B
I like the aliases too ... however, I've had issues with MySQLCOM for start ... it fails silently ... My workaround is akin to the others ... ~/.bash_aliases
我也喜欢别名......但是,我在启动 MySQLCOM 时遇到了问题......它无声地失败......我的解决方法类似于其他...... ~/.bash_aliases
alias mysqlstart='sudo /usr/local/mysql/support-files/mysql.server start'
alias mysqlstop='sudo /usr/local/mysql/support-files/mysql.server stop'
回答by David
As thishelpful article states: On OS X to start/stop MySQL from the command line:
正如这篇有用的文章所述:在 OS X 上从命令行启动/停止 MySQL:
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
On Linux start/stop from the command line:
在 Linux 上从命令行启动/停止:
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
/etc/init.d/mysqld restart
Some Linux flavours offer the service command too
一些 Linux 版本也提供服务命令
# service mysqld start
# service mysqld stop
# service mysqld restart
or
或者
# service mysql start
# service mysql stop
# service mysql restart
回答by Alex K
If you installed it with homebrew, the binary will be somewhere like
如果你用自制软件安装它,二进制文件将在某个地方
/usr/local/Cellar/mysql/5.6.10/bin/mysqld
which means you can start it with
这意味着你可以用
/usr/local/Cellar/mysql/5.6.10/support-files/mysql.server start
and stop it with
并停止它
/usr/local/Cellar/mysql/5.6.10/support-files/mysql.server stop
Edit: As Jacob Raccuia mentioned, make sure you put the appropriate version of MySQL in the path.
编辑:正如 Jacob Raccuia 所提到的,确保在路径中放置了适当版本的 MySQL。
回答by Dennis
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
make alias in .bash_profile
在 .bash_profile 中创建别名
alias start_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM start"
alias stop_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM stop"
and if you are trying to run as root use following safe mode
如果您尝试以 root 用户身份运行,请使用以下安全模式
sudo ./bin/mysqld_safe
if you are still having issues starting, a recommended read: mysql5.58 unstart server in mac os 10.6.5
如果您仍然遇到启动问题,推荐阅读: mysql5.58 unstart server in mac os 10.6.5
回答by 42wolf
maybe your mysql-server didn't started
也许你的 mysql-server 没有启动
you can try
你可以试试
/usr/local/bin/mysql.server start
/usr/local/bin/mysql.server 启动
回答by shacharsol
For me this solution worked on mac Sierra OS:
对我来说,这个解决方案适用于 mac Sierra OS:
sudo /usr/local/bin/mysql.server start
Starting MySQL
SUCCESS!
回答by Nevio Vesi?
If it's installed with homebrew try just typing down mysql.serverin terminal and that should be it.
AFAIK it executable will be under /usr/local/bin/mysql.server.
如果它与自制软件一起安装,请尝试mysql.server在终端中输入,就可以了。AFAIK 它的可执行文件将在 /usr/local/bin/mysql.server 下。
If not you can always run following "locate mysql.server" which will tell you where to find such file.
如果没有,您可以始终运行“locate mysql.server”,它会告诉您在哪里可以找到此类文件。

