MySQL Login with Different User Account

The user account in MySQL contains essential information for the MySQL accounts, such as login information, account privileges, and the host information. Therefore, to access and manage the databases in MySQL, we need to create a user account. We can create several user accounts on the MySQL server and used them whenever we need them. This article will see how we can log in to the server with a different account.

Syntax

The following is the syntax to log in as a different user on the MySQL server:

After pressing the enter key, we need to write the same password associated with the user:

Let us understand it with the help of the following explanations. First, we will create a new user named 'William', and the password is 'will123456'. We can do this by executing the below query:

Next, we will verify the newly created user has been successfully created in the MySQL.user table or not. We can execute the below query to display all users from MySQL.user table:

After execution, we will get the output as follows:

MySQL Login with Different User Account

Next, we need to provide all privileges to the newly created user account 'William' by executing the query as follows:

If this query is successful, we should get the below message:

If we want to login to a different user account, we need to open the command prompt by executing the RUN command in the search box or pressing the Windows + R shortcut key. It will display the screen where we type CMD and click the OK button. See the below screenshot:

MySQL Login with Different User Account

After clicking the OK button, we can see the command prompt as follows:

MySQL Login with Different User Account

Now, we will follow the steps given below to reach the location of the bin directory:

Step 1: Suppose we have installed MySQL in the C folder on our device. Then, copy that folder and paste it into our command prompt and press the Enter key.

After pressing the Enter key, we can see the below output:

MySQL Login with Different User Account

Step 2: Next, we will use the syntax that we have discussed at the beginning (mysql -u username -p.). Write the 'William' as the user name & 'will123456' as the password created above and press the Enter key to access the account. See the below query:

After pressing the Enter key, we will get the below output that shows the username is opened successfully.

MySQL Login with Different User Account




Contact US

Email:[email protected]

Login with Different User
10/30