Home Database Mysql Tutorial Mysql服务器的启动与停止(二)

Mysql服务器的启动与停止(二)

Jun 07, 2016 pm 05:59 PM

Mysql服务器的启动与停止(二)

三、停止服务器
要手工启动服务器,使用MySQLadmin:

%mysqladmin shutdown

要自动停止服务器,你不需做特别的事情。BSD系统一般通过向进程发一个TERM信号停止服务,它们或者正确应答它或被粗鲁地杀死。mysqld在它收到这个信号时以终止作为应答。对于用mysql.server启动服务器的System V风格的系统,停止进程将用一个stop参数调用该脚本,告诉服务器终止,当然假定你已安装了mysql.server。

四、如果你不能连接服务器,如何重新获得对服务器的控制

在某些情况下,你可能由于不能连接它而手工重启服务器。当然,这有点矛盾。因为一般你通过连接服务器而手工关掉它,那么这种情况如何会出现。

首先,MySQL root口令可以已经设置为你不知道的值,这可能发生在你修改口令时,例如,如果你在输入新口令时偶然键入一个不可见的控制字符。你也可能忘记口令。

其次,连接localhost通常通过一个Unix域套接字文件进行,一般是/tmp/mysql.sock。如果套接字文件被删除了,本地客户就不能连接。这可能发生在你的系统运行一个cron任务删除了/tmp下的临时文件。

如果你因为丢失套接字文件而不能连接,你可以简单地通过重启服务器重新创建得到它。因为服务器在启动时重新创建它。这里的骗局是你不能用套接字建立连接因为它不见了,你必须建立一个TCP/IP连接,例如,如果服务器主机是pit.snake.net,你可以这样连接:

%mysqladmin -p -u root -h pit.snake.net shutdown

如果套接字文件被一个cron任务删除,问题将重复出现,除非你修改cron任务或使用一个或使用一个不同的套接字文件,你可以使用全局选项文件指定一个不同的套接字,例如,如果数据目录是/usr/local/var,你可以通过将下列行加入/etc/my.cnf中,将套接字文件移到那里:

[mysqld]
socket=/usr/local/var/mysql.sock

[client]
socket=/usr/local/var/mysql.sock
对服务器和客户均指定路径名,使得它们都使用同一个套接字文件。如果你只为服务器设置路径,客户程序将仍然期望在原位置执行套接字,在修改后重启服务器,使它在新位置创建套接字。

如果你由于忘记root口令或已经将它设置为不同于认为的值而不能连接,你需要重新获得对服务器的控制,是你能再次设置口令:



中断服务器

如果你以root登录服务器主机,你可以用kill命令终止服务器。你可以使用ps命令或通过寻找服务器的PID文件(通常在数据目录中)找出服务器进程的ID。

最好是首先尝试用一个向服务器发出一个TERM信号的正常kill看它是否将以正常终止应答。这种方式下,表和日志将正确地被清空。如果服务器阻塞并且不应答一个正常终止信号,你可以用kill -9强制终止它。这是最后的手段了,因为这可能有未清空的修改,而且你冒着让表处于一个不一致状态的风险。

如果你用kill -9终止服务器,要确保在启动服务器前用myisamchk和isamchk检查你的表。
用--skip-grant-table选项重启服务器。
这告诉服务器不使用授权表验证连接,这允许你以root连接而无须口令。在你已经连接后,改变root口令。
用mysqladmin flush-privileges告诉服务器再次使用授权表启动
如果你的mysqladmin版本不认识Flash-privileges,试一试reload。

五、运行多个服务器

大多数再一台给定的机器上运行单个MySQL服务器,但在很多情况下,运行多个服务器是很有用的:

你可能想测试一个服务器的新版本,而保留你正在运行的生产服务器。在这种情况下,你会运行不同的服务器代码。
操作系统一般限制每个进程的打开文件句柄数量。如果你的系统很难提高这个限制,运行多个服务器是解决限制的一种方法。在这种情况下,你可能运行统一服务器的多个实例。
ISP经常为其客户提供自己的MySQL安装,有必要涉及单独的服务器。在这种情况下,你可能运行同一版本的多个实例或不同版本,如果不同的客户想要不同版本的MySQL。
很自然地,运行多个服务器比只运行一个服务器要复杂得多。如果你安装多个版本,你不能在同一个地方安装所有东西。当服务器运行时,某些参数必须或很可能对每个服务器是唯一的,它们包括服务器在哪安装、其数据目录的路径名、TCP/IP端口和UNIX域套接字路径名以及用于运行服务器的UNIX账号(如果你不再同一账号下运行所有服务器)。如果你决定运行多个服务器,一定要注意你使用的参数,是你不至于。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Apr 02, 2025 pm 07:05 PM

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

Can mysql and mariadb coexist Can mysql and mariadb coexist Apr 08, 2025 pm 02:27 PM

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

See all articles