
mysqld Command in Linux
mysqld is the MySQL server daemon, which is responsible for handling database operations, managing connections, and executing SQL queries. It is a crucial component of the MySQL database management system.
Table of Contents
Here is a comprehensive guide to the options available with the mysqld command −
Understanding mysqld Command
Before using mysqld, you need to have MySQL installed on your Linux system. mysqld is included with the MySQL server package. If it's not already installed, you can install it using your package manager.
For Debian-based systems (e.g., Ubuntu) −
sudo apt update sudo apt install mysql-server

For Red Hat-based systems (e.g., CentOS) −
sudo yum install mysql-server
Verify installation −
which mysqld

How to Use mysqld Command in Linux?
The mysqld daemon can be started and stopped using system service management commands. On most Linux distributions, systemctl is used to manage services.
Start the MySQL server −
sudo systemctl start mysqld

Stop the MySQL server −
sudo systemctl stop mysqld
Restart the MySQL server −
sudo systemctl restart mysqld
Check the status of the MySQL server −
sudo systemctl status mysql

Configuring mysqld −
The behavior of mysqld can be configured using the MySQL configuration file (my.cnf or my.ini). This file contains various settings that control the operation of the MySQL server.
ini [mysqld] port = 3306 datadir = /var/lib/mysql socket = /var/lib/mysql/mysql.sock log-error = /var/log/mysql/error.log pid-file = /var/run/mysqld/mysqld.pid
Running mysqld with Command-Line Options
You can run mysqld with various command-line options to override the default configuration settings.
sudo mysqld --port=3307 --datadir=/custom/mysql/data --socket=/custom/mysql/mysql.sock

This command starts the MySQL server on port 3307, using a custom data directory and socket file.
Checking mysqld Version
To check the version of the MySQL server, use the --version option.
mysqld --version

This command displays the version of the MySQL server.
Running mysqld in Safe Mode
You can run mysqld in safe mode using the mysqld_safe script. This script starts the MySQL server with additional safety checks and logging.
sudo mysqld_safe --defaults-file=/etc/mysql/my.cnf

This command starts the MySQL server in safe mode using the specified configuration file.
Running mysqld with a Specific Configuration File
You can specify a custom configuration file using the --defaults-file option.
sudo mysqld --defaults-file=/custom/mysql/my.cnf

This command starts the MySQL server using the specified configuration file.
Running mysqld with a Specific User
You can run mysqld as a specific user using the --user option.
sudo mysqld --user=mysql

This command starts the MySQL server as the mysql user.
Running mysqld with a Specific Data Directory
You can specify a custom data directory using the --datadir option.
sudo mysqld --datadir=/custom/mysql/data

This command starts the MySQL server using the specified data directory.
Running mysqld with a Specific Socket File
You can specify a custom socket file using the --socket option.
sudo mysqld --socket=/custom/mysql/mysql.sock

This command starts the MySQL server using the specified socket file.
Running mysqld with a Specific Port
You can specify a custom port using the --port option.
sudo mysqld --port=3307

This command starts the MySQL server on port 3307.
Running mysqld with Logging Enabled
You can enable logging using the --log-error option.
sudo mysqld --log-error=/var/log/mysql/error.log

This command starts the MySQL server with error logging enabled.
Running mysqld with a Specific PID File
You can specify a custom PID file using the --pid-file option.
sudo mysqld --pid-file=/var/run/mysqld/mysqld.pid

This command starts the MySQL server using the specified PID file.
Running mysqld with a Specific Character Set
You can specify a custom character set using the --character-set-server option.
sudo mysqld --character-set-server=utf8mb4

This command starts the MySQL server using the utf8mb4 character set.
Running mysqld with a Specific Collation
You can specify a custom collation using the --collation-server option.
sudo mysqld --collation-server=utf8mb4_unicode_ci

This command starts the MySQL server using the utf8mb4_unicode_ci collation.
Running mysqld with SSL
You can enable SSL for the MySQL server using the --ssl option along with other SSL-related options such as --ssl-ca, --ssl-cert, and --ssl-key.
sudo mysqld --ssl --ssl-ca=/path/to/ca-cert.pem --ssl-cert=/path/to/server-cert.pem --ssl-key=/path/to/server-key.pem

This command starts the MySQL server with SSL enabled.
Running mysqld with Replication
You can configure the MySQL server for replication using various replication-related options such as --server-id, --log-bin, and --relay-log.
sudo mysqld --server-id=1 --log-bin=mysql-bin --relay-log=mysql-relay-bin

This command starts the MySQL server with replication enabled.
Running mysqld with GTIDs
You can enable Global Transaction Identifiers (GTIDs) for replication using the --gtid-mode and --enforce-gtid-consistency options.
sudo mysqld --gtid-mode=ON --enforce-gtid-consistency=ON

This command starts the MySQL server with GTIDs enabled.
Running mysqld with Performance Schema
You can enable the Performance Schema using the --performance-schema option.
sudo mysqld --performance-schema=ON

This command starts the MySQL server with the Performance Schema enabled.
Running mysqld with InnoDB
You can configure the MySQL server to use the InnoDB storage engine using various InnoDB-related options such as --innodb-buffer-pool-size and --innodb-log-file-size.
sudo mysqld --innodb-buffer-pool-size=1G --innodb-log-file-size=256M

This command starts the MySQL server with the specified InnoDB configuration.
Conclusion
mysqld is a powerful and versatile daemon that is essential for managing MySQL databases on a Linux system. It provides a wide range of options for configuring and running the MySQL server, making it an essential tool for database administrators.
By understanding and using the various options and commands available in mysqld, you can effectively manage your MySQL server and ensure its smooth operation.