Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1
Decoding with the wrong password will give a spurious result, not an error. For example
mysql> SELECT DECODE(ENCODE('my string','mypass'),'badpass');

results in
+------------------------------------------------+
| DECODE(ENCODE('my string','mypass'),'badpass') |
+------------------------------------------------+
| aZ^ |
| @}¿? |
+------------------------------------------------+
Remember that the result of an ENCODE(), being binary, needs to be stored as a BLOB data type.

MD5(string)


MD5() returns an MD5 checksum for a given string. This is a 32-character hexadecimal number.


LAST_INSERT_ID([expr])


This function returns the last value that was inserted into an AUTO_INCREMENT column after having been
generated automatically. It refers only to values handled by the current connection to the database.


Managing a Database with mysqladmin


The mysqladmin utility is used to perform a wide range of administrative operations on a MySQL database.
It is usually run from a command line prompt.
When invoked, you should pass mysqladmin a number of options and commands that tell it how to run
and what to do.


How to Use mysqladmin


The following is the basic syntax for mysqladmin:


mysqladmin [options] command1 [cmd1_opt] command2 [cmd2_opt]
Remember that you may need to prefix mysqladmin with the path to the mysql/bin directory where it
resides.
Also, after you assign usernames and privileges to a database, you will need to use the -p and/or -u
options when invoking mysqladmin if your MySQL username is different from your UNIX username.
This tells MySQL that you are offering to provide it a username and password; if you do not and MySQL
requires them, you will receive an error message.
To summarize, the following commands can be used with mysqladmin:
ƒ create databasename Creates a new database with the specified name
ƒ drop databasename Drops (deletes) the database with the specified name
ƒ status Gives a brief status message from the server
ƒ version Displays server version information
ƒ extended-status Creates an extended status message from the server
ƒ variables Displays available variables
ƒ processlist Displays a list of active threads in the server, useful to see how busy
the server is
ƒ flush-hosts Flushes all cached hosts
ƒ flush-logs Flushes all logs
ƒ flush-tables Flushes all tables
ƒ flush-privileges Reloads the grant tables
ƒ kill id1,id2 Kills mysql threads
ƒ password new_password Changes the old password to a new password
ƒ ping Sends a "ping" signal to mysqld to check that it is functioning
ƒ reload Makes mysql reload its grant tables
ƒ refresh Flushes all grant tables and closes and opens logfiles
ƒ shutdown Shuts down the MySQL server
As well as the commands, mysqladmin can be given the following options to tell it how to run the
commands:
ƒ -#, --debug= To output to a debug log; often this is 'd:t:o,filename'.
ƒ -f, --force Dropping a database will give a warning, as will some other
commands; --force will continue even if you get such a warning.
ƒ -C, --compress Use compression in server/client protocol.
Free download pdf