Archive

Archive for the ‘Beginner’ Category

MySQL anonymous accounts – User=”, Host=’%’ – CODE RED

October 5th, 2009

I want to highlight the importance of reviewing mysql’s initial set of accounts.
Say you have a mysql on abc.def.ghi.jkl running on port 3306 anonymous account with privileges without a password, then:
1. mysql (if issued on localhost)
2. mysql -h abc.def.ghi.jkl
3. mysql -u ” -h abc.def.ghi.jkl
4. mysql -u ” -h abc.def.ghi.jkl -P 3306
5. mysql -u user_which_does_not_exist -h abc.def.ghi.jkl

will all manage to get into mysql given the way mysql authenticates users is against your username and client host from where you are connecting.

This verification is done versus the following columns in the mysql.user table, i.e., User,Host and Password columns.
An entry in the mysql.user table with the following values User=”, Host=’%’ will accept ANY user connecting from ANYWHERE in the world, thus disabling ANY security. Hence the reason for this blog post highlighting the importance of dropping such accounts, at least in all environments apart from dev.

Further information at:

http://dev.mysql.com/doc/refman/5.1/en/connection-access.html

VN:F [1.8.0_1031]
Rating: 10.0/10 (1 vote cast)
VN:F [1.8.0_1031]
Rating: 0 (from 0 votes)

Beginner, MySQL , , , , , ,

MySQL related bookmark collection

September 17th, 2009

I am publishing my MySQL related bookmark collection http://www.mysqlpreacher.com/bookmarks/.

Feel free to send me links you think might be good to add in order to help others.

Remember, SHARING IS CARING!!! …. we get so much for free, why shouldn’t we give some back?

Cheers,
Darren

VN:F [1.8.0_1031]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.0_1031]
Rating: 0 (from 0 votes)

Beginner, Databases, MySQL , , , , , , , , , , , , , ,

Securich – 0.1.4

August 10th, 2009

Just a small note to advise that Securich reached 0.1.4.
Some new tools include:
* Added Password complexity
* Enhanced `set_password` – Old password is now necessary to replace it by a new one
* Enhanced Revoke privileges to accept regexp
* Added Block user@hostname on a database level
* Added Creation of reserved usernames
* Added Help stored procedure displays help for each stored proc
* Enhanced `create_update_role` to include the removal of privilages from roles
* Enhanced `grant_priveleges` on `alltables` for a database without tables would terminate with an error instead of gracefully (now fixed)
* Added Restore user@hostname on a database level
* Removed ’show warnings’ from sql installation

The database design using workbench is also available in the db folder (for easier understanding of what lies beneath.

Cheers,
Darren

VN:F [1.8.0_1031]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.0_1031]
Rating: 0 (from 0 votes)

Beginner, MySQL , , , , , , , , , , , ,

MySQL processlist – (show/kill processes)

July 3rd, 2009

It”s not the most common task in the world, but you might want to view processes from a particular user and once in a while you might even need to kill processes from a single user, be it during an attack or because you simply got a bug in an application bombarding your db server with connections!

Here is a small stored procedure which does exactly that!

call process_list("show","username","hostname");
– shows all processes owned by username@hostname
call process_list("kill","username","hostname");
– kills all processes owned by username@hostname

The code for this stored procedure can be found below. If you have any comments / suggestions feel free to comment below.

######################################################################
## ##
## Stored Procedure: process_list & kill user ##
## call process_list("show","%") show processlist for all users ##
## call process_list("show","root") show processlist for root user ##
## call process_list("kill","user1") kill connections for user1 ##
## ##
## by Darren Cassar http://www.mysqlpreacher.com ##
## ##
######################################################################

DROP PROCEDURE IF EXISTS process_list;

DELIMITER $$

CREATE PROCEDURE "process_list"( choice char(4), usernamein varchar(16), hostnamein varchar(60))
BEGIN

DECLARE CURCONN int;

IF choice <> "show" AND choice <> "kill" then
select "wrong choice";
END IF;

IF usernamein = "" then
set usernamein = "%";
END IF;

IF hostnamein = "" then
set hostnamein = "%";
END IF;

SET CURCONN=(select connection_id());

IF choice = "show" then

select *
from information_schema.processlist
where ID <> CURCONN and
USER like usernamein and
( HOST like CONCAT(hostnamein ,":%") or
HOST like hostnamein );

ELSEIF choice = "kill" then

