Change MySQL password without displaying it - mysql

There are many solutions and documentation on the web that have an answer on how to change a MySQL user password. All of them though, display the password to be changed. Is there a way that the new password be hidden or replaced by asterisks for increased security?

You can use the mysqladmin command:
mysqladmin -u user -p -h localhost password
where:
user: is the username.
localhost: you can change this to your host, or leave it as is for localhost.
password: is the mysqladmin command that instructs the change of password.
By executing the above command, you will be prompted to enter you current password and then type your new password, both without the characters being displayed on the screen.

Related

Can't run mysql commands as root linux user

As linux root user:
root#local:~# mysql
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using
password: NO)
I'm confused. Shouldn't the root user be able to run mysql without additional authentication? How do I fix this?
Your root account in MySql has a password. Try this
mysql -p
and enter the password you, or somebody set.
If that doesn't work try
mysql -h localhost -u root -p
It that doesn't work you'll need to reset your MySql root password. That's the topic of several tutorials on the 'toobz
If the MySQL root user has a password, using the default authentication plugin, then you must provide a password to connect, full stop. You can configure an account with no password, but that's a habit you should avoid.
You can provide a password by any of the following means:
Entering it interactively with the -p option
Entering it in plaintext in the commandline like -p<mypassword>
Storing it in plaintext in your ~/.my.cnf file in the [client] section (see https://dev.mysql.com/doc/refman/8.0/en/option-files.html)
Storing it in an obfuscated form in your ~/.mylogin.cnf file (see https://dev.mysql.com/doc/refman/8.0/en/mysql-config-editor.html).
There's also a way to provide a password through environment variables, but that's discouraged now because it's really not secure.
ALTER USER 'root'#'localhost' IDENTIFIED WITH auth_socket;

MySQL command prompt doesnt require password

I have installed MySQL on my machine. I can log in by directly opening the MySQL 5.6 command line client from the start menu and it prompts me for my password. When I enter the correct password it lets me in, and if it's wrong, it kicks me out.
When I run MySQL from the command prompt, the ONLY way I can log in (using both root user or another user I have created) is to enter no password. If I enter my password it says access denied to root#localhost... yada yada ... using password:YES
so in summary if i type
mysql -u root -p
password: [mypassword]
it doesn't work, throwing the error Access denied, using password yes
However, if I do
mysql -u root -p
password: [blank]
it logs in. same behavior for any other user.
That makes no sense to me cause in every other application I have to enter a password to get in.
any ideas?
This is because the user root has no password by default unless specified during installation. Trying to login with a password is impossible if there is no password.

mysql access denied for user 'odbc'#'localhost' to database

I installed MySql5.5 and set password during installation but when I try to use mysql from windows command prompt, I have get the error:
access denied for user 'odbc'#'localhost' to database password = 'YES'
I would like to change it back into "root#localhost" as well as to reset the password but I can't log in mysql.
How do I login to mysql with root?
You're trying to use the mysql interactive shell? You can specify usernames at the command line:
c:\> mysql -u root -p
where
-u = specify username
-p = prompt for password
I fixed this by implementing a little hacky solution. Downloaded hxd (hex editor) and searched for 'ODBC' (there should only be one match) and just changed it to 'root'.
You are logging into mysql with a default no-rights user, you have to login as root if you want to do everything:
C:\Program Files\MySQL\MySQL Server 5.5\bin>mysql.exe -u root -p
Enter Password: *****
If you never specified a root password it should be blank, if you did, you have to remember what it was, or find out how to reset the root password.

'Access denied for user 'root'#'localhost' (using password: NO)'

I'm trying to set the password of the user root but I'm gettin the error below, any idea?
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root#localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD '*436576511F70A4E3B305E1AB8E209851945D8687' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> exit
Bye
root#tirengarfio:/var/www/rs2# mysqladmin -u root password foo,
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
$ mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
password is to be typed literally. It's a command. You don't have to substitute password with your actual password.
# /etc/init.d/mysqld stop
Stopping MySQL: [ OK ]
# mysqld_safe --skip-grant-tables &
[1] 13694
# Starting mysqld daemon with databases from /var/lib/mysql
# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
Set/Change password:
mysqladmin -u root -p password
Login to MySQL console:
mysql -u root -p
To exit the console:
.\q
when trying to run this command i got the same error
sudo mysqladmin create asteriskcdrdba
i simply add a few lines to the code
-u root -p
and pressed the enter key. i then typed my password and hit enter. Linux liked my command as nothing more was displayed
so maybe try
sudo <your command here> -u <username> -p
after that hit enter and enter your password
Those are all good answers, but don't quite touch the deep cause of the problem one most likely has if faced with the OP question. That is, not knowing the ORIGINAL "starting" password created during the installation time.
And all these command lines with "-u root ..." etc. imply knowing and using THAT password.
Now this part from the original installation message may help anyone facing the problem above:
Initial password for first time use of MySQL is saved in $HOME/.mysql_secret
ie. when you want to use "mysql -u root -p" first you should see password
in /root/.mysql_secret
This is basically a more detailed version of a previous answer.
In your Terminal, go to the location of your utility program, mysqladmin
For example, if you were doing local development and using an application like M/W/XAMP, you might go to the directory:
/Applications/MAMP/Library/bin
This is where mysqladmin resides.
If you're not using an application like MAMP, you may also be able to find your local installation of mysql at: /usr/local/mysql
And then if you go to: /usr/local/mysql/bin/
You are in the directory where mysqladmin resides.
Then, to change the password, you will do the following:
At your Terminal prompt enter the exact command below (aka copy and paste) and press enter. The word "password" is part of the command, so don't be confused and come to the conclusion that you need to replace this word with some password you created previously or want to use in the future. You will have a chance to enter a new password soon enough, but it's not in this first command that you will do that:
./mysqladmin -u root -p password
The Terminal will ask you to enter your original or initial password, not a new one yet. From the above image you provided, it looks like you have one already created, so enter it here:
Enter password: oldpassword
The Terminal will ask you to enter a new password. Type it here and press enter:
New password: newpassword
Then the Terminal will ask you to confirm the new password. Type it here and press enter:
Confirm new password: newpassword
Reset or restart your Terminal.
In some cases, as with M/W/XAMP, you will have to update this new password in various files in order to get your application running properly again.
open my.cnf using following path
C:\xampp\mysql\bin
under # The following options will be passed to all MySQL clients
#password remove # comment sign if it is there password = "newpassword"
save file
close file
re-start mysql
Firstly, go to the folder support-files on terminal, and start the server
by mysql.server start,
Secondly, go to the folder bin on terminal or type
/usr/local/mysql/bin/mysqladmin -u root -p password
It would ask you for the old temporary password which was given to you while installing Mysql, type that and type in your new password and it would work.

mysql is prompting for password even though my password is empty

I installed mysql on ubuntu server and did not specify password. When I do
mysql -u root -p
it prompts for password and without providing any input I just hit enter and it works.
Now I need to perform some operation on the database using cron job. My cron job does not work because mysql prompts for a password. I tried doing
mysql -u root -p'' my_database
but that did not work either.
Any suggestion?
Go like this mysql -u root --password="" dbname
Try not asking mysql to prompt for the password, 'mysql -u myuser'. I would suggest you create an account with only the required privileges to do this. Also limit its access to localhost. Put a password on root.
I installed mysql on ubuntu server and did not specify password. When
I do
mysql -u root -p
-p brings up the password prompt. If you do not have a password, then you do not want to do that.
Just write:
mysql -u root
For the love of god, get a password on that account!
For passing the password in the command use -p$PASSWORD. In the following example, user/password is root/root:
mysql -proot -D my-db -u root -h 127.0.0.1 -e "select * from my_table"
IMPORTANT: notice that there is no space between -p and the password in -proot
Check MySQL Documentation for how to reset your password, since I found no way to enter a password either. You could use the following: http://dev.mysql.com/doc/mysql-windows-excerpt/5.0/en/resetting-permissions-windows.html
Which states that you have to create a file with the following query:
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
FLUSH PRIVILEGES;
And then start up mysqld service with the --init-file parameter (see the documentation for more information about this). This should reset your root password.
Why don't you specify a password for root? For security reasons and your script would work.
Mysql's "root" account should have a password; otherwise anyone with an account on your machine has full access to the database.
Set a password (e.g. with SET PASSWORD)
Add the password to ~/.my.cnf
If you want more sane authentication options, I recommend Postgres.