Search code examples
windows-8cygwinmysql

Shutting down mysqld in Cygwin


How are you supposed to shutdown mysqld faster from Cygwin (without killing the process in Task Manager) and prevent these errors?

This is how I started it:

$ /usr/bin/mysqld_safe &
[1] 4440

Chloe@xps ~
$ 130809 17:27:09 mysqld_safe Logging to '/var/lib/mysql/xps.err'.
chown: invalid user: `mysql'
130809 17:27:10 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

When I try to shut it down, it prints this forever and won't respond to ^C:

$ /usr/sbin/mysqld.exe shutdown
130809 17:29:26 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
130809 17:29:26 [Note] Plugin 'FEDERATED' is disabled.
130809 17:29:26 InnoDB: The InnoDB memory heap is disabled
130809 17:29:26 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130809 17:29:26 InnoDB: Compressed tables use zlib 1.2.7
130809 17:29:26 InnoDB: Initializing buffer pool, size = 128.0M
130809 17:29:26 InnoDB: Completed initialization of buffer pool
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
130809 17:29:26  InnoDB: Retrying to lock the first data file
InnoDB: Unable to lock ./ibdata1, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.

It finally pretends to shut down after 3 minutes of printing those errors repeatedly, but it really doesn't shut down because it is still in Task Manager and ps list. I don't think it should take that long.

130809 17:31:06 [Note] /usr/sbin/mysqld: Shutdown complete

I also tried

$ mysqladmin shutdown

but that appears to hang.


Solution

  • I know that probably the user already found how to shutdown MySQL, but I just had the same issue and this was the first hit on google.

    The trick was to add the host as the IP address and user on the command (if I used localhost as the host, the command would hang up).

     mysqladmin.exe -h 127.0.0.1 -u root shutdown
    

    @Chloe there are a few of scenarios where this might not work. The 2 most common I think are if MySQL is bound to a different IP or if it's bound to a different port (the other scenarios are if MySQL is not using TCP, but one of the other transport protocols).

    So, for example, after I run mysqld_safe & and mysql starts, then when I run the command netstat I can see that it's listening and on the default port 3306

    $ netstat -an | grep 3306
    

    I hope this helps!


    edit

    If MySQL is not running, you'll need to provide a connection timeout (--connect-timeout=N) as by default mysqladmin waits forever to connect to the server. For example, if MySQL is not running

    $ mysqladmin.exe -h 127.0.0.1 -u root --connect-timeout=5 shutdown
    
    mysqladmin: connect to server at '127.0.0.1' failed
    error: 'Can't connect to MySQL server on '127.0.0.1' (4)'
    Check that mysqld is running on 127.0.0.1 and that the port is 3306.
    You can check this by doing 'telnet 127.0.0.1 3306'
    

    Here, the command waits for 5 seconds before giving up. From my point of view, it doesn't make sense that it waits forever, but that's the default that mysql picked up :S.