IF usernamein = "root" then
select "Illegal username when killing processes";
ELSE
SET @CNT = (
select count(*)
from information_schema.processlist
where ID <> CURCONN and
USER like usernamein and
( HOST like CONCAT(hostnamein ,":%") or
HOST like hostnamein )
);

SET @VAR=1;

WHILE ( @VAR <= @CNT) DO

SET @TID = (
select id
from information_schema.processlist
where ID <> CURCONN and
USER like usernamein and
( HOST like CONCAT(hostnamein ,":%") or
HOST like hostnamein ) limit 1
);

SET @k = CONCAT("kill " , @TID);
PREPARE killcom FROM @k;
EXECUTE killcom;
set @k=NULL;

SET @VAR=@VAR+1;

END WHILE;

END IF;

END IF;

END$$

DELIMITER ;

VN:F [1.8.0_1031]
Rating: 7.0/10 (4 votes cast)
VN:F [1.8.0_1031]
Rating: +2 (from 4 votes)

Beginner, Databases, MySQL , , , , , ,

Save time and energy: How to … (… continued)

July 2nd, 2009

Earlier this year I had published a small blog about being efficient when using mysql prompt. This is a small continuation of it highlighting a couple of other cool features which I really find very useful when working command line (i.e. always!).

The first I’m gonna list here is setting the prompt itself by typing – \R mysql \D > thus enabling date and time display at each comand which is great for auditing and record keeping. There is a whole bunch of prompt values which you can find here:

Option Description
\c //A counter that increments for each statement you issue
\D //The full current date
\d //The default database
\h //The server host
\l //The current delimiter (new in 5.0.25)
\m //Minutes of the current time
\n //A newline character
\O //The current month in three-letter format (Jan, Feb, …)
\o //The current month in numeric format
\P //am/pm
\p //The current TCP/IP port or socket file
\R //The current time, in 24-hour military time (0–23)
\r //The current time, standard 12-hour time (1–12)
\S //Semicolon
\s //Seconds of the current time
\t //A tab character
\U //Your full user_name@host_name account name
\u //Your user name
\v //The server version
\w //The current day of the week in three-letter format (Mon, Tue, …)
\Y //The current year, four digits
\y //The current year, two digits
\_ //A space
\ //A space (a space follows the backslash)
\' '//Single quote
\" "//Double quote
\\ //A literal “\” backslash character
\x //x, for any “x” not listed above

The second thing is the \e or edit which lets you edit a long query you might have been writing, in any editor you have set on your machine, most often vi, a must know editor for all of you out there.

Enjoy
Darren

VN:F [1.8.0_1031]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.0_1031]
Rating: 0 (from 0 votes)

Beginner, Databases, MySQL

MCDBA Certification – KPIs

March 27th, 2009

A few interesting KPIs about certified people and their current location (the fact that many people travel from one country to the other for work is very popular these days especially in the IT sector):

Before starting to read, I am hereby assuming the MySQL list of MCDBAs is on a residence basis not citizenship.

There are at the time of this writing a total of 796 MCDBAs in the world, living in 57 countries.

When analyzing the number of MCDBAs / country, it is pretty obvious the scene is totally dominated by the US:

+----------------------+-------------+
| Country              | No of Certs |
+----------------------+-------------+
| UnitedStates         |         346 | 
| Unitedkingdom        |          47 | 
| Germany              |          46 | 
| India                |          34 | 
| Italy                |          28 | 
| Japan                |          26 | 
| Canada               |          23 | 
| China                |          20 | 
| Brazil               |          18 | 
| Australia            |          16 | 
| France               |          16 | 
| Netherlands          |          13 | 
| Switzerland          |          13 | 
| SouthKorea           |          12 | 
| Spain                |          11 | 
| HongKong             |          10 | 
| Sweden               |          10 | 
| SouthAfrica          |          10 | 
| Singapore            |           9 | 
| Taiwan               |           8 | 
| Poland               |           7 | 
| Philippines          |           6 | 
| Norway               |           5 | 
| Russia               |           5 | 
| Finland              |           5 | 
| Ireland              |           4 | 
| Israel               |           3 | 
| Srilanka             |           3 | 
| Ukraine              |           3 | 
| Austria              |           3 | 
| Belgium              |           3 | 
| Denmark              |           2 | 
| Egypt                |           2 | 
| Mexico               |           2 | 
| Malta                |           2 | 
| Thailand             |           2 | 
| Unitedarabemirates   |           2 | 
| Latvia               |           2 | 
| Bangladesh           |           1 | 
| Croatia              |           1 | 
| TrinidadandTobago    |           1 | 
| BosniaandHerzegovina |           1 | 
| Malaysia             |           1 | 
| Slovenia             |           1 | 
| SaudiArabia          |           1 | 
| Indonesia            |           1 | 
| Jordan               |           1 | 
| Kenya                |           1 | 
| Lithuania            |           1 | 
| Luxembourg           |           1 | 
| Guatemala            |           1 | 
| Nepal                |           1 | 
| Gibraltar            |           1 | 
| Newzealand           |           1 | 
| Pakistan             |           1 | 
| Portugal             |           1 | 
| Virginislands        |           1 | 
+----------------------+-------------+ 

But what happens when we look at the number of MCDBAS in respect to population / area?

The country with largest certs / capita is Gibralter with a MySQL Certified DBA in 31k population, followed by Virgin Islands at 1 for 110k and Malta at 2 / 412.6k.

The country with least certs / capita is Indonesia with a single MySQL Certified DBA out of almost 230M people.



+----------------------+------------+-------------+---------+
| Country              | Population | No of Certs | PPM     |
+----------------------+------------+-------------+---------+
| Gibraltar            |      31000 |           1 | 32.2580 | 
| Virgin Islands       |     110000 |           1 |  9.0900 | 
| Malta                |     412600 |           2 |  4.8470 | 
| Luxembourg           |     491700 |           1 |  2.0330 | 
| Singapore            |    4839400 |           9 |  1.8590 | 
| Switzerland          |    7700200 |          13 |  1.6880 | 
| Hong Kong            |    6985200 |          10 |  1.4310 | 
| United States        |  306088000 |         346 |  1.1300 | 
| Sweden               |    9259828 |          10 |  1.0790 | 
| Norway               |    4810122 |           5 |  1.0390 | 
| Finland              |    5331096 |           5 |  0.9370 | 
| Ireland              |    4517800 |           4 |  0.8850 | 
| Latvia               |    2260000 |           2 |  0.8840 | 
| Netherlands          |   16492476 |          13 |  0.7880 | 
| United Kingdom       |   61612300 |          47 |  0.7620 | 
| Trinidad and Tobago  |    1339000 |           1 |  0.7460 | 
| Australia            |   21707964 |          16 |  0.7370 | 
| Canada               |   33596000 |          23 |  0.6840 | 
| Germany              |   82062200 |          46 |  0.5600 | 
| Slovenia             |    2053355 |           1 |  0.4870 | 
| Italy                |   60090400 |          28 |  0.4650 | 
| United Arab Emirates |    4599000 |           2 |  0.4340 | 
| Israel               |    7382200 |           3 |  0.4060 | 
| Denmark              |    5511451 |           2 |  0.3620 | 
| Austria              |    8356700 |           3 |  0.3580 | 
| Taiwan               |   23027672 |           8 |  0.3470 | 
| Lithuania            |    3350400 |           1 |  0.2980 | 
| Belgium              |   10741000 |           3 |  0.2790 | 
| Bosnia Herzegovina   |    3767000 |           1 |  0.2650 | 
| South Korea          |   48333000 |          12 |  0.2480 | 
| France               |   65073482 |          16 |  0.2450 | 
| Spain                |   45853000 |          11 |  0.2390 | 
| New Zealand          |    4302010 |           1 |  0.2320 | 
| Croatia              |    4432000 |           1 |  0.2250 | 
| South Africa         |   48697000 |          10 |  0.2050 | 
| Japan                |  127630000 |          26 |  0.2030 | 
| Poland               |   38130300 |           7 |  0.1830 | 
| Jordan               |    6316000 |           1 |  0.1580 | 
| Sri Lanka            |   20238000 |           3 |  0.1480 | 
| Brazil               |  190902000 |          18 |  0.0940 | 
| Portugal             |   10631800 |           1 |  0.0940 | 
| Guatemala            |   14027000 |           1 |  0.0710 | 
| Philippines          |   92226600 |           6 |  0.0650 | 
| Ukraine              |   46143700 |           3 |  0.0650 | 
| Saudi Arabia         |   25721000 |           1 |  0.0380 | 
| Russia               |  141850000 |           5 |  0.0350 | 
| Malaysia             |   28067000 |           1 |  0.0350 | 
| Nepal                |   29331000 |           1 |  0.0340 | 
| Thailand             |   63389730 |           2 |  0.0310 | 
| India                | 1161120000 |          34 |  0.0290 | 
| Egypt                |   76030000 |           2 |  0.0260 | 
| Kenya                |   39802000 |           1 |  0.0250 | 
| Mexico               |  109610000 |           2 |  0.0180 | 
| China                | 1335962133 |          20 |  0.0140 | 
| Bangladesh           |  162221000 |           1 |  0.0060 | 
| Pakistan             |  165899500 |           1 |  0.0060 | 
| Indonesia            |  229850000 |           1 |  0.0040 | 
+----------------------+------------+-------------+---------+

