Table of Contents
Mysql startup options and configuration files
Mysql startup method
mysqld
mysqld_safe
mysqld_multi
mysql.server
Mysql startup mode option
选项的长形式和短形式
Mysql启动配置文件
My.cnf文件读取优先级
Home Database Mysql Tutorial What is the running file of mysql

What is the running file of mysql

Apr 11, 2023 am 10:38 AM
mysql mysqli Getting started with mysql

The running file of mysql is mysqld; mysqld is an executable file, representing the Mysql server program. Executing this file can directly start a server process; and mysqld_safe is a startup script, which will indirectly call mysqld, and A monitoring process will also be started incidentally.

What is the running file of mysql

The operating environment of this tutorial: Windows 10 system, mysql8 version, Dell G3 computer.

What is the running file of mysql?

Mysql startup options and configuration files

Mysql startup method

The following startup commands all need to rely on the Mysql environment variables configured in the Linux environment

vi /etc/profile
Add the installation path of Mysql at the end of the file (in the demonstration, mysql is configured under /usr/local/mysql-5.7.26. This path needs to be based on your own environment. Depends)
export PATH=/usr/local/mysql-5.7.26/bin/:$PATH
Refresh the configuration file after updating the file, otherwise it will not take effect immediately
source /etc/profile

mysqld

Mysqld is an executable file, which represents the Mysql server program. Executing this file can directly start a server process.

If non-root users can start in the following way, specify the configuration file to be read at startup.

mysqld --defaults-file=/etc/my.cnf  &
Copy after login

The root user needs to add startup parameters (mysql does not allow the root user to start directly due to security issues, so it needs to add startup parameters to force the use of the root account to start).

mysqld --defaults-file=/etc/my.cnf --user=root  &
Copy after login

mysqld_safe

mysqld_safe is a startup script that indirectly calls mysqld and also starts a monitoring process. This monitoring process will be used when the server hangs. , can automatically restart the service. In addition, this script will redirect the error information and diagnostic information of the server program to a file to record the error log.

You don’t need to specify a default configuration file. The command is as follows

mysqld_safe --defaults-file=/etc/my.cnf &
Copy after login

mysqld_multi

mysqld_multi can start multiple mysql database instances, which will not be discussed here.

mysql.server

There is actually a folder support-files in the installation directory of mysq. The specific directory is /usr/local/mysql-5.7 .26/support-files, the mysql.server inside is also a startup script. This script will indirectly call the mysqld_safe script. The execution command is as follows

### 路径依照自己的mysql安装路径来
cd /usr/local/mysql-5.7.26/support-files
./mysql.server start|stop
Copy after login

If this path is specified Soft link

ln -s /usr/local/mysql-5.7.26/support-files/mysql.server /etc/init.d/mysql

Then The startup command can be simplified to

service mysql stop/start
Copy after login

Mysql startup mode option

The Mysql service can specify some startup parameters when starting, such as the Mysql server and client discussed before The client's connection methods include TCP/IP, named pipes, shared memory, and Unix domain socket files. If the following conditions are met when the client starts, it will communicate with the server using domain socket files.

  • The -h option was not specified.
  • Specify -h to specify the domain name as localhost, which is -hlocalhost.
  • The client startup parameter specifies --protocol=socket.

If the client specifies -h followed by the IP address, even if it is 127.0.0.1, it means using TCP/IP connection, then this is the client If the server side is prohibited from using TCP/IP communication, what should be done?

Root users use the following commands, non-root users do not need --user=root

mysqld --user=root --skip-networking &
Copy after login

Client operation

### 采用unix域套接字文件通信 正常
[root@test ~]# mysql -uroot -p

[root@test ~]# mysql -hlocalhsot -uroot -p

### 采用TCP/IP连接,直接拒绝
[root@test ~]# mysql -h127.0.0.1 -uroot -p
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
Copy after login

Another example is specifying the database storage engine. The default in Mysql is InnoDB. We can modify it through the startup options

### 非root用户去除--user=root选项
mysqld --user=root --default-storage-engine=MyISAM
Copy after login

