How do you stop MySQL on a Mac OS install?

前端 未结 20 1430
暗喜
暗喜 2020-11-30 16:08

I installed MySQL via MacPorts. What is the command I need to stop the server (I need to test how my application behave when MySQL is dead)?

相关标签:
20条回答
  • 2020-11-30 16:33

    Use:

    sudo mysqladmin shutdown --user=*user* --password=*password*
    

    One could probably get away with not using sudo. The user could be root for example (that is, the MySQL root user).

    0 讨论(0)
  • 2020-11-30 16:33

    Well, if all else fails, you could just take the ruthless approach and kill the process running MySQL manually.

    That is,

    ps -Af
    

    to list all processes, then do "kill <pid>" where <pid> is the process id of the MySQL daemon (mysqld).

    0 讨论(0)
  • 2020-11-30 16:34

    I installed mysql5 and mysql55 over macports. For me the mentioned files here are located at the following places:

    (mysql55-server) /opt/local/etc/LaunchDaemons/org.macports.mysql55-server/org.macports.mysql55-server.plist

    (mysql5) /opt/local/etc/LaunchDaemons/org.macports.mysql5/org.macports.mysql5.plist

    So stopping for these works like this:

    mysql55-server:

    sudo launchctl unload -w /opt/local/etc/LaunchDaemons/org.macports.mysql55-server/org.macports.mysql55-server.plist
    

    mysql5:

    sudo launchctl unload -w /opt/local/etc/LaunchDaemons/org.macports.mysql5/org.macports.mysql5.plist 
    

    You can check if the service is still running with:

    ps ax | grep mysql
    

    Further you can check the log files in my case here:

    mysql55-server

    sudo tail -n 100 /opt/local/var/db/mysql55/<MyName>-MacBook-Pro.local.err
    ...
    130213 08:56:41 mysqld_safe mysqld from pid file /opt/local/var/db/mysql55/<MyName>-MacBook-Pro.local.pid ended
    

    mysql5:

    sudo tail -n 100 /opt/local/var/db/mysql5/<MyName>-MacBook-Pro.local.err
    ...
    130213 09:23:57  mysqld ended
    
    0 讨论(0)
  • 2020-11-30 16:36

    There are different cases depending on whether you installed MySQL with the official binary installer, using MacPorts, or using Homebrew:

    Homebrew

    brew services start mysql
    brew services stop mysql
    brew services restart mysql
    

    MacPorts

    sudo port load mysql57-server
    sudo port unload mysql57-server
    

    Note: this is persistent after a reboot.

    Binary installer

    sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop
    sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
    sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart
    
    0 讨论(0)
  • 2020-11-30 16:36

    Try

    sudo <path to mysql>/support-files/mysql.server start
    sudo <path to mysql>/support-files/mysql.server stop
    

    Else try:

    sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
    sudo /Library/StartupItems/MySQLCOM/MySQLCOM stop<br>
    sudo /Library/StartupItems/MySQLCOM/MySQLCOM restart
    

    However, I found that the second option only worked (OS X 10.6, MySQL 5.1.50) if the .plist has been loaded with:

    sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
    

    PS: I also found that I needed to unload the .plist to get an unrelated install of MAMP-MySQL to start / stop correctly. After running running this, MAMP-MySQL starts just fine:

    sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist

    0 讨论(0)
  • 2020-11-30 16:36

    On my mac osx yosemite 10.10. This command worked:

    sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
    sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysql.plist
    

    You can find your mysql file in folder /Library/LaunchDaemons/ to run

    0 讨论(0)
提交回复
热议问题