On a per area basis, the country with most certified MySQL DBAs is again Gibralter given its 6Km squared of area, followed by Singapore, Hong Kong and Malta.

The least being Pakistan, Russia and Indonesia in order.

*PPK here means parts per 1000 Km squared

+----------------------+----------+-------------+----------+
| Country              | Area     | No of Certs | PPK*     |
+----------------------+----------+-------------+----------+
| Gibraltar            |        6 |           1 | 166.6667 | 
| Singapore            |      699 |           9 |  12.8755 | 
| Hong Kong            |     1108 |          10 |   9.0253 | 
| Malta                |      316 |           2 |   6.3291 | 
| Virgin Islands       |      347 |           1 |   2.8818 | 
| Luxembourg           |     2586 |           1 |   0.3867 | 
| Switzerland          |    41284 |          13 |   0.3149 | 
| Netherlands          |    41543 |          13 |   0.3129 | 
| Taiwan               |    36188 |           8 |   0.2211 | 
| Trinidad and Tobago  |     5130 |           1 |   0.1949 | 
| United Kingdom       |   242900 |          47 |   0.1935 | 
| Israel               |    22072 |           3 |   0.1359 | 
| Germany              |   357022 |          46 |   0.1288 | 
| South Korea          |    99678 |          12 |   0.1204 | 
| Belgium              |    30528 |           3 |   0.0983 | 
| Italy                |   301318 |          28 |   0.0929 | 
| Japan                |   377915 |          26 |   0.0688 | 
| Ireland              |    70273 |           4 |   0.0569 | 
| Slovenia             |    20273 |           1 |   0.0493 | 
| Denmark              |    43094 |           2 |   0.0464 | 
| Sri Lanka            |    65610 |           3 |   0.0457 | 
| United States        |  9629091 |         346 |   0.0359 | 
| Austria              |    83871 |           3 |   0.0358 | 
| Latvia               |    64589 |           2 |   0.0310 | 
| France               |   632760 |          16 |   0.0253 | 
| United Arab Emirates |    83600 |           2 |   0.0239 | 
| Poland               |   312685 |           7 |   0.0224 | 
| Sweden               |   450295 |          10 |   0.0222 | 
| Spain                |   505992 |          11 |   0.0217 | 
| Philippines          |   300000 |           6 |   0.0200 | 
| Bosnia Herzegovina   |    51197 |           1 |   0.0195 | 
| Croatia              |    56594 |           1 |   0.0177 | 
| Norway               |   323802 |           5 |   0.0154 | 
| Lithuania            |    65300 |           1 |   0.0153 | 
| Finland              |   338145 |           5 |   0.0148 | 
| Jordan               |    89342 |           1 |   0.0112 | 
| Portugal             |    92090 |           1 |   0.0109 | 
| India                |  3287263 |          34 |   0.0103 | 
| Guatemala            |   108889 |           1 |   0.0092 | 
| South Africa         |  1221037 |          10 |   0.0082 | 
| Bangladesh           |   143998 |           1 |   0.0069 | 
| Nepal                |   147181 |           1 |   0.0068 | 
| Ukraine              |   603500 |           3 |   0.0050 | 
| Thailand             |   513120 |           2 |   0.0039 | 
| New Zealand          |   270467 |           1 |   0.0037 | 
| Malaysia             |   329847 |           1 |   0.0030 | 
| Canada               |  9984670 |          23 |   0.0023 | 
| Brazil               |  8514877 |          18 |   0.0021 | 
| Australia            |  7692024 |          16 |   0.0021 | 
| China                |  9640821 |          20 |   0.0021 | 
| Egypt                |  1002000 |           2 |   0.0020 | 
| Kenya                |   580367 |           1 |   0.0017 | 
| Mexico               |  1964375 |           2 |   0.0010 | 
| Saudi Arabia         |  2000000 |           1 |   0.0005 | 
| Indonesia            |  1904569 |           1 |   0.0005 | 
| Russia               | 17098242 |           5 |   0.0003 | 
| Pakistan             |  7960951 |           1 |   0.0001 | 
+----------------------+----------+-------------+----------+

