MariaDB – Admin – mysqladmin

mysqladmin is used to run commands against mysqld daemon

XREF to this doc for info: http://www.ewhathow.com/2013/09/how-to-check-if-mysql-server-is-running-on-linux/
XREF to this MariaDB doc: https://mariadb.com/kb/en/mariadb/mysqladmin/

Q: How to check if MySQL Process is running?
A: ps aux | grep mysql
mysql 9555 0.0 7.2 774240 133436 ? Ssl 14:17 0:02 /usr/sbin/mysq d
paul 9713 0.0 0.2 162420 4212 pts/0 T 15:02 0:00 mysql -u root -p
root 9812 0.0 0.0 112640 964 pts/0 S+ 15:29 0:00 grep –color=auto mysql
Note: ERROR! MySQL is running but PID file could not be found

Q: Logged in as root, is mysqladmin running?
A: mysqladmin status
Note: mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘root’@’localhost’ (using password: NO)’
Note: Issue is that syntax requires authentication

Q: How to check mysqladmin running?
A: mysqladmin -u root -p status (Note: Enter password I have for database system)
Uptime: 4748 Threads: 2 Questions: 27 Slow queries: 0 Opens: 0 Flush tables: 1 Open tables: 11 Queries per second avg: 0.005

Q: As an experiment, stop the SQL service, check for mysqladmin running, start the service again
A: sudo systemctl stop mariadb.service
A: mysqladmin -u root -p status
Note: mysqladmin: connect to server at ‘localhost’ failed
error: ‘Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2 “No such file or directory”)’
Check that mysqld is running and that the socket: ‘/var/lib/mysql/mysql.sock’ exists!
A: sudo systemctl start mariadb.service
A: mysqladmin -u root -p status
Note: Uptime: 7 Threads: 1 Questions: 1 Slow queries: 0 Opens: 0 Flush tables: 1 Open tables: 11 Queries per second avg: 0.142
Summary: Output of “mysqladmin status” will give a definite answer on whether the MySQL service is running.

Q: How to check status of mysql service (because I’m using CentOS)
A: service mysql status
Note: ERROR! MySQL is running but PID file could not be found
Note: Instructions within here to fix this: http://geeksterminal.com/fix-mysql-is-running-but-pid-file-could-not-be-found-error/342/

Q: What is the PID file that it was referring to?

Q: What happens when I enter: mysqladmin -u root -p (and enter the database system password)?
mysqladmin Ver 9.1 Distrib 10.1.8-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Administration program for the mysqld daemon.
Usage: mysqladmin [OPTIONS] command command….

Default options are read from the following files in the given order:
/etc/my.cnf ~/.my.cnf
The following groups are read: mysqladmin client client-server client-mariadb
The following options may be given as the first argument:
–print-defaults Print the program argument list and exit.
–no-defaults Don’t read default options from any option file.
–defaults-file=# Only read default options from the given file #.
–defaults-extra-file=# Read this file after the global files are read.

