如何"safely"终止mysqld?

How to "safely" terminate mysqld?

我正在关注 mysql on Cygwin

# To begin MySQL setup run the following:
mysql_install_db

# Run mysql - you'll get a firewall alert from windows if you have it active.
mysqld_safe &

# Immediately following that, it would be wise to run the following:
mysql_secure_installation

mysql_install_db 期间,有人问我数据库 (DB) 是为谁准备的。我指定了一个非管理员帐户 nonadmin.

对于mysql_secure_installation过程,我遵循了同名的MariaDB page。与描述相反,我被告知我没有root密码,所以我将其设置为与我的cygwin和windows管理员帐户相同。

我忘记了上面三个命令中的每一个是否使用了哪个帐户,但我记得是这样的:

看来我应该在最后一步之后重新启动服务器。使用 ps -ef,我注意到进程 mysqld 属于 nonadmin。使用 nonadmin,我在 mysql on Cygwin 尝试了 mysqladmin shutdown 命令。我得到:

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'nonadmin'@'localhost' (using password: NO)'

我尝试了提示用户输入密码的命令变体:mysqladmin -p shutdown。我这样做了两次,为 nonadminadmin 输入了 cygwin/windows 密码。两次,我得到:

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'nonadmin'@'localhost' (using password: YES)'

总共尝试了 3 次。然后我切换到 admin 帐户并重试了所有 3 次尝试。我收到了以上消息,但用户名是 admin:

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'admin'@'localhost' (using password: NO)'

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'admin'@'localhost' (using password: YES)'

因此,连接到守护进程以将其关闭并不令人愉快。作为替代方案,我想避免使用 kill -9 破坏 mysqld,因为我喜欢干净利落地终止(尽管我可能很快就会这样做)。

作为另一种选择,我遇到了对 /etc/init.d 的引用,但我没有这样的文件。

谁能解释一下为什么我无法连接到守护程序以将其关闭?

此外,我是 MySQL 的新手,所以如果可能的话,最好找到回到 mysql on Cygwin 的过程而不是偏离太多。

谢谢。

我最终做的是 kill -9ps -ef 显示的所有 mysql 进程。然后我删除了 /var/lib/mysql —— 不小心删除了所有 /var/lib/*。因此,随后,我重新安装了所有 Cygwin 软件包,从而从头开始。

我还在 this alaya page 找到了以下更详细的过程,用于在 Cygwin 上安装 MySQL/MariaDB 数据库,之后我 能够关闭MySQL 服务器。

from the Administrator terminal run:

mysql_install_db

Start the mysql server:

mysqld_safe &

then run:

mysql_secure_installation

You should then be able to log in to MariaDB from a non-administrative shell with:

mysql -u root -p

最初的 mysql_install_db 步骤生成了以下看起来很有用的信息,我在此处捕获了这些信息,因为我不确定是否有办法再次获取它。

Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
2019-05-01 23:00:06 0 [Warning] InnoDB: innodb_open_files 300 should not be greaterthan the open_files_limit 256
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h fmaPC password 'new-password'

Alternatively you can run:
'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

mysql_secure_installation步骤中,我按照建议设置了root密码。那么,我可以代替 mysql -u root -p 步骤发出以下命令来停止 MySQL 服务器:

mysqladmin -u root -p shutdown

从一个没有管理员权限的用户的角度来看,我对这个过程有了一个重要的发现。与上面引用的 alaya 页面上的建议相反,上述过程 而不是 必须从管理员帐户完成。重要的是,可以连接到 MySQL 服务器的用户帐户与主机系统(Windows 或 *nix)上的用户帐户无关(这是我从阅读 MariaDB 知识库中得到的事实) ).我怀疑主机系统上的任何用户都可以通过它提供的套接字 [1] 使用正确的密码连接到服务器上的任何用户帐户。

我还发现上述过程适用于具有非常严格的 Windows 防火墙策略的计算机。即使服务器(mysqld_safe & 步骤)和客户端(mysql -u root -p 步骤)是从同一个非管理帐户启动的,Windows 防火墙也会发出有关限制某些功能的警告。我怀疑触发器是创建用于连接到服务器的套接字。然而,尽管有警告,ps -ef 显示服务器为 运行。因此,我怀疑防火墙限制只允许环回连接。 mysql_secure_installation 这一步显然不允许外部连接,我发现在这一步之后,停止并重新启动服务器不再触发防火墙警告。所以 mysql_secure_installation 的效果似乎会持续到后续的 sqld 启动中,至少当它们通过 mysqld_safe.

启动时是这样

[1] "Present" 在这里可能不是正确的术语,因为我更像是一名分析师,而不是开发人员或管理员。