At this point I'd like to ask the community a couple of questions:

1. Do you think there are many good MySQL DBAs who never tried getting certified?

2. Would you think it is fair to assume, the people who never tried the MCDBA exam is proportional to does who did? (my guess is yes)

 
KPIs for developers and cluster certified people will follow in other blogs.

VN:F [1.8.0_1031]
Rating: 9.3/10 (3 votes cast)
VN:F [1.8.0_1031]
Rating: 0 (from 0 votes)

Advanced, Beginner, Databases, Intermediate, MySQL , , , , ,

Save time and energy: How to …

February 23rd, 2009

Save time and energy: How to:

Listening to “Highway to Hell” in an Oxford University computer lab on a sunday afternoon writing a MySQL blog can be legitimally defined by some as sick but thats what a geek calls a relaxing yet productive sunday afternoon.

For the sake of all those CLI ambassadors like myself, I wanted to share a couple of tips and tricks I use quite often when doing my mysql db administration work / scripting. I strongly suggest any mysql dba / dev use CLI simply because thats the one thing you should always have on any machine on which mysql is installed, be it Unix, Linux, Mac, Microsoft or whatever platform you are using.

Cancelling a query you are typing without exiting to the terminal:
`\c` – How many times you ended up hitting `CTRL+C` (default process kill in most OSes) in order to cancel a command, finding yourself going back to the console and having to connect again? Nuisence? Hell yeah! Especially if you had a number of temp tables waiting to be used.


A `CTRL+C` would bring send you to console:
mysql> SELECT
-> User, Host
-> OOPS I DID A MISTAKE
-> FROM --Hit `CTRL+C` here
-> Aborted
mysqlpreacher:~ darrencassar$

A `\c` in the mysql program would just cancel the wrong query:
mysql> SELECT
-> User, Host
-> OOPS I DID A MISTAKE
-> FROM
-> \c
mysql>

BTW it doesn’t work with the USE command – it gives an error but at least doesn’t terminate the connection:

mysql> USE m\c
ERROR 1049 (42000): Unknown database 'mc'
mysql>

Running a console command from within a mysql terminal session:
`\!` – Need to run a console command while you are logged in a mysql terminal session? There is no need to exit the current session or to dupplicate the terminal session and run the command, just use `\!`


mysql> \! pwd
/var/root/sandboxes/mysql_5130
mysql> \! ls
COPYING VERSION data my restart stop
README clear grants.mysql my.sandbox.cnf send_kill use
USING current_options.conf load_grants proxy_start start
mysql> \! ps -ef | grep mysql | grep -v grep
0 36319 1 0 0:00.01 ttys002 0:00.02 /bin/sh /mysql/releases/5.1/5.1.30/bin/mysqld_safe --defaults-file=/var/root/sandboxes/mysql_5130/my.sandbox.cnf
0 36389 36319 0 0:00.14 ttys002 0:01.48 /mysql/releases/5.1/5.1.30/bin/mysqld --defaults-file=/var/root/sandboxes/mysql_5130/my.sandbox.cnf --basedir=/mysql/releases/5.1/5.1.30 --datadir=/var/root/sandboxes/mysql_5130/data --user=root --log-error=/var/root/sandboxes/mysql_5130/data/msandbox.err --pid-file=/var/root/sandboxes/mysql_5130/data/mysql_sandbox3308.pid --socket=/tmp/mysql_sandbox3308.sock --port=3308
0 36987 26344 0 0:00.01 ttys002 0:00.02 mysql -u root -p --auto-rehash -h 127.0.0.1 -P 3308
0 36992 36987 0 0:00.00 ttys002 0:00.00 sh -c ps -ef | grep mysql
mysql>

