How to Make the Initial Connection to MySQL (From Various Access Points)

Updated on February 12, 2019
Lovelli Fuad profile image

Lovelli has been writing for Blasting News for a little over a year now. She's adopted four kittens and dumped her Amazon bookstore.

How do you make that initial connection with MySQL?
How do you make that initial connection with MySQL? | Source

1. Making the connection

Now that you have installed the MySQL Server and Workbench, you should find the following MySQL products accessible from your Windows machine: the Workbench, the Command Line - Unicode, and Command Line. Often, you'll find online how-to articles with instructions that you need to input into a MySQL Shell. But where can you find this tool?

Do you need the MySQL Shell?

Well, no. It is not a critical component at this stage. The Shell from MySQL is a separate release that bridges the non-SQL (or NoSQL) and the SQL words. Some parts of MySQL manual from their website guide you to start from the shell command line, but mainly only to connect to the server.

You already can connect to the MySQL server with your Windows machine! And without installing the additional Shell.. If you haven't yet installed MySQL or is considering to, these hubs can help:

Hello, Command Prompt!
Hello, Command Prompt!

Connect from the command prompt

Within Windows, you can just go to the command prompt, which is a Windows tool that you access by typing "cmd" onto the search box. From there, you will be able to connect to MySQL, and the rest is command-line client queries--the things you would input if you were using the MySQL command-line in the first place.

The command prompt is also known by other false names, such as the MS-DOS or the DOS prompt, which it certainly is not. The names may have originated from the command interpreters used for older Windows version, circa XP.

Alternative location route

Another way that you can access the prompt is by typing onto your Run command the location "C:\Windows\system32\cmd.exe", which will open the same window you would see if you typed in "cmd" into the Windows search box. Remember, the primary use of the command prompt is to do certain Windows operating tasks. To access MySQL from the prompt, we'll use the "mysql" command.

Run 'mysql' command on the prompt.
Run 'mysql' command on the prompt.

MySQL not recognized?

A common type of error you could find is the "'MySQL' is not recognized as internal or external command, operable program or batch file'".

Get the path, avoid such errors

Just to be sure that we eliminate any chances of getting the dreaded "MySQL not recognized" error, it's a good idea to check on your installation:

  • Go to "This PC" or type in "PC" into the Windows search box, and then click right on the desktop app icon and then select "Properties"
  • Click on “Advanced system settings” > “Environment Variables” and look at “System variables”.
  • Scroll down to one of the variables that says “Path”. Click on the value, and then click “Edit”. Among the variables you need to specify MySQL installation path.
  • The installation path will most likely be on the C: folder > Program Files > MySQL > MySQL Server > bin. Copy the address using the “Copy address as text” option.
  • Back on the variable, click on “New”, and then paste the copied address, and then click OK (each time you need to), and navigate back to the command prompt.

Copy the full MySQL installation path and then paste into the variable column.
Copy the full MySQL installation path and then paste into the variable column.

Connect from MySQL command line

Finally, you can easily access your MySQL Command Line Client and enter your root password, and then work from there. However, once you are within the MySQL command line client, you cannot switch users. To be able to log-in as a new user (with the privileges you have already specified), you need to access the program from the command prompt and specify your username.

2. Creating a new user (for tests)

In my previous articles on MySQL installation, I have provided a step-by-step instruction on how you can set the root password and create a new user during the custom setup installation. These user administration tasks can also be done within the MySQL command-line client, where you create users with custom restrictions, as needed.

Now let's create a new user with some access to our test database. The first thing we want to do is access the command line using our root account and create the user from there. But before all that, why don't we check out the list of all of the available users?

SELECT user FROM mysql.user;
SELECT user, host FROM mysql.user;
See the users and the host that have already been created.
See the users and the host that have already been created.

Name your new user

To create a new user from the command line, you need to specify it a username and a secure password. We will be providing this user with all the privileges at first, and then log in to try out the connection with the test database. After the test, we’ll delete the user.

I'm going to name my new user "espresso_gal" and assign her the password "password" just for the purpose of this connection test:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Grant some privileges

Now we have successfully created a user, but without privileges, so espresso_gal won’t be able to do anything with our databases yet. We gave her the common ‘localhost’ for the host; it actually refers to this computer, or My Computer.

Next, we specify the privileges to our test user. We want her to be able to read, edit, and perform all the necessary actions to all of our databases. So our command line would look like:

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

Note: You SHOULD NOT grant all privileges to every new user you create. It is more practical to make sure that your users are provided only the required privileges for them, although you can change this later on. Now that's a wrap for our espresso_gal. We are going to finalize her privileges and let the changes take effect.

Create a new test user from the MySQL command line client.
Create a new test user from the MySQL command line client.

3. Setting up a test database

To have a go at a near real-life scenario of a remote access from a specific user, we are going to create a test database from the MySQL Workbench. Our reference is the test database detailed in a Make Use Of guide for MySQL installation.

  • First, launch the Workbench application and navigate to the connection you have created during the installation with the root account.

Choose the 'create schema' option.
Choose the 'create schema' option.
  • From the workbench, create a new schema by clicking right on the blank part of the Navigator box that says "SCHEMAS" on the top-left of the dashboard. From the selection, click "Create Schema".
  • Give your schema a name. Mine is called "coffee" to suit espresso_gal. You can name it anything you want. (If you're stuck, "Test" is available :))

Set as default.
Set as default.
  • Right-click on this new schema from the navigator box, and select “Set as Default Schema.”
  • Next, we're going to create a table named "Test_Table" using two lines of code, and then we're going to execute the SQL script.

Create the test table.
Create the test table.

SQL script code

CREATE TABLE Test_Table ( id smallint unsigned not null auto_increment, name varchar(25) not null, constraint my_example primary key (id) );
INSERT INTO Test_Table ( id, name ) VALUES ( null, 'Test data' );

Create the test table:

a. Click on the SQL icon on the menu. This will create a new SQL tab for you to execute the queries.

b. Select the database you just created by clicking on it until the name turns bold.

c. Copy the first line of code from the SQL script above and paste it on to the new tab.

d. Click on the lightning icon to execute the first line of code. If it is successfully executed, you will see a green check on the report in the Output box below.

e. Next, copy the second line of code and paste it on the tab, below the first line of code. Again, click the lightning icon and it will execute.

Confirm that the test table has been created.
Confirm that the test table has been created.
See information for your table.
See information for your table.

To check that the table has been successfully created, you can to go to your new schema and look at the tables tab. If nothing is showing, click right and "Refresh All" from the options. Once you see your new table there, right-click on it and select the first option, "Select Rows - Limit 1000". You will see your test table along with the data.

4. Accessing your MySQL database remotely (the test)

We're going to have espresso_gal establish a remote connection to our coffee database, which we have just created using the two lines of code. Now how do we set a remote connection exactly? Right from the MySQL Workbench.

  • Launch the Workbench and navigate to the "Database" tab on the top of the page, located just under the home icon, between View and Tools. From the options, select "Connect to Database".
  • On the next window, make sure that the TCP/IP setting is the same as the one you set up earlier during installation. On the Username box, type in the new user you created for the test, and on the Default Schema box, input the name of your test database.
  • Once you click okay, you will be asked to input the password for the new user.

The remote access is successful if you see that the MySQL Workbench connects to the MySQL database, allowing you to browse through your schema and input queries to modify your test database.

Launch the workbench.
Launch the workbench.
Fill in the box with your details.
Fill in the box with your details.
Fill in the password, if asked.
Fill in the password, if asked.

This article is accurate and true to the best of the author’s knowledge. Content is for informational or entertainment purposes only and does not substitute for personal counsel or professional advice in business, financial, legal, or technical matters.

Questions & Answers

    © 2018 Lovelli Fuad

    Comments

      0 of 8192 characters used
      Post Comment

      No comments yet.

      working

      This website uses cookies

      As a user in the EEA, your approval is needed on a few things. To provide a better website experience, owlcation.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

      For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://owlcation.com/privacy-policy#gdpr

      Show Details
      Necessary
      HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
      LoginThis is necessary to sign in to the HubPages Service.
      Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
      AkismetThis is used to detect comment spam. (Privacy Policy)
      HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
      HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
      Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
      CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
      Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
      Features
      Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
      Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
      Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
      Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
      Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
      VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
      PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
      Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
      MavenThis supports the Maven widget and search functionality. (Privacy Policy)
      Marketing
      Google AdSenseThis is an ad network. (Privacy Policy)
      Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
      Index ExchangeThis is an ad network. (Privacy Policy)
      SovrnThis is an ad network. (Privacy Policy)
      Facebook AdsThis is an ad network. (Privacy Policy)
      Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
      AppNexusThis is an ad network. (Privacy Policy)
      OpenxThis is an ad network. (Privacy Policy)
      Rubicon ProjectThis is an ad network. (Privacy Policy)
      TripleLiftThis is an ad network. (Privacy Policy)
      Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
      Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
      Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
      Statistics
      Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
      ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
      Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
      ClickscoThis is a data management platform studying reader behavior (Privacy Policy)