Simple Basic MySql – beginning mysql mysqlshow

[problem]

You want to perform command line display of mysql dbs with mysqlshow.

[/problem]

[solution]

Is this demo, I show the options for mysqlshow.

mysqlshow is a real easy way to quickly view your dbs, tables and rows.

[/solution]

[example]

Show Databases

 $ mysqlshow -i -u'root' -p'xxxxxx' +---------------+ |   Databases   | +---------------+ | demo          | | mysql         | | test          | +---------------+ 

Show number of tables under each db

 $ mysqlshow -v -i -u'root' -p'xxxxx' +---------------+--------+ |   Databases   | Tables | +---------------+--------+ | demo          |      1 | | mysql         |     15 | | test          |      0 | +---------------+--------+ 5 rows in set. 

Show total number of rows for each db

 [marcus@bagend ~]$ mysqlshow -v -v -i -u'root' -p'xxxxx' +---------------+--------+--------------+ |   Databases   | Tables |  Total Rows  | +---------------+--------+--------------+ | demo          |      1 |            7 | | mysql         |     15 |         1383 | | test          |      0 |            0 | +---------------+--------+--------------+ 5 rows in set. 

[/example]

Simple Basic MySql – beginning mysql db management

[problem]

You want to know how to do the following, through mysql command line interface:

    Connect to the mysql daemon
    Show the databases your user has access
    Show tables defined under that db
    Show schema for given table

[/problem]

[example]

 mysql -u'username' -p'password' -h'mysql_host' 

mysql_host is optional if the daemon is running on the same host.

Show databases

 show databases; 

Show tables

 show tables; 

Describe tables

 use demo; describe demo; 

For example:

 mysql> show databases; +----------+ | Database | +----------+ | demo     | | test     | +----------+ 2 rows in set (0.00 sec)  mysql> use demo;  Database changed mysql> show tables; +----------------+ | Tables_in_demo | +----------------+ | demo_table     | +----------------+ 1 row in set (0.00 sec)  mysql> desc demo_table; +-------+--------------+------+-----+---------+-------+ | Field | Type         | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | id    | mediumint(9) |      | PRI | 0       |       | | day   | varchar(20)  |      |     |         |       | | val   | tinyint(4)   |      |     | 0       |       | +-------+--------------+------+-----+---------+-------+ 3 rows in set (0.10 sec) 

[/example]

Simple Basic Java Software – analysing arguments from command line

[problem]

You want a simple bit of java code that takes arguments from the command line and displays them.

[/problem]

[solution]

Good demo on how to obtain and handle java arguments.

  public class Arguments {    public static void main(String argv[]) {      if(argv.length > 0) {        System.out.println("args exec w " + argv.length + " args");          for(int i=0;i... 

[/solution]

[example]

Here is a demo:

 # java Arguments -a -x -y args exec w 3 args argv[0] = -a argv[1] = -x argv[2] = -y 

[/example]

Useful UNIX tip – generate 512 bytes of random data with dd

[problem]

You want to generate 512 bytes of random data

[/problem]

[solution]

Use UNIX dd (disk to disk) command with /dev/random blocks for truly random data, whereas /dev/urandom just pumps out whatever is available.

[/solution]

[example]

You need to escape the control characters, or else it will trash your screen. cat -ve escapes these control characters for you.

dd bs=1 count=512 if=/dev/urandom | cat -ve

dd is a very powerful command and can be used to read files, data, tapes, even disks, etc – varying the number of blocks with count and block size with bs.

if is the input device and of can be used to designate an output device.

dd bs=1 count=512 if=/dev/urandom | openssl base64

Also it can convert to upper and lower case, with conv=ucase, etc.

If you have an extremely large file, it can open at an offset – via the skip option, for example to skip the first 1k of the file and read 100 bytes:

dd if=access_log.techieblogs bs=1 skip=1024 count=1000  - - [04/Jun/2006:00:13:10 +0800] "GET /mysqldemo/run_q.php?database=mysql HTTP/1.1" 200 1364

[/example]

Useful Perl script – convert text to ascii

[problem]

You want to convert text to ascii values.

[/problem]

[solution]

Perl script to convert standard input to ascii values, useful with web code.

You can take the output and insert directly into HTML pages.

  #!/usr/bin/perl  while(sysread(STDIN,$a,1)) {  $c=ord($a);if($c==10) { print "n"; } else { print "&#$c;"; }  }  exit(0);  __END__ 

[/solution]

[example]

Here is a screen shot:

convert characters to ascii values in perl

[/example]

[reference]

[/reference]

First steps in vb scripting for windows / DOS

[problem]

Starting out with a new series of tips, getting started with vb scripting. Microsoft have an excellent guide on the site, which I’ve link at the bottom of this post.

[/problem]

[solution]

Below is the typical ‘hello world’ script

[/solution]

[example]

 C:\Documents and Settings\Admin > copy con test.vbs Wscript.echo "Hello World." ^Z 1 file(s) copied.C:\Documents and Settings\Admin > cscript test.vbs Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.Hello World. 

[/example]

[reference]

Microsoft technet tips on beginning vb scripting

[/reference]

Switch to a different user in MS Windows / DOS

[problem]

You want to switch user from the MS DOS prompt.

[/problem]

[solution]

Use runas

runas /?

[/solution]

[example]

Switch user to other id (Then just run explorer and browse to directory)

runas /user:USERID@xxx c:\winnt\system32\cmd.exe

Where user-id is the USER you wish to change to. For example Admin. xxx represents the hostname of the box or domain.

You can also just use local, if changing to user on the same box, like this:

 C\:Documents and Settings\Admin runas /user:localmarcus "c:\WINDOWS\system32\cmd.exe" Enter the password for localmarcus: Attempting to start c\:WINDOWS\system32\cmd.exe as user "localmarcus" ...

[/example]

Setting file permissions from command line in windows

[problem]

You want to modify permissions in Windows from the DOS prompt command line.

[/problem]

[solution]

Use cacls

cacls /?

[/solution]

[example]

Here are the commands to modify MS Windows/DOS files and directories.

  • Display file permissions. Replace filename with your file name.
> cacls filename ...filename            NT AUTHORITYSYSTEM:F PCxxxxxxxxxxxxAdmin:F
  • Modify permissions. Here we are granting full access to the user, replace user with desired user name.
> cacls filename /E /G user:F processed file: C:...filename
  • Here we see the permissions have been reset:
> cacls filename ...filename           PCxxxxxxxxxuser:F NT AUTHORITYSYSTEM:F PCxxxxxxxxxxxxxAdmin:F

[/example]

Useful PHP tool to create an image with superimposed text

[problem]

You want to create an image text label.

[/problem]

[solution]

Use GD library that can be built-in to PHP. Or just use my free on-line tool to create it, as shown in example below.

Once GD is built in – use this PHP code to generate the label.

  

[/solution]

[example]

This shows the label .

You can use this to generate black blank images, with white superimposed text over the top:

generate black blank images, with white superimposed text .. click this link, change text “label” – then save to your machine.

[/example]

[reference]

[/reference]

[tags]Image, PHP[/tags]