Abrir una ventana de comandos y ejecutara el comando netstat con las opciones del ejemplo
netstat -anob
obtendremos un listados de los procesos utilizados, los puertos usados ...
viernes, 27 de junio de 2014
mysql - Sintaxis para conectar con servidor mysql por linea de comandos
Sintaxis para conectar con servidor mysql por linea de comandos
mysql -u DBUSER -h DBSERVERNAME -p
A continuacion pedirá la contraseña de acceso
Fuente: http://www.cyberciti.biz/faq/how-to-connect-to-my-mysql-database-server-using-command-line-and-php/
mysql -u DBUSER -h DBSERVERNAME -p
A continuacion pedirá la contraseña de acceso
Fuente: http://www.cyberciti.biz/faq/how-to-connect-to-my-mysql-database-server-using-command-line-and-php/
martes, 17 de junio de 2014
system Error. Code: 5. Al intentar instalar un servicio en windows bajo el comando MS-DOS servicio.exe /install
Este error se produce por directivas de privilegios en windows. Para solucionarlo basta con ejecutar la aplicacion de CMD.EXE (MS_DOS) con privilegios de administrador. Botón derecho sobre la aplicacion ejecutar como adminitrador. Al lanzar el comando con privilegios de administrador no tendremos ningun problema.
Suerte
lunes, 16 de junio de 2014
Pasar por get una variable que contiene el caracter # almohadilla o caracteres especiales en ASP.NET C#
Realizando una aplicación en ASP.NET y C# me encontré con un problema. Tenia que pasar una variable por metodo GET y ésta contenia el caracter almohadilla #. Para solucionarlo ASP.NET C# dispone de la funcion
URL = 'http://www.dominio.com?nombre_variable=' + System.Web.HttpUtility.UrlEncode(VARIABLE_QUE_CONTIENE_CARACTERES_ESPECIALES);
Utilizando una cadena constante en lugar de Variable sería algo asi...
URL = 'http://www.dominio.com?nombre_variable=' + System.Web.HttpUtility.UrlEncode('###00012');
Suerte.
Fuente: http://stackoverflow.com/questions/3840762/how-do-you-urlencode-without-using-system-web
System.Web.HttpUtility.UrlEncode();
Asi que basta con construir nuestra cadena utilizando esta función del siguiente modoURL = 'http://www.dominio.com?nombre_variable=' + System.Web.HttpUtility.UrlEncode(VARIABLE_QUE_CONTIENE_CARACTERES_ESPECIALES);
Utilizando una cadena constante en lugar de Variable sería algo asi...
URL = 'http://www.dominio.com?nombre_variable=' + System.Web.HttpUtility.UrlEncode('###00012');
Suerte.
Fuente: http://stackoverflow.com/questions/3840762/how-do-you-urlencode-without-using-system-web
Obtener informacion sobre una tabla mysql: collation, numero de registros, valor de auto_increment ..
Para consultar la información sobre el estado de una tabla en mysql utilizaremos la sintaxis
SHOW TABLE STATUS like 'NOMBRE_DE_MI_TABLA'
Nos devolvera multitud de información muy util.
3.7.5.38
Fuente:
http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html
SHOW TABLE STATUS like 'NOMBRE_DE_MI_TABLA'
Nos devolvera multitud de información muy util.
3.7.5.38 SHOW TABLE STATUS Syntax
SHOW TABLE STATUS [{FROM | IN} db_name]
[LIKE 'pattern' | WHERE expr]
SHOW TABLE STATUS works likes SHOW TABLES, but provides a lot of information about each non-TEMPORARYtable. You can also get this list using the mysqlshow --status db_name command. The LIKE clause, if present, indicates which table names to match. The WHERE clause can be given to select rows using more general conditions, as discussed in Section 20.27, “Extensions to SHOW Statements”.
This statement also displays information about views.
SHOW TABLE STATUS output has the following columns:NameThe name of the table.EngineThe storage engine for the table. See Chapter 14, Storage Engines.VersionThe version number of the table's.frmfile.Row_formatThe row-storage format (Fixed,Dynamic,Compressed,Redundant,Compact). ForMyISAMtables, (Dynamiccorresponds to what myisamchk -dvv reports asPacked. The format ofInnoDBtables is reported asRedundantorCompact. For theBarracudafile format of theInnoDB Plugin, the format may beCompressedorDynamic.RowsThe number of rows. Some storage engines, such asMyISAM, store the exact count. For other storage engines, such asInnoDB, this value is an approximation, and may vary from the actual value by as much as 40 to 50%. In such cases, useSELECT COUNT(*)to obtain an accurate count.TheRowsvalue isNULLfor tables in theINFORMATION_SCHEMAdatabase.Avg_row_lengthThe average row length.Data_lengthThe length of the data file.Max_data_lengthThe maximum length of the data file. This is the total number of bytes of data that can be stored in the table, given the data pointer size used.Index_lengthThe length of the index file.Data_freeThe number of allocated but unused bytes.Beginning with MySQL 5.1.24, this information is also shown forInnoDBtables (previously, it was in theCommentvalue).InnoDBtables report the free space of the tablespace to which the table belongs. For a table located in the shared tablespace, this is the free space of the shared tablespace. If you are using multiple tablespaces and the table has its own tablespace, the free space is for only that table. Free space means the number of completely free 1MB extents minus a safety margin. Even if free space displays as 0, it may be possible to insert rows as long as new extents need not be allocated.For partitioned tables, this value is only an estimate and may not be absolutely correct. A more accurate method of obtaining this information in such cases is to query theINFORMATION_SCHEMA.PARTITIONStable, as shown in this example:SELECT SUM(DATA_FREE) FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA = 'mydb' AND TABLE_NAME = 'mytable';For more information, see Section 20.11, “TheINFORMATION_SCHEMA PARTITIONSTable”.Auto_incrementThe nextAUTO_INCREMENTvalue.Create_timeWhen the table was created.Update_timeWhen the data file was last updated. For some storage engines, this value isNULL. For example,InnoDBstores multiple tables in its system tablespace and the data file timestamp does not apply. Even with file-per-table mode with eachInnoDBtable in a separate.ibdfile, change buffering can delay the write to the data file, so the file modification time is different from the time of the last insert, update, or delete. ForMyISAM, the data file timestamp is used; however, on Windows the timestamp is not updated by updates so the value is inaccurate.Check_timeWhen the table was last checked. Not all storage engines update this time, in which case the value is alwaysNULL.CollationThe table's character set and collation.ChecksumThe live checksum value (if any).Create_optionsExtra options used withCREATE TABLE. The original options supplied whenCREATE TABLEis called are retained and the options reported here may differ from the active table settings and options.CommentThe comment used when creating the table (or information as to why MySQL could not access the table information).Before MySQL 5.1.24, free space forInnoDBtables is reported in the comment. As of 5.1.24, it is reported in theData_freecolumn.
For
MEMORY tables, the Data_length, Max_data_length, and Index_length values approximate the actual amount of allocated memory. The allocation algorithm reserves memory in large amounts to reduce the number of allocation operations.
For
NDBCLUSTER tables, the output of this statement shows appropriate values for the Avg_row_length andData_length columns, with the exception that BLOB columns are not taken into account. Prior to MySQL 5.1.21, the number of MySQL Cluster replicas was shown in the Comment column as number_of_replicas (Bug #11379).
For views, all the fields displayed by
SHOW TABLE STATUS are NULL except that Name indicates the view name andComment says view.
Copyright © 1997, 2014, Oracle and/or its affiliates. All rights reserved. Legal Notices
Fuente:
http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html
Suscribirse a:
Comentarios (Atom)
Jesús Moreno - Ingeniero Ténico Informático - consultor Informático
Hola, soy Jesús Moreno Ingeniero Técnico Informático en sistemas por la US y propietario de éste blog. Mi trabajo en los ultimos años se ...
-
Para aquellos que tengáis el gusanillo de la numismática, queréis empezar a coleccionar y no podéis o no queréis hacer una gran inversión en...
-
Al intentar compartir la impresora nos lanza un error que dice: " No se pudo guardar la configuración de la impresora. No hay no hay m...
-
Un método rápido y eficaz en 5 sencillos pasos: 1.- Desde SQL Management nos conectamos a nuestro servidor SQL Sercer y extraemos el met...

User Comments
<?php
mysql_connect("localhost","root","");$result = mysql_query("SHOW TABLE STATUS FROM test;");
while($array = mysql_fetch_array($result)) {$total = $array[Data_length]+$array[Index_length];
echo '
Table: '.$array[Name].'<br />
Data Size: '.$array[Data_length].'<br />
Index Size: '.$array[Index_length].'<br />
Total Size: '.$total.'<br />
Total Rows: '.$array[Rows].'<br />
Average Size Per Row: '.$array[Avg_row_length].'<br /><br />
';
}?>
This script is a hack. Feel free to improve and post.
For some reason, I can't get it to format nicely, either.
#!/opt/gnu/bin/perl -w
use strict;
use Getopt::Long;
my @options;
# Get output immediately. It won't hurt performance.
use FileHandle;
autoflush STDERR;
autoflush STDOUT;
my $pw;
push(@options, "password=s", \$pw);
my $host = "localhost";
push(@options, "host=s", \$host);
die "Couldn't parse options" if !GetOptions(@options);
die "Must give -password\n" if !defined($pw);
my $cmd = mysql_cmd("show databases");
open(CMD, $cmd) or die "Couldn't $cmd: $!\n";
my @databases;
my $header = <CMD>;
while ( <CMD> ) {
s/[\r\n]$//g;
#print "$_\n";
push (@databases, $_);
}
close(CMD);
#print "@databases";
my %colmap = ( 'Data_length' => 6,
'Index_length' => 8,
'Engine' => 1,
'Comment' => 17 );
my %size;
my %total_size;
my %engine_map;
my $inno_db_free;
foreach my $db (@databases) {
print STDERR ".";
$cmd = mysql_cmd("use $db; show table status");
open(CMD, $cmd) or die "Couldn't $cmd: $!\n";
my $header = <CMD>;
my $total_size = 0;
if (defined($header)) {
$header =~ s/[\r\n]$//g;
my @head = split("\t", $header);
foreach my $col (keys %colmap) {
die "$db: Expected '$col', found '" . $head[$colmap{$col}] . "'"
if $head[$colmap{$col}] ne $col;
}
while (<CMD>) {
my @data = split("\t");
my ($data_length, $index_length) = @data[6,8];
my ($engine, $comment) = @data[1,17];
$engine_map{$engine}++;
$size{$db}{$engine} += $data_length + $index_length;
$total_size{$db} += $data_length + $index_length;
if ( $comment =~ /InnoDB free: (\d+) kB/ ) {
die "Found two different inno DB free sized.\n"
if defined($inno_db_free) && $inno_db_free != $1;
$inno_db_free = $1;
}
}
close(CMD);
}
}
print STDERR "\n";
print "NOTE: All numbers are in megabytes (M).\n";
printf("Inno DB free: %.1f\n", $inno_db_free / 1024)
if defined($inno_db_free);
printf("%-30s ", "database");
foreach my $engine (sort keys(%engine_map)) {
printf "%7s ", $engine;
}
printf "%8s", "total";
print "\n";
foreach my $db (sort {$total_size{$b} <=> $total_size{$a}} keys %total_size) {
printf("%-30s ", $db);
foreach my $engine (sort keys(%engine_map)) {
my $size= $size{$db}{$engine};
$size = 0 if !defined($size);
printf("%7.1f ", $size / 1024 / 1024);
}
printf("%8.1f\n", $total_size{$db} / 1024 / 1024);
}
sub mysql_cmd {
my $mysql_cmd = shift;
return "mysql -uroot -h$host -p$pw -e '$mysql_cmd'|";
}
Example output:
% ./db-space.pl -p ...
....................
NOTE: All numbers are in megabytes (M).
Inno DB free: 10755.0
database HEAP InnoDB MyISAM total
tldan 0.0 339.1 720.3 1059.4
ml3test7 0.0 1010.8 0.0 1010.8
ml3test6 0.0 930.4 0.0 930.4
test 0.0 655.4 0.0 655.4
blarg4 0.0 39.5 0.0 39.5
The way the foreign key info is stored in the Comment field can be a pain to parse. Here's a snippet of PHP code that shows how to do this.
<?php//DB connection already established$res = mysql_query("SHOW TABLE STATUS LIKE 'MY_TABLE'");$row = mysql_fetch_assoc($res);mysql_free_result($res);$commentArr = preg_split('/; */', $row['Comment']);$foreignKeyArr = array(); //<-- We want to fill this.foreach($commentArr as $comment) {
//Only work on InnoDB foreign key info.
if(preg_match(
'/\(`(.*)`\) REFER `(.*)\/(.*)`\(`(.*)`\)/',
$comment,
$matchArr)) {
$primaryKeyFieldArr = preg_split('/` `/', matchArr[1]);
$foreignKeyDatabase = $matchArr[2];
$foreignKeyTable = $matchArr[3];
$foreignKeyFieldArr = preg_split('/` `/', $matchArr[4]);
for($i = 0; $i < count($primaryKeyFieldArr); $i++) {
$foreignKeyArr[ $primaryKeyFieldArr[$i] ] = array(
'db' => $foreignKeyDatabase,
'table' => $foreignKeyTable,
'field' => $foreignKeyFieldArr[$i]);
}
}?>
Now $foreignKeyArr holds a list of fields from MY_TABLE
that have a foreign key constraint. If MY_FK is a foreign
key referencing YOUR_ID in YOUR_TABLE, you will get:
$foreignKeyArr['MY_FK']['db'] == 'THIS_DATABASE'
$foreignKeyArr['MY_FK']['table'] == 'YOUR_TABLE'
$foreignKeyArr['MY_FK']['field'] == 'YOUR_ID'
I know you Perl guys will balk at this - but the JDBC METADATA can give you this information quite easily.
maybe there is something similar for Perl DBI?
Yes!
http://search.cpan.org/src/TIMB/DBI_AdvancedTalk_2004/sld086.htm
mysqlshow -u <user> --password=<password> --status <dbname> | ruby -e 'puts STDIN.readlines[4..-2].inject(0) {|s,e| s += e.split("|")[7].to_i}'
<?phpprint('<table cols="6"><th>Table</th><th>Data Size</th><th>Index Size</th><th>Total size</th><th>Total Rows</th><th>Avg. Size per Row</th>');mysql_connect("localhost","my_user","password");$result = mysql_query("SHOW TABLE STATUS FROM test;");
while($array = mysql_fetch_array($result)) {$total = $array[Data_length]+$array[Index_length];
if ( $array[Data_length] > 0 ) {
print('<tr><td align="center">');
print(' ' . $array[Name] . '<br /></td><td align="center">');
if ( $array[Data_length] < 1024 ) {
echo ' '.$array[Data_length].'</td><td align="center">';
} elseif ( ($array[Data_length] > 1024) && ($array[Data_length] < 1048576 ) ) {
printf('%.0fK',($array[Data_length] / 1024) );
print('</td><td align="center">');
} elseif ( $array[Data_length] >= 1048576 ) {
printf('%.2fMB',($array[Data_length] / 1048576) );
print('</td><td align="center">');
}
if ( $array[Index_length] < 1024 ) {
echo ' '.$array[Index_length].'<br /></td><td align="center">';
} elseif ( ($array[Index_length] > 1024) && ($array[Index_length] < 1048576 ) ) {
printf('%.0fK',($array[Index_length] / 1024) );
print('<br /></td><td align="center">');
} elseif ( $array[Index_length] >= 1048576 ) {
printf('%.2fMB',($array[Index_length] / 1048576) );
print('<br /></td><td align="center">');
}
if ( $total < 1024 ) {
echo ' '.$total.'<br /></td><td align="center">';
} elseif ( ($total > 1024) && ($total < 1048576 ) ) {
printf('%.0fK',($total / 1024) );
print('<br /></td><td align="center">');
} elseif ( $total >= 1048576 ) {
printf('%.2fMB',($total / 1048576) );
print('<br /></td><td align="center">');
}
echo '
'.$array[Rows].'</td><td align="center">
'.$array[Avg_row_length].'</td></tr>
';
}
}?>
I tried your script BUT got a problem with "SHOW TABLE STATUS". It only returns the first foreign key (in MySql 5.0.27).
Instead of it, I'm using "SHOW CREATE TABLE" and this regular expression:
'/FOREIGN KEY \(`(.*)`\) REFERENCES `(.*)` \(`(.*)`\)/'
I'm assuming that all the references are located in the same database.
http://en.latindevelopers.com/ivancp/2012/a-better-show-table-status/
That stored procedure returns a result like this: