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.... ;)
Related
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
I was getting an error trying to log in to mysql with mysql -u root -p , it always gave me the error "ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)". I'm on a Macbook Air running Yosemite.
So, I figured that I'd forgotten my password. It got so frustrating trying to reset it that I uninstalled mysql completely by sudo rming /usr/local/bin/mysql, and then reinstalling the dmg again from scratch. The installer gave me the gibberish temporary password, I tried logging in with it, and I got the same 1045 error that I've been getting all along. So maybe my first password wasn't wiped somehow . . . ?
I've tried this both with and without running mysqld in another terminal window, did not make a difference unfortunately. Any help on how I can just set the root password to whatever I want and log into mysql?
If you want to update a root password, then you need to use the following command:
$ mysqladmin -u root -p oldpassword newpassword
If you are trying to update the password for another user use:
$ mysqladmin -u user-name -p oldpassword newpassword
If you get a Access denied error it may be because you are not running the command as root.
To run a command as root add sudo to the beginning of the command.
For Example:
To update the password for the current, as root use:
$ sudo mysqladmin -u root -p oldpassword newpassword
To update the password for another user, as root use:
$ sudo mysqladmin -u user-name -p oldpassword newpassword
Also you might want to look at mysql_secure_installation, it will make your mysql installation more secure, it is recommended that you use it for production servers.
You first need to enter in your MySQL database : then copy and paste the following
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('SETYOURPASSWORDHERE');
Be sure your user is root
I am trying the following mysql command:
zcat ***.sql.gz | mysql -u root -p dbname
Maybe the question applies equally to the following, simpler command:
mysql -u root -p dbname
You can find this kind of snippet all over the internet, and it usually works. It should prompt you for the db user's password (in this case, the db root pw), and then use "dbname" as the database name. Only today it did NOT ask me for the root pw, and instead just said
Access denied for user 'root'#'localhost' (using password: YES)
I assume that in this case mysql thought that "dbname" is the password. I just don't understand why in the usual case it understands that "dbname" is the database name.
I have also seen this variation:
mysql -u root -pthepassword dbname
Here the interesting thing is that -u is followed by a space, but -p is not.
The question: How does mysql distinguish the dbname from the password?
I exported all databases of a MySQL server by:
mysqldump -u root -p --all-databases > /tmp/dbs.sql
Then I copied the file (by scp) on another server, which has the same MySQL version, and imported it with:
mysql -u root -p < dbs.sql
I can access to MySQL only as root. With other users, I obtain:
~$ mysql -u jag -p
Enter password:
ERROR 1045 (28000): Access denied for user 'jag'#'localhost' (using password: YES)
However, selecting all users in mysql.user table, I can see that all user accounts where imported. So, how can I overcome this problem, without resetting all user passwords?
You need to specify username and password, you can try this:
mysql -u USERNAME -pPASSWORD -h HOSTNAMEORIP DATABASENAME
Note that there is no space between -p parameter and password!
You can check this: http://dev.mysql.com/doc/refman/5.0/en/connecting.html
After following all the similar answers for this issue, I've solved it in CentOS with this:
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
please make sure to grant privileges to that user u want to restore with, in this case 'jag'
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