Connecting to MySQL

Technical Articles

Solution
Application
Content Type
Technical Documentation
Utilities & Services
ft:locale
en-US

Requirements

Depending on the MySQL version you installed, the installation process may have created a randomly generated password for the "root" MySQL user (instead of the older strategy of creating the "root" user with no password).

You should temporarily copy this password somewhere (you will need it to complete the steps below), and plan to change the "root" user password.

  1. Do one of the following, depending on your platform:
    • Linux: From a command prompt, access the MySQL command line as the "root" MySQL user by typing:
      mysql -u root -p
      Note:

      If you have not added a path to mysql to the system path, you may need to enter the full path to MySQL in place of mysql in the above command. The path to MySQL can be determined with the command which mysql, but on Linux, it is usually:

      /usr/bin/mysql
    • Windows: Launch the "MySQL Command Line Client" or "MySQL Command Line Client - Unicode".

    • Mac: Open the Terminal application and access the MySQL command line as "root" MySQL user by typing:
      mysql -u root -p
      Note:

      If you have not added a path to mysql to the system path, you may need to enter the full path to MySQL in place of mysql in the above command. The default path for MySQL on macOS is:

      /usr/local/mysql/bin/mysql
  2. If prompted, enter the password for the "root" MySQL user or simply press the Return key if the user has no password.
On any of the platforms, you should now see the MySQL command prompt:
mysql>

The remainder of the process is the same on all platforms.

Note:

All MySQL commands must end with a semicolon (;) and, although MySQL reserved words are presented below in uppercase, they are case-insensitive and may be typed in all lowercase.