Home  >  Article  >  Database  >  What is the running file of mysql

What is the running file of mysql

藏色散人
藏色散人Original
2023-04-11 10:38:171713browse

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  &

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  &

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 &

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

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

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 &

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)

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

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 |
+-------+----------------------------------------------------------------------------------------+

创建后的数据库操作引擎变为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

Mysql启动配置文件

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

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

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

[mysqld]

[mysqld_safe]

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

[mysql]

[mysqladmin]

### 所有配置组的格式同上
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

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

  • 如果服务端采用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

推荐学习:《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:
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
Previous article:Does mysql have plsql?Next article:Does mysql have plsql?