1. ¿Cómo cambiar la contraseña del usuario root
# mysqladmin -u root -pxxx password 'yyy'
# mysql -u root -pyyy
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.0.67 MySQL Community Server (GPL)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
# mysql -u root -pyyy
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.0.67 MySQL Community Server (GPL)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
2. ¿Cómo chequear si el servidor MySQL está corriendo?
# mysqladmin -u root -p ping
Enter password:
mysqld is alive
Enter password:
mysqld is alive
3. ¿Cómo saber que versión de MySQL estoy corriendo?
# mysqladmin -u root -pxxx version
mysqladmin Ver 8.42 Distrib 5.0.67 on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 5.0.67
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 100 days 0 hours 0 min 0 sec
Threads: 1 Questions: 241986 Slow queries: 0 Opens: 11097
Flush tables: 2 Open tables: 32 Queries per second avg: 1.23
mysqladmin Ver 8.42 Distrib 5.0.67 on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 5.0.67
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 100 days 0 hours 0 min 0 sec
Threads: 1 Questions: 241986 Slow queries: 0 Opens: 11097
Flush tables: 2 Open tables: 32 Queries per second avg: 1.23
4. ¿Cuál es el estado actual del servidor MySQL?
# mysqladmin -u root -pxxx status
Uptime: 8640000
Threads: 1 Questions: 241986 Slow queries: 0 Opens: 11097
Flush tables: 2 Open tables: 32 Queries per second avg: 1.23
Uptime: 8640000
Threads: 1 Questions: 241986 Slow queries: 0 Opens: 11097
Flush tables: 2 Open tables: 32 Queries per second avg: 1.23
El comando status muestra la siguiente información:
- Uptime: segundos desde los que se inició el servidor
- Threads: numero total de clientes conectados
- Questions: número total de consultas que el servidor ha ejecutado desde desde su inicio.
- Slow queries: número total de consulta que el servidor ha ejecutado y que tienen un tiempo mayor de ejecución a la variable long_query_time.
- Opens: número total de tablas abiertas por el servidor.
- Flush tables: cuantas tablas han sido "volcadas".
- Open tables: número total de tablas abiertas en la base de datos.
5. ¿Cómo ver las variables de estado de MySQL y sus valores actuales?
# mysqladmin -u root -pxxx extended-status
+-----------------------------------+-----------+
| Variable_name | Value |
+-----------------------------------+-----------+
| Aborted_clients | 579 |
+-----------------------------------+-----------+
| Variable_name | Value |
+-----------------------------------+-----------+
| Aborted_clients | 579 |
6. ¿Cómo ver las variables del sistema de MySQL y sus valores?
# mysqladmin -u root -pxxx variables
+---------------------------------+---------------------------------+
| Variable_name | Value |
+---------------------------------+---------------------------------+
| auto_increment_increment | 1 |
+---------------------------------+---------------------------------+
| Variable_name | Value |
+---------------------------------+---------------------------------+
| auto_increment_increment | 1 |
7. ¿Cómo ver todos los procesos/consultas ejecutándose en la base de datos?
# mysqladmin -u root -pxxx processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost | | Sleep | 36 | | |
| 23 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost | | Sleep | 36 | | |
| 23 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
También puedes correr este comando automáticamente cada un segundo de la siguiente forma:
# mysqladmin -u root -pxxx -i 1 processlist
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost | | Sleep | 36 | | |
| 23 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 20 | root | localhost | | Sleep | 36 | | |
| 23 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 24 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 24 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
8. ¿Cómo crear una base de datos MySQL?
# mysqladmin -u root -pxxx create basedeprueba
9. ¿Cómo eliminar una base de datos MySQL?
# mysqladmin -u root -pxxx drop basedeprueba
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
Do you really want to drop the 'basedeprueba' database [y/N] y
Database “basedeprueba” dropped
Database “basedeprueba” dropped
10. ¿Cómo recargar/refrescar los privilegios de la tabla de permisos?
# mysqladmin -u root -pxxx reload;
El comando refresh hará un flush de todas las tablas y cerrará/abrirá los archivos de log.
# mysqladmin -u root -pxxx refresh;
11. ¿Cuál es el método seguro de detener el servidor MySQL?
# mysqladmin -u root -pxxx shutdown
12. Listado de todos los comandos flush
# mysqladmin -u root -pxxx flush-hosts
# mysqladmin -u root -pxxx flush-logs
# mysqladmin -u root -pxxx flush-privileges
# mysqladmin -u root -pxxx flush-status
# mysqladmin -u root -pxxx flush-tables
# mysqladmin -u root -pxxx flush-threads
# mysqladmin -u root -pxxx flush-logs
# mysqladmin -u root -pxxx flush-privileges
# mysqladmin -u root -pxxx flush-status
# mysqladmin -u root -pxxx flush-tables
# mysqladmin -u root -pxxx flush-threads
13. ¿Cómo matar un proceso pendiente de un cliente MySQL?
Previo a este comando es necesario identificar el thread a eliminar ejecutando el comando processlist de mysqladmin.
Previo a este comando es necesario identificar el thread a eliminar ejecutando el comando processlist de mysqladmin.
# mysqladmin -u root -pxxx kill 20
14. ¿Cómo iniciar y parar la replicación en un servidor esclavo?
# mysqladmin -u root -pxxx stop-slave
Slave stopped
Slave stopped
# mysqladmin -u root -pxxx start-slave
15. ¿Cómo combinar múltiples comandos de mysqladmin juntos?
# mysqladmin -u root -pxxx process status version
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 43 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
+----+------+-----------+----+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+-------+------------------+
| 43 | root | localhost | | Query | 0 | | show processlist |
+----+------+-----------+----+---------+------+-------+------------------+
Uptime: 3135
Threads: 1 Questions: 50 Slow queries: 1 Opens: 10 Flush tables: 2
Open tables: 0 Queries per second avg: 0.5
mysqladmin Ver 8.42 Distrib 5.0.67 on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Threads: 1 Questions: 50 Slow queries: 1 Opens: 10 Flush tables: 2
Open tables: 0 Queries per second avg: 0.5
mysqladmin Ver 8.42 Distrib 5.0.67 on i686
Copyright (C) 2000-2006 MySQL AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 5.0.67
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 52 min 15 sec
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 52 min 15 sec