Wednesday, May 16, 2018

Connecting to MySQL DB


Ways of Connecting
==================

prompt> mysql

  # default hostname is localhost
  # default user is current user for Linux and "ODBC" for windows
  # 1st non-option parameter is treated as default database

shell> mysql --host=localhost --user=myname -pMyInsecurepass123 mydb

  # there must be no space between "-p" and the actual password
  # this form is insecure because the password is in cleartext, it is possible
    to be seen in "history" or "ps auxw"

shell> mysql -h network-db.com -u myname -p mydb

  # this will prompt user for password
  # secure compared to the previous

Notes on Credentials
====================

* MySQL doesn't have a limit on password length
* If system library limits password to 8 characters or less, MySQL password
  can be adjusted to adapt to it
* credentials can be set under ~/.my.cnf following this format

[client]
host=localhost  # you can ommit this line
user=root
password=Pass123^^

Choosing Port and Host
======================

You can choose host and port using the following format:

mysql --port=13306 --host=127.0.0.1

You may also store the hostname in MYSQL_HOST environment variable.

No comments:

Post a Comment