Customer End operation

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> CREATE TABLE test(
    ->    id INT
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql> show create table test;
+-------+----------------------------------------------------------------------------------------+
| Table | Create Table                                                                           |
+-------+----------------------------------------------------------------------------------------+
| test  | CREATE TABLE `test` (
  `id` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------+
Copy after login

创建后的数据库操作引擎变为MyISAM,配置生效。

综上Mysql如果存在多个启动指令可以采用**--启动选项1=值1 --启动选项2=值2 ... --启动选项n=值n**,配置修改启动项。

Mysql启动指令众多,其它指令可以通过命令**mysqld --verbose --help**查看。

选项的长形式和短形式

在myql中其实一直有区分长形式命令和短形式命令,但是我们在使用时并没有注意;

需要注意的是长连接前面是两个横杠--,短连接只有一个-,另外长连接指令和值之前需要有空格,短连接可以紧挨着不需要空格。

### 长连接形式
mysql --host 127.0.0.1  --user root --port 3306 --password
 
### 短连接形式
mysql -h127.0.0.1 -uroot -P3306 -p
Copy after login

Mysql启动配置文件

采用Mysql启动方式选项虽然是方便,但也带来的一些问题,如果启动选项参数过多导致启动命令毫无可读性而言,启动选项配置的参数只对当前启动的服务生效,也就是如果下次重启所有的启动参数将被还原不会被记录,所以为了将这些启动参数保存,我们就需要一个配置文件默认称为my.cnf。

my.cnf配置文件按照启动的是客户端程序还是服务端程序将配置分为了多个组,如下所示

#### 服务端启动配置
[server]
### 格式一:配置项=具体值
port=3306
### 格式二:配置项(没有值的情况,配置项为禁止客户端采用TCP/IP连接)
skip-networking

[mysqld]

[mysqld_safe]

#### 客户端启动配置
[client]

[mysql]

[mysqladmin]

### 所有配置组的格式同上
Copy after login
mysqladmin:是一个执行管理操作的客户端程序,它可以检查服务器的配置和当前服务的状态,创建和删除数据库等。
[root@test ~]# mysqladmin -uroot -p processlist
Enter password:
+----+------+-----------+------+---------+------+----------+------------------+
| Id | User | Host      | db   | Command | Time | State    | Info             |
+----+------+-----------+------+---------+------+----------+------------------+
| 33 | root | localhost | test | Sleep   | 5    |          |                  |
| 35 | root | localhost |      | Query   | 0    | starting | show processlist |
+----+------+-----------+------+---------+------+----------+------------------+
[root@test ~]# mysqladmin -uroot -p status
Enter password:
Uptime: 13335  Threads: 2  Questions: 66  Slow queries: 0  Opens: 121  Flush tables: 3  Open tables: 5  Queries per second avg: 0.004
### 打印系统变量
[root@test ~]# mysqladmin -uroot -p variable

服务端和客户端不同命令启动会读取不同的配置组;

如果多个配置组存在相同的配置如下所示

[mysqld]
port = 3306
###.....省略其它配置
[server]
port=3333
[mysqld_safe]
port=5555
Copy after login

会根据书写顺序读取,也就是说后面的配置会覆盖前面的配置

  • 如果服务端采用mysqld启动服务端那么port的最终结果为port=3333(只会读取[mysqld]和[server]配置组)
  • 如果服务端采用mysqld_safe启动服务端那么port的最终结果为port=5555(只会读取[mysqld],[mysqld_safe]和[server]配置组)

My.cnf文件读取优先级

在启动Mysql服务时如果没有指定配置文件的具体路径,那么Mysql服务会到如下几个目录搜索,可以通过命令mysql --help查看,部分说明如下

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

读取文件的顺序为

  1. /etc/my.cnf
  2. /etc/mysql/my.cnf
  3. /usr/local/mysql/etc/my.cnf
  4. ~/.my.cnf(注意:这里的文件名为.my.cnf和其它路径是有区别的,并且文件名前面有一个点那么Linux服务器会将这个文件隐藏,也就是使用ll命令查询不到此文件,只有使用ll -a才能获取,另外这个文件是在登录用户的家目录!!!)。

What is the running file of mysql

这四个文件会按照顺序读取,也就是说如果在/etc/my.cnf文件下配置了port=3006,在~/.my.cnf下面配置了port=3307那么最终读取的结果是port为3307。

当然这是Mysql读取默认配置的情况,我们可以自己指定配置文件路径,如下所示

#### --defaults-file后面接任意路径文件,非root用户不需要--user=root
mysqld --defaults-file=/usr/local/mysql/etc/my.cnf.copy --user=root
Copy after login

推荐学习:《MySQL视频教程

The above is the detailed content of What is the running file of mysql. For more information, please follow other related articles on the PHP Chinese website!

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

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)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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: 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.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

How to create navicat premium How to create navicat premium Apr 09, 2025 am 07:09 AM

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

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.

How to create a new connection to mysql in navicat How to create a new connection to mysql in navicat Apr 09, 2025 am 07:21 AM

You can create a new MySQL connection in Navicat by following the steps: Open the application and select New Connection (Ctrl N). Select "MySQL" as the connection type. Enter the hostname/IP address, port, username, and password. (Optional) Configure advanced options. Save the connection and enter the connection name.

How to use single threaded redis How to use single threaded redis Apr 10, 2025 pm 07:12 PM

Redis uses a single threaded architecture to provide high performance, simplicity, and consistency. It utilizes I/O multiplexing, event loops, non-blocking I/O, and shared memory to improve concurrency, but with limitations of concurrency limitations, single point of failure, and unsuitable for write-intensive workloads.

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 and SQL: Essential Skills for Developers MySQL and SQL: Essential Skills for Developers Apr 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.

See all articles