如何在系统启动时自动启动MAMP sql server

时间:2011-09-06 22:05:47

标签: mysql macos mamp

我正在使用MAMP包附带的SQL服务器。我想设置我的电脑,以便每次启动时SQL服务器都会自动启动。有谁知道实现这一目标的最简单方法?

很多,非常感谢,

d

更新

当我尝试使用Macmade建议的LaunchDaemon文件时,我收到以下错误:

110906 19:52:05 mysqld_safe Starting mysqld daemon with databases from /Applications/MAMP/db/mysql
110906 19:52:05 [Warning] Setting lower_case_table_names=2 because file system for /Applications/MAMP/db/mysql/ is case in$
110906 19:52:05 [Note] Plugin 'FEDERATED' is disabled.
^G/Applications/MAMP/Library/bin/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
110906 19:52:05 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
110906 19:52:05 InnoDB: The InnoDB memory heap is disabled
110906 19:52:05 InnoDB: Mutexes and rw_locks use GCC atomic builtins
110906 19:52:05 InnoDB: Compressed tables use zlib 1.2.3
110906 19:52:05 InnoDB: Initializing buffer pool, size = 128.0M
110906 19:52:05 InnoDB: Completed initialization of buffer pool
110906 19:52:05  InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
110906 19:52:05 mysqld_safe mysqld from pid file /Applications/MAMP/db/mysql/Doyuen-Kos-Mac-Pro.local.pid ended

在此之后无效,我查看了一些MAMPs目录,发现了一个名为startMysql.sh的脚本。当我从命令行运行它时,它启动sql server。完善。关于它可能有用的机会,我也尝试将它放入LaunchDaemon文件中。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <false/>
    <key>Label</key>
    <string>mysql</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Applications/MAMP/bin/start.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

这也不起作用。另外,奇怪的是,它似乎没有在控制台应用程序中产生任何类型的任何消息。

我仍然被困住了。有人有什么想法吗?

3 个答案:

答案 0 :(得分:3)

在Mac中打开Textedit或纯文本编辑器,将其粘贴到其中

对于Apache

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>info.mamp.start.apache</string>
    <key>ProgramArguments</key>
    <array>
      <string>/Applications/MAMP/Library/bin/apachectl</string>
      <string>start</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

然后为mysql创建另一个文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>info.mamp.start.mysql</string>
    <key>ProgramArguments</key>
    <array>
      <string>/Applications/MAMP/Library/bin/mysqld_safe</string>
      <string>--port=3306</string>
      <string>--socket=/Applications/MAMP/tmp/mysql/mysql.sock</string>
      <string>--lower_case_table_names=0</string>
      <string>--pid-file=/Applications/MAMP/tmp/mysql/mysql.pid</string>
      <string>--log-error=/Applications/MAMP/logs/mysql_error_log</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>UserName</key>
    <string>YOUR_USERNAME</string>
  </dict>
</plist>

请务必将“YOUR_USERNAME”替换为您帐户的用户名。

将此文件另存为(或将文件移至)/Library/LaunchDaemons/info.mamp.start.apache.plist和/Library/LaunchDaemons/info.mamp.start.mysql.plist。

要保存的文件夹是/ Library / LaunchDaemons /

打开终端,输入

cd / Library / LaunchDaemons / sudo chown root:wheel info.mamp.start.apache.plist sudo chown root:wheel info.mamp.start.mysql.plist

完成。重启Mac

参考:http://stringfoo.com/2008/08/25/tutorial-launching-mamp-silently-on-startup/

答案 1 :(得分:2)

您可能需要LaunchDaemon文件。

在/ Library / LaunchDaemons /目录中创建一个名为whatever.plist的文件,并放置以下内容。

请注意,权限必须是:root:wheel / 644

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <false/>
    <key>Label</key>
    <string>mysql</string>
    <key>ProgramArguments</key>
    <array>
        <string>/path/to/mysql/bin/mysqld_safe</string>
        <string>--user=_mysql</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

答案 2 :(得分:-1)

我刚刚找到了解决这个问题的可能方法。事实证明,MAMP的付费版本MAMP Pro具有简单的单击功能,可以将系统配置为在启动时启动SQL服务器。因此,支付约50美元购买付费版本是实现这一目标的一种方法。这不是我希望的那种解决方案,但它完成了工作。