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.
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 immediatelysource /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
读取文件的顺序为
- /etc/my.cnf
- /etc/mysql/my.cnf
- /usr/local/mysql/etc/my.cnf
- ~/.my.cnf(注意:这里的文件名为.my.cnf和其它路径是有区别的,并且文件名前面有一个点那么Linux服务器会将这个文件隐藏,也就是使用ll命令查询不到此文件,只有使用ll -a才能获取,另外这个文件是在登录用户的家目录!!!)。
这四个文件会按照顺序读取,也就是说如果在/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!

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
