Home Database Mysql Tutorial MySQL数据库的启动与终止(1)

MySQL数据库的启动与终止(1)

Jun 07, 2016 pm 04:07 PM
mysql start up database server termination

由于MySQL服务器具有多种安装分发,而且能够运行在多种操作平台之上,因此它的启动与停止的方法也多种多样。你可以根据实际情况使用其中的一种。在你安装、升级或者维护系统时,你可能需要多次启动和终止服务器,你需要了解启动和终止服务器的方方面面。 直

由于MySQL服务器具有多种安装分发,而且能够运行在多种操作平台之上,因此它的启动与停止的方法也多种多样。你可以根据实际情况使用其中的一种。在你安装、升级或者维护系统时,你可能需要多次启动和终止服务器,你需要了解启动和终止服务器的方方面面。

直接运行守护程序

1、你可以采用的方法

一般的,你可以有以下几种选择启动MySQL服务器,它们的功能和用法几乎是相同的,所以一起在这里介绍:

直接使用MySQL守护程序mysqld启动数据库系统,尤其是Win32平台上的分发,这是因为,在Win32平台上没有mysql.server等服务器脚本可用。

通过调用safe_mysqld脚本,它接受与mysqld相同的参数,并试图为mysqld决定正确的选项,然后选择用那些运行它。

2、脚本或者守护程序的存放位置

对于二进制分发的安装,mysqld守护程序安装在MySQL安装目录的bin目录下,或者可在MySQL源代码分发的libexec目录下找到,缺省为/usr/local/libexec/。对于rpm分发,mysqld应该位于PATH变量决定的程序搜索路径中,因此可以直接引用。

safe_mysqld仍旧是一个脚本,并且只存在于Unix平台的分发中。safe_mysqld脚本安装在MySQL安装目录的bin目录下,或可在MySQL源代码分发的scripts目录下找到。对于rpm分发,该脚本应该位于PATH变量决定的程序搜索路径中,因此可以直接引用。

3、为什么要使用safe_mysqld脚本

safe_mysqld接受和mysqld同样的参数,并试图确定服务器程序和数据库目录的位置,然后利用这些位置调用服务器。safe_mysqld将服务器的标准错误输出重定向到数据库目录中的错误文件中,并以记录的形式存在。启动服务器后,safe_mysqld还监控服务器,并在其死机时重新启动。safe_mysqld通常用于Unix的BSD风格的版本。

如果,你曾经为root或在系统启动程序中启动safe_mysqld,其错误日志将有root拥有。如果再用非特权的用户身份调用safe_mysqld,则可能引起“Access Denied”(即,“所有权被拒绝”)的错误。此时可以删除错误文件在试一次。

由于safe_mysqld脚本的功能,使用safe_mysqld脚本明显比直接启动mysqld守护程序来得有效。

4、启动服务器的完整过程

对于Unix平台上的分发,如果你以root或在系统引导期间启动sqfe_mysqld,出错日志由root拥有,这可能在你以后试图用一个非特权用户调用safe_mysqld时将导致“permission denied”(权限拒绝)错误,删除出错日志再试一下。因此建议你在启动服务器前,首先切换到一个专门的用户mysql。

具体方法如下:

Unix平台

$ su mysql

$ safe_mysql & (或者 mysqld & ,不推荐)

Win32平台

C: \ mysql\bin>mysqld --standalone

或者C: \ mysql\bin>mysqld-nt –standalone

如果你使用mysqld并且没有把mysql安装在标准的位置,通常需要提供—basedir选项你的数据库的安装位置。

$safe_mysqld --basedir=”/path/to/mysql” &(Unix平台)

c:\mysql\bin>mysqld --basedir=”x:/path/to/mysql” (Win32平台)

5、使用safe_mysqld脚本实现服务器的自动启动

同样你可以利用safe_mysqld和mysqld实现服务器随操作系统自动启动。对于Linux系统以及BSD风格的系统(FreeBSD,OpenBSD等)),通常在/etc目录下有几个文件在引导时初始化服务,这些文件通常有以“rc”开头的名字,且它有可能由一个名为“rc.local”的文件(或类似的东西),特意用于启动本地安装的服务。

在这样的系统上,你可能将类似于下列的行加入rc.local文件中以启动服务器(如果safe_mysqld的目录在你的系统上不同,修改它即可):

if [ -x /usr/local/bin/safe_mysqld ]; then /usr/local/bin/safe_mysqld & fi

由于这样在引导时启动,将使用root身份启动数据库,在某些时候可能会产生问题和麻烦。这是你可以指定--user选项,因此可以将上面的代码修改为:

if [ -x /usr/local/bin/safe_mysqld ]; then

/usr/local/bin/safe_mysqld --user=mysql --datadir=/path/to/data  &

fi

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)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

See all articles