Autocompletion on command line mysql:
`\#`, `rehash` or `–auto-rehash` – Autocompletion is fast, handy and help you produce more in less.
Autocompletion in MySQL is enabled by default, and there is a need to use –disable-auto-rehash (note that –no-auto-rehash or -A are deprecated) in order to disable rehashing which makes mysql start faster. If this is done, then it can be called upon using either of the following `\#`, `rehash` or using `–autu-rehash` depending on where you are and what you are comfortable with. If you are already in a mysql terminal session, then type in `\#` or `rehash`. Another option is to connect to mysql using: `mysql -u user -p –auto-rehash` as a startup option. Having done that, remember to initialise the hashing by issueing a `USE DATABASENAME` as otherwise the autocompletion won’t work. Autocompleting a word / name can be done in a similar way to what you’d do in CL UNIX, LINUX or DOS, typing the first part of the word and then pressing `TAB`.

–auto-rehash:

mysqlpreacher:~ darrencassar$ mysql -u root -p --auto-rehash -h 127.0.0.1 -P 3308
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.30 MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> use m
max_connections max_questions max_updates max_user_connections modified mysql
mysql> use mysql
Database changed

\# or rehash:

mysqlpreacher:~ darrencassar$ mysql -u root -p -h 127.0.0.1 -P 3308
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.30 MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> \#
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> use m
max_connections max_questions max_updates max_user_connections modified mysql
mysql> use mysql

more tips and tricks will follow in future blogs,

Asta la vista mysql user!

VN:F [1.8.0_1031]
Rating: 7.7/10 (3 votes cast)
VN:F [1.8.0_1031]
Rating: 0 (from 0 votes)

Beginner, Databases, Intermediate, MySQL , ,

Slap’em

February 13th, 2009

Giving a bunch of mysql instances something you do everyday and you might think ….. how should I do it? Write a bunch of selects and inserts manually? nahh that takes s**tload of time, should I run binlogs collected from a live system on my test server? nahh thats not practical nor is it real since it doesn’t contain selects, should I gather the general query log and try that out? nahhh  …..

MySQL has been kind enough to supply us with their mysql_slap which does the job for us and given I needed to do a proof of concept on monitoring a group of 4 circular replicated servers I wrote a small script which does the job of slapping them with a varying level of concurrancy, iterations, number of queries and connections for as long as you like.

Here it is and I hope some of you might find it useful for slapping their own test servers :).

#!/bin/bash

NumberOfConcurrentLoads=4
LOGFILE=randomslap-4n-circularreplication

load () {

run=0
#Obtaining pid of the current process
PID=$$

echo "MySQL Slap random loading MySQL instances" >> $LOGFILE-$PID.log
echo "Loading child $a out of $NumberOfConcurrentLoads" >> $LOGFILE-$PID.log
echo "Starting at: `date`" >> $LOGFILE-$PID.log
echo ""

while [ 1 ]
do

#Generate a few values for the actual command to run through
prt=$((RANDOM%4+17001)) #ports being 17001,17002,17003,17004
cnc=$((RANDOM%50+1)) #number of concurrent sessions
itr=$((RANDOM%9+1)) #number of iterations
noq=$((RANDOM%100+50)) #number of queries
sec=$((RANDOM%30+10)) #seconds idle after finishing the process

echo "Run number $run" >> $LOGFILE-$PID.log
echo `date +%Y/%m/%d---%H:%M | sed 's/---/ /'` >> $LOGFILE-$PID.log

echo "Port=$prt" >> $LOGFILE-$PID.log
echo "Concurrency=$cnc" >> $LOGFILE-$PID.log
echo "Iterations=$itr" >> $LOGFILE-$PID.log
echo "Number-Of-Queries=$noq" >> $LOGFILE-$PID.log
echo "Breaktime=$sec" >> $LOGFILE-$PID.log

echo "Output:" >> $LOGFILE-$PID.log
mysqlslap --user=root --password='msandbox' --auto-generate-sql -vv -h hostname -P $prt --concurrency=$cnc --iterations=$itr --number-of-queries=$noq >> $LOGFILE-$PID.log

run=`expr $run + 1`
sleep $sec

done

}
#Fork a number of concurrent scripts to emulate more of a realistic load rather than one process connecting to just one server at a time
for ((a=1;a<=NumberOfConcurrentLoads;a++))
do
load &
done

If you are wondering … yes I totally indendate my code :) but the html version came out this way and I didn’t bother with indenting it using html really.

VN:F [1.8.0_1031]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.0_1031]
Rating: 0 (from 0 votes)

Beginner, Databases, Intermediate, MySQL, Uncategorized , , ,

Get Adobe Flash playerPlugin by wpburn.com wordpress themes