-c, –count=# Number of iterations to make. This works with -i
(–sleep) only.
–debug-check Check memory and open file usage at exit.
–debug-info Print some debug info at exit.
-f, –force Don’t ask for confirmation on drop database; with
multiple commands, continue even if an error occurs.
-C, –compress Use compression in server/client protocol.
–character-sets-dir=name
Directory for character set files.
–default-character-set=name
Set the default character set.
-?, –help Display this help and exit.
-h, –host=name Connect to host.
-b, –no-beep Turn off beep on error.
-p, –password[=name]
Password to use when connecting to server. If password is
not given it’s asked from the tty.
-P, –port=# Port number to use for connection or 0 for default to, in
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/services, built-in default (3306).
–protocol=name The protocol to use for connection (tcp, socket, pipe,
memory).
-r, –relative Show difference between current and previous values when
used with -i. Currently only works with extended-status.
-s, –silent Silently exit if one can’t connect to server.
-S, –socket=name The socket file to use for connection.
-i, –sleep=# Execute commands repeatedly with a sleep between.
–ssl Enable SSL for connection (automatically enabled with
other flags).
–ssl-ca=name CA file in PEM format (check OpenSSL docs, implies
–ssl).
–ssl-capath=name CA directory (check OpenSSL docs, implies –ssl).
–ssl-cert=name X509 cert in PEM format (implies –ssl).
–ssl-cipher=name SSL cipher to use (implies –ssl).
–ssl-key=name X509 key in PEM format (implies –ssl).
–ssl-crl=name Certificate revocation list (implies –ssl).
–ssl-crlpath=name Certificate revocation list path (implies –ssl).
–ssl-verify-server-cert
Verify server’s “Common Name” in its cert against
hostname used when connecting. This option is disabled by
default.
-u, –user=name User for login if not current user.
-v, –verbose Write more information.
-V, –version Output version information and exit.
-E, –vertical Print output vertically. Is similar to –relative, but
prints output vertically.
-w, –wait[=#] Wait and retry if connection is down.
–connect-timeout=#
–shutdown-timeout=#
–plugin-dir=name Directory for client-side plugins.
–default-auth=name Default authentication client-side plugin to use.

Variables (–variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
——————————— —————————————-
count 0
debug-check FALSE
debug-info FALSE
force FALSE
compress FALSE
character-sets-dir (No default value)
default-character-set auto
host (No default value)
no-beep FALSE
port 0
relative FALSE
socket (No default value)
sleep 0
ssl FALSE
ssl-ca (No default value)
ssl-capath (No default value)
ssl-cert (No default value)
ssl-cipher (No default value)
ssl-key (No default value)
ssl-crl (No default value)
ssl-crlpath (No default value)
ssl-verify-server-cert FALSE
user root
verbose FALSE
vertical FALSE
connect-timeout 43200
shutdown-timeout 3600
plugin-dir (No default value)
default-auth (No default value)

Where command is a one or more of: (Commands may be shortened)
create databasename Create a new database
debug Instruct server to write debug information to log
drop databasename Delete a database and all its tables
extended-status Gives an extended status message from the server
flush-all-statistics Flush all statistics tables
flush-all-status Flush status and statistics
flush-client-statistics Flush client statistics
flush-hosts Flush all cached hosts
flush-index-statistics Flush index statistics
flush-logs Flush all logs
flush-privileges Reload grant tables (same as reload)
flush-slow-log Flush slow query log
flush-status Clear status variables
flush-table-statistics Clear table statistics
flush-tables Flush all tables
flush-threads Flush the thread cache
flush-user-statistics Flush user statistics
kill id,id,… Kill mysql threads
password [new-password] Change old password to new-password in current format
old-password [new-password] Change old password to new-password in old format
ping Check if mysqld is alive
processlist Show list of active threads in server
reload Reload grant tables
refresh Flush all tables and close and open logfiles
shutdown Take server down
status Gives a short status message from the server
start-slave Start slave
stop-slave Stop slave
variables Prints variables available
version Get version info from server

Q: Why do I have to enter the password each time I run a mysqladmin command?
A: Because that’s the way it is
Note: mysqladmin -u root -p ping — responds with “mysqld is alive”, but I have to enter password each time

Q: What are some mysqladmin commands I can play with?
A: http://www.tecmint.com/mysqladmin-commands-for-database-administration-in-linux/

Q: How to change the password for root?
A: mysqladmin -u root -p123456 password ‘xyz123’
Note: p123456 was old password and xyz123 is new

Q: How to check if MariaDB/MySQL is running?
A: mysqladmin -u root -p ping
Note: Comes back with, “mysqld is alive”

Q: How to check which version of MariaDB is running?
A: mysqladmin -u root -p version
mysqladmin Ver 9.1 Distrib 10.1.8-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Server version 10.1.8-MariaDB
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 16 hours 46 min 1 sec
Threads: 1 Questions: 8 Slow queries: 0 Opens: 0 Flush tables: 1 Open tables: 11 Queries per second avg: 0.000

Q: How to check status of server, so see threads?
A: mysqladmin -u root -p status
Uptime: 60501 Threads: 1 Questions: 9 Slow queries: 0 Opens: 0 Flush tables: 1 Open tables: 11 Queries per second avg: 0.000

Q: How to check all the running processes?
A: mysqladmin -u root -p processlist
+—-+——+———–+—-+———+——+——-+——————+———-+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+—-+——+———–+—-+———+——+——-+——————+———-+
| 19 | root | localhost | | Query | 0 | init | show processlist | 0.000 |
+—-+——+———–+—-+———+——+——-+——————+———-+

Q: How to create a database?
A: mysqladmin -u root -p create databasename

Q: How to show databases
A: First, go into MariaDB Monitor with – mysql -u root -p
A: show databases;
— +——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| test |
+——————–+
4 rows in set (0.00 sec)

Q: How to Drop (AKA Delete, including all tables) a database? This should be done with caution as the data is destroyed.
A: mysqladmin -u root -p drop databasename

Q: How to shutdown MariaDB safely?
A: mysqladmin -u root -p shutdown

Q: Another way of how to shutdown MariaDB?
A: sudo systemctl stop mariadb.service

Q: How to start a server?
A: sudo systemctl start mariadb.service

Q: How to kill a sleeping process?
A: First, find the current processes with — mysqladmin -u root -p processlist
A: mysqladmin -u root -p kill 5,10
Note: The Process ID’s are 5 and 10 — if multiple processes you separate with a comma

Q: How to run multiple commands at same time?
A: mysqladmin -u root -p status version ping
Note: Put a space between each command

About Paul

CERT Coordinator, Ham Radio Operator, GTD Fan; Photographer; Domino/Notes Administrator
This entry was posted in Linux. Bookmark the permalink.