SET GLOBAL event_scheduler = ON;
CREATE EVENT mievento
ON SCHEDULE EVERY 1 HOUR
STARTS CURRENT_TIMESTAMP
DO
DELETE FROM tblreseteopass WHERE creado <= DATE_SUB(CURTIME(), INTERVAL 2 DAY);
/* Affected rows: 0 Filas encontradas: 0 Advertencias: 0 Duración para 1 query: 0,047 sec. */
ALTER EVENT mievento
ON SCHEDULE EVERY 10 MINUTE
STARTS CURRENT_TIMESTAMP
DO
DELETE FROM tblreseteopass WHERE creado <= DATE_SUB(CURTIME(), INTERVAL 5 MINUTE);
/* Affected rows: 0 Filas encontradas: 0 Advertencias: 0 Duración para 1 query: 0,000 sec. */
MariaDB [test]> SET GLOBAL event_scheduler = ON;
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> show create event mievento1 \G
*************************** 1. row ***************************
Event: mievento1
sql_mode: STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
time_zone: SYSTEM
Create Event: CREATE /* DEFINER=`root`@`localhost` */ EVENT `mievento` ON SCHEDULE EVERY 10 MINUTE STARTS '2016-09-17 11:06:09' ON COMPLETION NOT PRESERVE ENABLE DO DELETE FROM tbl_test WHERE creado <= DATE_SUB(CURTIME(), INTERVAL 5 MINUTE)
character_set_client: utf8mb4
collation_connection: utf8mb4_general_ci
Database Collation: utf8_general_ci
1 row in set (0.00 sec)
DROP EVENT mievento;
O podemos detener el event_scheduler con el siguiente comando:
SET GLOBAL event_scheduler = OFF;
Archivo por meses: septiembre 2016
Ejecutar php sin servidor web
Hoy continuo realizando un proyecto, he tenido la necesidad de ver vía navegador parte de código antiguo que esta en php, pues bien, normalmente suelo ejecutar :
python -m SimpleHTTPServer 80
or
python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 ...
192.168.1.90 - - [08/Sep/2016 08:40:21] "GET / HTTP/1.1" 200 -
192.168.1.90 - - [08/Sep/2016 08:40:51] "GET /test HTTP/1.1" 200 -
Esto va muy bien si lo que necesitas ver es html o descargar algún fichero, normalmente lo utilizo para descargar algún pdf o música al móvil, entre otras.
El problema que surgía hoy es que tenia un antiguo proyecto en php, puedo arrancar alguna maquina virtual, subir el proyecto y listo, pero, por que no lo puedo visualizar desde mi equipo tal y como esta, la solución esta en php.
En mi caso como ejecutable php tengo el siguiente binario :
/usr/bin/php5
Este lo utilizo por consola para ejecutar algunos scripts en php.
Ahora bien, ¿como hago para poder poner en escucha el equipo en el puerto 80 y poder interpretar en código php?
Se hace de la siguiente forma:
Accedemos como superuser al directorio donde tenemos nuestro código php y ejecutamos:
php5 -S 127.0.0.1:80 -t .
php5 [options] -S <addr>:<port> [-t docroot]
Si os fijáis hay un punto al final, este indica el directorio actual, también podríamos indicar el directorio a publicar :
php5 -S 127.0.0.1:80 -t /home/test/project_php
De esta forma se pone a la escucha.
PHP 5.6.17-3 Development Server started at Thu Sep 8 08:26:26 2016
Listening on https://127.0.0.1:80
Document root is /home/test/project_php
Press Ctrl-C to quit.
Si accedemos vía navegador, veremos como se ejecuta correctamente:
También podemos observar a que fichero hemos accedido, con su código de estado:
PHP 5.6.17-3 Development Server started at Thu Sep 8 08:26:26 2016
Listening on https://127.0.0.1:80
Document root is /home/test/project_php
Press Ctrl-C to quit.
[Thu Sep 8 08:27:45 2016] 127.0.0.1:60148 [200]: /info.php
php5 -S 192.168.1.90:80 -t /home/test/project_php
PHP 5.6.17-3 Development Server started at Thu Sep 8 08:36:21 2016
Listening on https://192.168.1.35:80
Document root is /home/test/project_php
Press Ctrl-C to quit.
[Thu Sep 8 08:36:25 2016] 192.168.1.33:60045 [200]: /info.php
[Thu Sep 8 08:36:26 2016] 192.168.1.33:60046 [404]: /favicon.ico - No such file or directory
[Thu Sep 8 08:36:26 2016] 192.168.1.33:60047 [404]: /favicon.ico - No such file or directory
Bien de una forma u otra podemos interpretar el código php para visualizarlo en el navegador, también recordemos como lo hemos hecho con python.
Mysql consultas
SELECT table_name AS "Tables", round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" FROM information_schema.TABLES ORDER BY (data_length + index_length) DESC;
SELECT TABLE_SCHEMA AS 'Database', TABLE_NAME AS 'Table', CONCAT(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2)," Mb") AS Size FROM INFORMATION_SCHEMA.TABLES;
SELECT TABLE_SCHEMA AS 'Database', TABLE_NAME AS 'Table', CONCAT(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2)," MB") AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '%YOUR_DB_NAME%' ;
SELECT CONCAT(sum(ROUND(((DATA_LENGTH + INDEX_LENGTH - DATA_FREE) / 1024 / 1024),2))," MB") AS Size FROM INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA like '%YOUR_DB_NAME%' ;
SELECT table_schema "databases", sum( data_length + index_length ) / 1024 / 1024 "data length", sum( data_free )/ 1024 / 1024 "data free" FROM info
rmation_schema.TABLES GROUP BY table_schema ;
SELECT unix_timestamp()-31*86400 "unix time";
SELECT count(*) TABLES, concat(round(sum(table_rows)/1000000,2),'K') rows, concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA, concat(round(sum(index_length)/(1024*1024*1024),2),'G') index, concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size, round(sum(index_length)/sum(data_length),2) indexfrac FROM information_schema.TABLES;
SELECT count(*) TABLES,table_schema,concat(round(sum(table_rows)/1000000,2),'M') rows, concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA, concat(round(sum(index_length)/(1024*1024*1024),2),'G') index, concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size, round(sum(index_length)/sum(data_length),2) indexfrac FROM information_schema.TABLES GROUP BY table_schema ORDER BY sum(data_length+index_length) DESC LIMIT 10;
SELECT engine, count(*) TABLES, concat(round(sum(table_rows)/1000000,2),'M') rows, concat(round(sum(data_length)/(1024*1024*1024),2),'G') DATA, concat(round(sum(index_length)/(1024*1024*1024),2),'G') index, concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size, round(sum(index_length)/sum(data_length),2) indexfrac FROM information_schema.TABLES GROUP BY engine ORDER BY sum(data_length+index_length) DESC LIMIT 10;
Reset password user Mysql
Hi all,
Working on a project Today I found I needed the password of user admin mysql database in windows, as well to perform the reset of the database execute the following command :
mysqld.exe -u admin --skip-grant-tables
Then:
mysql.exe
select user from mysql.user;
update mysql.user set password = password('new password') where user = 'admin';
flush privileges;
\q
And this is all
C:\Parallels\Plesk\Databases\MySQL51\bin>mysql -u admin -p
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73-community MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.02 sec)