How to connect as different user in MySQL? - mysql

How do I connect as different user in MySQL. When I start MySQL command line I am prompted to enter the password for root. I have tried the following command to connect as a user I created but when I press enter I am taken to a new line without asking me for password:
mysql -h localhost -u user1 -p
Thank You

Try the following command:
>> mysql -u USERNAME -p
replace USERNAME with the username you created and then press enter. You should be prompted for the password.

Related

What does mysql -u root -p do?

I am trying to figure out what the mysql -u root -p command does.
I have googled the command but I can't find any good results.
mysql -u root -p means, that you trying to connect to MySQL shell with parameters - -u parameter specified MySQL user name.
-u, --user=name User for login if not current user.
In your case it's root user.
-p, --password[=name]
Password to use when connecting to server. If password is
not given it's asked from the tty.
You can type mysql --help from the command line for more information about all available parameters.
Good luck.
It logs you into mysql as the root user. After -p (Immediately after it incidentally, no spaces) you would include the password.
`mysql -u root -p`
Its initiate a connection of MySQL.
-u means that we are going to connect with a username root
-p means that we will enter username's password
Check man mysql
Your command tries to connect to MySQL on localhost with user "root" and asking for a password

mysql import on Mac : second password asked?

I'm trying to import a mysql database from my Mac with terminal under OSX Yosemite. I typed the mysql command with -u -p -h etc but when I hit enter, Terminal ask me :
"Enter password".
I tried to re-enter the one I put in the command line, the one of my Mac, and others but nothing worked.
What is this second password asked ?
http://dev.mysql.com/doc/refman/5.0/en/connecting.html
For password options, the password value is optional.
If you use a -p or --password option and specify the password value, there must be no space between -p or --password= and the password following it.
If you use a -p or --password option but do not specify the password value, the client program prompts you to enter the password.
mysql --user=user_name --password=your_password db_name
So if you typed -p passwd instead of -ppasswd, it will ask for the password.
If the password itself doesn't work, then you have it wrong.

Can't login into mysql

I've just downloaded MySql using this tutorial after installing it before.
I've thought that it would solve my problems but, whenever I try to login into MySql via the terminal I'm prompted to enter the password though I've already logged in with the following command:
mysql -u user -p password
Here is what happening:
$> mysql -u user -p MYPASSWORD
Enter password:
And after I insert my password again...
$> mysql -u user -p MYPASSWORD
Enter password:
ERROR 1049 (42000): Unknown database 'MYPASSWORD'
I'd like to know if there's a solution to this weird problem.
The command is:
mysql -u user -ppassword
So in your case:
mysql -u user -p123456
By adding a space between -p and your password, you're actually setting the database to use, which is why you get the error unknown database.
The other solution would be:
mysql -u user -p
In that case, your password will be asked by the terminal. It is a bit more secure as your password does not stay in plain text in your terminal history. But if your password is 123456, I guess you're not too concerned by security ... ;)
Under normal circumstances, I would use:
mysql -uroot -p
Enter password:
you can try it.... ;)

Connect to database through MySql command line client

I am following this tutorial: http://dev.mysql.com/doc/refman/5.7/en/connecting-disconnecting.html
However when I run MySql command line client I automatically get asked for a password when I enter it I get connected automatically to a localhost database, how do I access other database's using something like the following as shown in the tutorial example?
shell> mysql -h host -u user -p
Enter password: ********
shell> mysql nameofdatabase -uusername -ppassword
You can put a space in between -u username but not between the -p and password.
There are multiple ways to access mysql on the command line. If you wish to connect to another database server, you need to add -h <hostname> to your mysql command. Without this, mysql assumes you want to connect to the local mysql server.
If you mean that you want to connect to another database on a host, just specify that database at the end of your command line.
$ mysql -u username -ppassword second_database
Note, there is NO space between -p and password. If -p is followed by a space, mysql will prompt you to enter a password interactively. Which you can do, if that is what you want.
$ mysql -u username -p third_database
Enter password: *********
Another way to connect would be to create a file in your home directory named .my.cnf. This file should contain the following:
[client]
user=username
password=yourpassword
If you have any special characters in your password, you will need to quote it. Having this file allows you to not need to enter any username or password on your command line:
$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
....
mysql>

error during mysql db connection in localhost

when I am trying to connect mySql data base from cmd it giving some error like -
c:\xampp\mysql\bin>mysqladmin -u root password 123123
mysqladmin: connect to server at localhost failed
error:Access denied for user root#localhost (using password : NO)
Shouldn't that be:
mysqladmin -u root -p PASSWORD
?
The syntax looks wrong to me, just like Roberto said. You could also use this
mysqladmin -u root -h localhost -p
It should then ask you for the password. This way you can be sure that only a wrongly entered PW prevents you from connecting.
It should be:
mysqladmin -u root -p
and it will prompt you for a password. If you need to enter the password directly via the command line ( say you need to write a script), you should be able to do that with:
mysqladmin -u root -p123123