LinuxCommandLibrary

mysqld

Start the MySQL database server

TLDR

Start the MySQL database server

$ mysqld
copy

Start the server, printing error messages to the console
$ mysqld --console
copy

Start the server, saving logging output to a custom log file
$ mysqld --log=[path/to/file.log]
copy

Print the default arguments and their values and exit
$ mysqld --print-defaults
copy

Start the server, reading arguments and values from a file
$ mysqld --defaults-file=[path/to/file]
copy

Start the server and listen on a custom port
$ mysqld --port=[port]
copy

Display help
$ mysqld --verbose --help
copy

SYNOPSIS

mysqld [options]

PARAMETERS

--basedir=path
    Specifies the base directory of the MySQL installation.

--datadir=path
    Defines the directory where MySQL stores its databases and tables.

--port=num
    Sets the TCP/IP port number that the server listens on for network connections (default: 3306).

--socket=path
    Specifies the Unix socket file path for local connections (default: /tmp/mysql.sock).

--user=name
    Runs the mysqld process as the specified system user for security reasons.

--log-error=file
    Directs server error messages and startup information to the specified file.

--pid-file=file
    Specifies the path for the file where the server writes its process ID (PID).

--defaults-file=file
    Reads default options from the specified configuration file instead of standard locations.

--skip-networking
    Disables TCP/IP networking, allowing connections only through the Unix socket file (for local access).

--help
    Displays a help message with all supported options and exits.

--version
    Displays the server version information and exits.

DESCRIPTION

The mysqld command is the primary executable for the MySQL database server. It is the core daemon process that runs in the background, listening for client connections, managing data storage, and processing all database queries. When mysqld is running, it handles tasks such as creating, reading, updating, and deleting data, managing users and permissions, and ensuring data integrity. It's the central component that makes the MySQL/MariaDB database system functional, allowing applications and users to interact with their databases.

CAVEATS

Running mysqld directly from the command line is generally not recommended for production environments. It's often better to use wrapper scripts like mysqld_safe or system service managers (like systemd or SysVinit) for proper management, logging, and process control. Security is paramount: ensure mysqld runs as a dedicated, unprivileged user. Be mindful of resource consumption (memory, CPU, disk I/O) as the database workload increases.

CONFIGURATION FILES

mysqld typically reads its configuration from files named `my.cnf` or `mysqld.cnf` located in standard paths (e.g., `/etc/my.cnf`, `/etc/mysql/my.cnf`, `~/.my.cnf`, or the data directory). These files allow persistent configuration settings without needing to specify them on the command line every time.

RUNNING <B>MYSQLD</B>

While mysqld can be invoked directly, it's commonly started via `mysqld_safe` (a wrapper script that adds safety features like error logging and restart capabilities) or, more often on modern Linux systems, managed as a service using `systemctl start mysql` (or `mariadb`) which handles the intricacies of process management, logging, and startup/shutdown.

HISTORY

MySQL was originally created by MySQL AB, a Swedish company, in the mid-1990s. Its core daemon, mysqld, quickly became a cornerstone of the LAMP (Linux, Apache, MySQL, PHP/Perl/Python) stack, driving countless web applications. Acquired by Sun Microsystems in 2008 and subsequently by Oracle in 2010, its open-source nature led to the creation of forks like MariaDB, which also uses a very similar mysqld daemon, maintaining much of the original command's functionality and interface.

SEE ALSO

mysql(1), mysqladmin(1), mysqld_safe(1), mysql_install_db(1), systemctl(1), service(8)

Copied to clipboard