关于macos:在Mac OS Lion上从命令行启动MySQL服务器

start MySQL server from command line on Mac OS Lion

我为Mac安装了mySQL。 除了使用System Preference中安装的mySQL.prefPane工具启动SQL Server之外,我还想知道从命令行启动的指令。
我做如下:

su root

我通过命令行启动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

请帮我!

编辑:

原因在这里:http://dev.mysql.com/doc/refman/5.5/en/changing-mysql-user.html

以下xdazz的答案中描述了一种解决方案。


只是:

mysql.server start

mysql.server stop

mysql.server restart


尝试/usr/local/mysql/bin/mysqld_safe

例:

1
2
3
4
5
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)

您还可以将这些添加到bash启动脚本中:

1
2
3
export MYSQL_HOME=/usr/local/mysql
alias start_mysql='sudo $MYSQL_HOME/bin/mysqld_safe &'
alias stop_mysql='sudo $MYSQL_HOME/bin/mysqladmin shutdown'


我也喜欢别名...但是,我在启动时遇到了MySQLCOM的问题...它默默地失败了...我的解决方法与其他类似...?/ .bash_aliases

1
2
alias mysqlstart='sudo /usr/local/mysql/support-files/mysql.server start'
alias mysqlstop='sudo /usr/local/mysql/support-files/mysql.server stop'


如这篇有用的文章所述:
在OS X上从命令行启动/停止MySQL:

1
2
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop

在Linux上,从命令行启动/停止:

1
2
3
/etc/init.d/mysqld start
/etc/init.d/mysqld stop
/etc/init.d/mysqld restart

一些Linux版本也提供service命令

1
2
3
# service mysqld start
# service mysqld stop
# service mysqld restart

要么

1
2
3
 # service mysql start
 # service mysql stop
 # service mysql restart


如果您使用自制软件安装,则二进制文件将类似于

1
/usr/local/Cellar/mysql/5.6.10/bin/mysqld

这意味着您可以从

1
/usr/local/Cellar/mysql/5.6.10/support-files/mysql.server start

并停止它

1
/usr/local/Cellar/mysql/5.6.10/support-files/mysql.server stop

编辑:正如Jacob Raccuia所述,请确保在路径中放置了适当版本的MySQL。


1
2
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop

在.bash_profile中创建别名

1
2
alias start_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM start"
alias stop_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM stop"

如果您尝试以root用户身份运行,请使用以下安全模式

1
sudo ./bin/mysqld_safe

如果您仍然遇到问题,建议阅读:
mysql5.58在Mac OS 10.6.5中启动服务器


也许您的mysql服务器没有启动

你可以试试

/usr/local/bin/mysql.server start


如果安装了自制软件,请尝试在终端中键入mysql.server,应该是这样。
AFAIK可执行文件位于/usr/local/bin/mysql.server下。

如果没有,您可以始终按照"定位mysql.server"运行,它将告诉您在哪里可以找到这样的文件。


对我来说,此解决方案在mac Sierra OS上有效:

1
2
3
sudo /usr/local/bin/mysql.server start
Starting MySQL
SUCCESS!

我的MySQL是通过自制软件安装在OS X ElCaptain上的。它正在修复的原因

<5233>

  • 建议我跑步

sudo chown -R $(whoami):admin /usr/local

然后:

1
2
brew update
mysql.server start

mysql现在正在运行


如果您通过Homebrew安装了MySQL,这些命令将为您提供帮助:

1
2
3
4
5
# For starting
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

# For stoping
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist


1
111028 16:57:43 [ERROR] Fatal error: Please read"Security" section of the manual to find out how to run mysqld as root!

您是否为MySQL安装设置了root密码?这与您的sudo根密码不同。尝试/usr/local/mysql/bin/mysql_secure_installation