888.524.6150 | software@K3integrations.com
Posted by John Ash on Thursday, April 22, 2010.
Though many GUIs exist for managing Mysql databases, my preference is still to use the powerful set of command-line utilities that come with it. The primary commands I use are:mysql, mysqladmin, mysqlshow, and mysqldump. I will write several blog entries on a number of personal tricks using these utilities that I have learned through the years.
After most mysql installs, there is usually a strong warning to set an initial root password. This is important to do... otherwise all your data and possibly even your entire server are vulnerable to attack. Setting an initial root password can be done with:
$ mysqladmin -u root password newpassword $ mysqladmin -u root -h hostname password newpassword
The problem is... once this password is set, most command-line mysql commands appear to fail, for example:
$ mysqlshow mysqlshow: Access denied for user 'root'@'localhost'; (using password: NO)
Why is this? Well... mysql commands default to using the currently logged in user (in this case, root) and an empty password. But since we just set a root password for the server, we can no longer connect with an empty password. The ugliest solution is to provide the password on each call. For example:
$ mysqlshow -password=sekrit_password
This is a pain to type, plus it's a slight security hole. Each time you type a command such as that, your password is recorded in your shell history (eventually stored in ~/.bash_history or similar place). Usually an up-arrow will retrieve these previous commands... password and all. You can even view commands immediately after a fresh login-from the last time (or last person) who was logged in.
A better, but still painful approach is to do something like:
$ mysqlshow -p Enter password:
$ vi ~/.my.cnf
[client] user=mysql_user password=mysql_password
user= line.$ chmod 700 ~Now we can enjoy all the power of Mysql command tools.
© 2010 K3 Integrations, LLC | 888.524.6150 | software@K3integrations.com