Authenticate as a specific user in MySQL

后端 未结 5 1255
离开以前
离开以前 2021-01-14 07:38

I\'m a Brand new User to MySQL DB, have installed the WAMPSERVER and I\'m using MySQL through the MySQL console.

Query_1: Every time that I log in, it directly asks

相关标签:
5条回答
  • 2021-01-14 08:20

    If you attempt to login without specifying a user-name, MySQL will assume "root". In most cases you don't switch the user, but give a single user all the required rights;, for example to access multiple databases. If that is not possible for you, you can use two MySQL connections with two different users simultaneously.

    0 讨论(0)
  • 2021-01-14 08:23

    I don't think its possible to switch users while in the console itself. You have to login with the different user instead.

    Logging in use this command

    mysql -u username -p
    

    Then it will prompt for the password.

    0 讨论(0)
  • 2021-01-14 08:27

    It is not possible to switch users in the MySQL console using WAMP. You must use SQL through the windows command line to switch users.

    Steps (win 8):

    1) Start

    2) Type: 'command prompt'

    3) Type: 'cd /'

    4) Navigate to where WAMP bin is located, my location is: C:\wamp\bin\mysql\mysql5.6.17\bin by typing: 'CD wamp\bin\mysql\mysql5.6.17\bin'

    5) run SQL under new user by typing 'mysql -u (username you want to use) -p (database you want to connect to)'

    You will now be logged in as a new user.

    0 讨论(0)
  • 2021-01-14 08:31

    The MySQL console provided in the wampserver admin panel, once a password is set, will prompt you for the root user's password before you can do anything. In order to log-in as a different user you need to log-in from the command-line. In order to this however, you'll need to add the file pathway to your installation of MySQL's bin folder to your user environment pathway so that your system will be able to access MySQL from the command line. To do this on windows open up file explorer, click on your C drive, open the wamp folder, open bin folder, open MySQL folder, open the MySQL folder with your installation version, open the bin folder you find there. In the file pathway bar of file explorer click on the folder icon to the left to generate the pathway to this bin folder, copy the pathway. Next open up control panel, in the search bar type the string environment variables, select edit user environment... you don't want to mess with the system environment, on the screen that appears choose the PATH variable- if it's not there then add it. Finally paste in the file pathway to MySQL's bin folder. Open up a command prompt and type mysql -u uswername -p hit return and then you'll be prompted for that user's password. Assuming of course you've made another user already.

    As far as I know, once logged in as the root or any other user, the only way to switch is to exit mysql and then enter again as a different user.

    0 讨论(0)
  • 2021-01-14 08:44

    You can specify your username and password like this:

    shell> mysql --user=user_name --password=your_password db_name
    

    As far as I know, there is no way to change user after login without restarting the client.

    0 讨论(0)
提交回复
热议问题