- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to log in as a different user on MySQL?
If you want to login as a different user on MySQL, you need to use “mysql -u -p command”. The syntax is as follows to login as a different user.
>mysql -u yourUsername -p After pressing enter key Enter password −
To understand the above syntax, let us create a user in MySQL. The syntax is as follows −
CREATE USER 'yourUserName'@'localhost' IDENTIFIED BY 'yourPassword';
Now I am going to create a user with name ‘John’ and password is ‘john123456’. The query is as follows −
mysql> CREATE USER 'John'@'localhost' IDENTIFIED BY 'john123456'; Query OK, 0 rows affected (0.15 sec)
Now check the user has been created in MySQL.user table or not. The query is as follows to list all users from MySQL.user table −
mysql> select user from MySQl.user;
The following is the output −
+------------------+ | user | +------------------+ | Manish | | User2 | | mysql.infoschema | | mysql.session | | mysql.sys | | root | | Adam Smith | | John | | User1 | | am | +------------------+ 10 rows in set (0.00 sec)
Now you need to give all privileges to the user John. The query is as follows:
mysql> GRANT ALL PRIVILEGES ON * . * TO 'John'@'localhost'; Query OK, 0 rows affected (0.19 sec)
Now to login as a different user, first open the command prompt by pressing Windows+R shortcut key and type CMD. Now you need to press OK button. The screenshot is as follows −
After pressing OK button, you will get a command prompt. The screenshot is as follows −
After that reach the location of bin. Follow the below given steps:
Step 1 −
Step 2 −
Now use the above syntax discussed at the beginning. Give the username ‘John’ and password ‘john123456’ which we created above to login. The command is as follows −
After pressing enter key you need to give password. The query is as follows −
- How to mask user email addresses with a different domain in MySQL?
- Turn on the general log in MySQL?
- How to enable MySQL Query Log?
- How to update User Logged in Time for a specific user in MySQL?
- How to show minor tick labels on a log-scale with Matplotlib?
- How to remove scientific notation from a Matplotlib log-log plot?
- How can we grant privileges to a MySQL user?
- How to display grant defined for a MySQL user?
- How to get a list of MySQL user hosts?
- How to get a list of MySQL user accounts?
- How to add a user to the group on linux
- MySQL query to update different fields based on a condition?
- How to prevent a user from accessing a specific schema in MySQL?
- How to make a log histogram in Python?
- How do I show logarithmically spaced grid lines at all ticks on a log-log plot using Matplotlib?