MySQL
Fact Finding
If you have just been given access to a server with some form of MySQL on it and you want to find out about it...
ps -ef | grep mysql
Will prove it's actually running and show who it's running as. Note that whichever user mysql is actually running as, you will normally need 'root' access to be able to manage MySQL.cat /etc/my.cnf
Will show you the config, or link you to the config, and may also give some hints as to what flavour of MySQL you are dealing with.e.g. Percona will link to these locations from /etc/my.cnf...!includedir /etc/my.cnf.d/!includedir /etc/percona-server.conf.d/
mysql -V
You might get lucky and be able to run the mysql client as your login user. Even better if you know some database users and their passwords.MySQL Status
sudo systemctl status mysqld
sudo service mysql status
Dec 12 13:46:36 nightingale systemd[1]: Stopped MySQL Community Server.Dec 12 13:46:36 nightingale systemd[1]: Starting MySQL Community Server...Dec 12 13:46:47 nightingale systemd[1]: Started MySQL Community Server.
mysql -uusername -p -estatus
Connection id: 11Current database: Current user: root@localhostSSL: Not in useCurrent pager: stdoutUsing outfile: ''Using delimiter: ;Server version: 8.0.18 MySQL Community Server - GPLProtocol version: 10Connection: Localhost via UNIX socketServer characterset: utf8mb4Db characterset: utf8mb4Client characterset: utf8mb4Conn. characterset: utf8mb4UNIX socket: /var/run/mysqld/mysqld.sockUptime: 16 min 26 sec
Threads: 2 Questions: 23 Slow queries: 0 Opens: 538 Flush tables: 4 Open tables: 35 Queries per second avg: 0.023--------------
sudo /etc/init.d/mysql status
This only works on some systems
MySQL Start
Linux
sudo systemctl start mysqld
sudo service mysql start
Windows
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld"
or (assuming a MySQL Windows Service has been configured)
sc start mysqld_service_name
or
NET START mysqld_service_name
MySQL Stop
Linux
sudo service mysql stop
Windows
"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqladmin" -u root shutdown -p
or (assuming a MySQL Windows Service has been configured)
sc stop mysqld_service_name
or
NET STOP mysqld_service_name
MySQL Version
mysql -V
If there are no firewalls blocking your route, you can also get basic version information using telnet or nc...
telnet myserver 3306
nc myserver 3306
Example output from nc...
U8.0.23-commercial(h(Mj3_*n▒▒▒▒▒5ek-*(1LNcaching_sha2_password^CMySQL Uptime
SHOW GLOBAL STATUS LIKE 'Uptime';
SELECT TIME_FORMAT(SEC_TO_TIME(VARIABLE_VALUE ),'%Hh %im') AS Uptime
FROM information_schema.GLOBAL_STATUS
WHERE VARIABLE_NAME='Uptime';
MySQL Run Script
source /path/script.sql
MySQL Architecture
Bibliography
https://support.oracle.com/portal/ https://www.oracle.com/technical-resources/ https://docs.oracle.com/en/database/other-databases/index.html
https://snippets.khromov.se/show-mysql-server-uptime-using-a-query/
https://stackoverflow.com/questions/3927690/howto-clean-a-mysql-innodb-storage-engine/4056261#4056261
Best Practiceshttps://smit90.medium.com/mysql-best-practices-optimizing-performance-and-reliability-with-advanced-concepts-c4f5ebedbcbe
Perconahttps://www.percona.com/doc/percona-server/LATEST/feature_comparison.htmlhttps://docs.percona.com/percona-server/8.0/feature-comparison.html
Windowshttps://dev.mysql.com/doc/refman/8.0/en/windows-start-command-line.html https://dev.mysql.com/doc/refman/8.0/en/windows-start-service.html https://dev.mysql.com/doc/refman/8.0/en/windows-restrictions.html