Updating an entry in a MySQL Database
The
UPDATE
command allows one to update an existing entry in
a MySQL database. The format for the command is as follows:
UPDATE table_name SET column1=value1, column2=value2, columnN=valueN WHERE clause;
E.g., suppose there is a database named "software" with a table
named "system1", which is used to maintain records of all the software
installed on system1, with the fields id, which ia a numeric value, and a
character field named "developer". The following commands could be used to
update just the developer field for the record in the table with id=37.
mysql> use software;
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> update system1 set developer="Acme Corporation" where id=37;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
You can enter a date for a date field with the value enclosed in single
quotes in the form YYYY-MM-DD
. E.g.:
update system1 set Obtained='2013-11-14' where id=37;
You can calculate the value for a field based on the contents of another
field in the database. E.g., suppose there is a field named Obtained
in the database and anotehr column with a field indicating when a virus scan
was conducted named Scan_date. If I knew a particular piece of software
was scanned the day after it was obtained, I could use the command below:
update system1 set Scaned=Obtained+1 where id=37;
What if there was no date previously entered in the Obtained field, i.e,
it has a null entry for that field. Then the Scaned field will still be
null.
Note: it is critically important not to forget the WHERE
clause when using an UPDATE
command. If you forget it, then the
update will be applied to every record in the database and you won't be able
to undo the update command unless you've followed the steps listed at
13.3.1. START TRANSACTION, COMMIT, and ROLLBACK Syntax prior to applying
the update command. If you haven't taken such steps, unless you have a
backup you can rely on, you won't be able to revert your data to what
it was before you applied the update command.
[/software/database/mysql]
permanent link
Replacing a character with a newline character using vi
If you wish to replace all occurrences of a character with a newline character, which is used on Linux/Unix systems to indicate the start
of a new line, you can represent the new line with a
\r
in a vi command; think of the "r" as representing a carriage return. E.g., if
I had a long line with items on the line separated by commas, I could use the command below to remove each comma and start another line where
the comma occurred, instead.
:s/,/\r/g
[/editors/vi]
permanent link
Sorting lines in a file using the vi editor
If you need to sort all the lines in a file alphabetically with the vi editor, you can use
! sort
. E.g., you could sort
lines 10 to 20 with the following command:
:10,20 ! sort
You can sort all lines in the file with 1,$ ! sort
.
[/editors/vi]
permanent link
SystemUIServer CPU Usage High
My MacBook Pro laptop running OS X 10.8.3 was performing abysmally. It was taking an inordinate amount of time to switch from application to application and to
perform even simple tasks in programs. I closed VMWare, which helped, but then
when I went to view a video in Safari I found I needed to increase the volume
to hear the audio, but the pinwheel just kept spinning preventing me from
doing so.
I started the Activity Monitor, which can be found in
Applications/Utilities, to see what was happening. After starting
the application, I clicked on the % CPU column header to order the
process list by CPU utilization. The Activity Monitor was showing
that the process SystemUIServer was using from 75% to 85%
of the CPU cycles. I clicked on SystemUIServer to select the
process then clicked on the Quit Process button then the
Quit button to kill the process.
The process got restarted shortly afterwards, but it was then using
about 0% of the CPU cycles.
I found someone else experiencing the problem posting at
High CPU use caused by SystemUIServer?
that he found the problem to be asociated with menubar apps, specifically
Dropbox in his case, but I don't use Dropbox and don't know what app
may have triggered the problem on my laptop.
[/os/os-x]
permanent link