I usually forget basic MySQL commands like checking the status and where is the configuration file. So, I collect the most useful and most used commands for MySQL in this post for a quick reference. Note that I use Ubuntu, so the the commands are Ubuntu-specific.
These commands are extremely useful, especially when you want to manage your own VPS or backup databases. Here we go:
Secure MySQL installation
This command is usually used after installing LAMP/LEMP on the server.
mysql_secure_installation
Start, stop, restart MySQL
systemctl start mysql
systemctl stop mysql
systemctl restart mysql
or
service mysql start
service mysql stop
service mysql restart
Check MySQL status
Checking if MySQL is active or not:
systemctl is-active mysql
For more advanced details, use:
systemctl status mysql
MySQL configuration file
/etc/mysql/ - Main MySQL server configuration directory
/etc/mysql/my.cnf - The MySQL database server configuration file
The my.cnf
simly loads config from these folders:
/etc/mysql/conf.d/
/etc/mysql/mariadb.conf.d/
In most cases, you might need to edit this file:
/etc/mysql/mariadb.conf.d/50-server.cnf