MySQL Tutorials - Herong's Tutorial Examples - v4.46, by Herong Yang
Manage MySQL Server 'mysqld' on CentOS
This section provides a tutorial example on how to start and stop MySQL server program 'mysqld' as a system service on CentOS 8 systems using the 'systemctl' command.
After install MySQL server with the "yum" command CentOS Linux systems, you need to learn how to manage it. The first task is to start or stop the MySQL server. Here is what I did on my CentOS 8 computer.
1. Check MySQL server status. I see an error message, because the it is not running.
herong$ mysqladmin status mysqladmin: connect to server at 'localhost' failed error: 'Can't connect to local MySQL server through socket ... Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!
2. Start MySQL server as a system service: I see an error message, because it is not enabled on CentOS 8.
herong$ sudo systemctl start mysqld.service Failed to start mysqld.service: Unit mysqld.service not found.
3. Enable MySQL server as a system service.
herong$ sudo systemctl enable mysqld.service Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service /usr/lib/systemd/system/mysqld.service.
4. Check MySQL server status again. I see the server is running. And there is no password for the "root" user!
herong$ mysqladmin status -u root -p Enter password: <Enter> Uptime: 82 Threads: 2 Questions: 5 Slow queries: 0 Opens: 115 Flush tables: 3 Open tables: 35 Queries per second avg: 0.060
5. Stop MySQL server.
herong$ sudo systemctl stop mysqld.service
6. Start MySQL server again.
herong$ sudo systemctl start mysqld.service
7. Connect to MySQL Server with "mysql" client program:
herong$ mysql -u root -p Enter password: <Enter> ... mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+
Cool. I am able to start and stop MySQL server as a system service on my CentOS 8 computer.
You can also use the "service" command, which actually calls the "systemctl" command, to start and stop MySQL server:
herong$ sudo service mysqld start herong$ sudo service mysqld stop
But, do not try to run the MySQL server program, mysqld, directly. You will run into errors.
herong$ sudo mysqld [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.17) starting as process 15754 [ERROR] [MY-010123] [Server] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root! [ERROR] [MY-010119] [Server] Aborting [System] [MY-010910] [Server] /usr/libexec/mysqld: Shutdown complete (mysqld 8.0.17) Source distribution.
Table of Contents
MySQL Introduction and Installation
Introduction of MySQL Programs
Perl Programs and MySQL Servers
Java Programs and MySQL Servers
Character Strings and Bit Strings
Table Column Types for Different Types of Values
Using DDL to Create Tables and Indexes
Using DML to Insert, Update and Delete Records
Using SELECT to Query Database
Window Functions for Statistical Analysis
Use Index for Better Performance
Transaction Management and Isolation Levels
Defining and Calling Stored Procedures
Variables, Loops and Cursors Used in Stored Procedures
System, User-Defined and Stored Procedure Variables
Storage Engines in MySQL Server
InnoDB Storage Engine - Primary and Secondary Indexes
Performance Tuning and Optimization
►Installing MySQL Server on Linux
Install MySQL Database Server on CentOS
►Manage MySQL Server 'mysqld' on CentOS
Set MySQL Server "root" Password on CentOS
MySQL Server File Locations on CentOS
MySQL Server Data Backups on CentOS
MySQL Server Log Files on CentOS
"Multiple files found for the same tablespace ID" Error