search
HomeDatabaseMysql TutorialMysql服务器的启动与停止(二)

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
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
When should you use a composite index versus multiple single-column indexes?When should you use a composite index versus multiple single-column indexes?Apr 11, 2025 am 12:06 AM

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)How to identify and optimize slow queries in MySQL? (slow query log, performance_schema)Apr 10, 2025 am 09:36 AM

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL: Essential Skills for DevelopersMySQL and SQL: Essential Skills for DevelopersApr 10, 2025 am 09:30 AM

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

Describe MySQL asynchronous master-slave replication process.Describe MySQL asynchronous master-slave replication process.Apr 10, 2025 am 09:30 AM

MySQL asynchronous master-slave replication enables data synchronization through binlog, improving read performance and high availability. 1) The master server record changes to binlog; 2) The slave server reads binlog through I/O threads; 3) The server SQL thread applies binlog to synchronize data.

MySQL: Simple Concepts for Easy LearningMySQL: Simple Concepts for Easy LearningApr 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.

MySQL: A User-Friendly Introduction to DatabasesMySQL: A User-Friendly Introduction to DatabasesApr 10, 2025 am 09:27 AM

The installation and basic operations of MySQL include: 1. Download and install MySQL, set the root user password; 2. Use SQL commands to create databases and tables, such as CREATEDATABASE and CREATETABLE; 3. Execute CRUD operations, use INSERT, SELECT, UPDATE, DELETE commands; 4. Create indexes and stored procedures to optimize performance and implement complex logic. With these steps, you can build and manage MySQL databases from scratch.

How does the InnoDB Buffer Pool work and why is it crucial for performance?How does the InnoDB Buffer Pool work and why is it crucial for performance?Apr 09, 2025 am 12:12 AM

InnoDBBufferPool improves the performance of MySQL databases by loading data and index pages into memory. 1) The data page is loaded into the BufferPool to reduce disk I/O. 2) Dirty pages are marked and refreshed to disk regularly. 3) LRU algorithm management data page elimination. 4) The read-out mechanism loads the possible data pages in advance.

MySQL: The Ease of Data Management for BeginnersMySQL: The Ease of Data Management for BeginnersApr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment