I was given a code repo which requires mysql in command line.
I am using Mac OS 10.11
First, I installed MySQL Community Server from http://dev.mysql.com/downloads/mysql/ and install it by running the PKG file.
After that, I opened System Preferences to start MySQL Server.
Then, I tried to execute
/usr/local/mysql/bin/mysql -uroot
and there is an error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
How could I have mysql in command line?
Thanks,
Typically the command is:
/usr/local/mysql/bin/mysql -u root -p
which will prompt you for your root password (which might be blank unless you changed it)
You can also use:
/usr/local/mysql/bin/mysql -u root -p[password]
but keep in mind that password will be visible onscreen as you are typing it unlike the straight -p option that will hide your password as you type it when prompted.
Take a look at the options for mysql: https://dev.mysql.com/doc/refman/5.6/en/mysql-command-options.html
In your case, I'd try /usr/local/mysql/bin/mysql -u root -p then hit enter. mysql will prompt you for your password - type in in and hit enter again. If it's wrong mysql will let you know and then you'll have to go about resetting the mysql root password.
https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/ is a reasonable set of instructions for doing that in OS X (may be out of date for your version of MySQL but the comments will help) but YMMV depending on where mysql was installed, etc...
Basically those instructions are:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
mysql -u root
ALTER USER 'root'#'localhost' IDENTIFIED by 'password';
FLUSH PRIVILEGES;
exit
sudo /usr/local/mysql/support-files/mysql.server start
Which
Stops mysql
Sets mysql to run without bothering with privileges
Opens a mysql prompt
Updates the root password to 'password' - you should use something else here.
"Cleans" passwords (some might say this is unnecessary)
Exits the mysql prompt
Starts mysql
That should allow you to run mysql -u root -p and use the new password set in #4.
I am trying to install openEMM on a Centos 6 VDS and have run into a snag. I am following the instructions on this page: http://www.roothelp.net/install-openemm-on-centos-6-x/. Everything has gone along fine until I reached the following commands:
service mysqld start
/usr/bin/mysql_secure_installation
cd /usr/share/doc/OpenEMM-2013/
mysqladmin -u root -p create openemm
The service starts fine, but when I run /usr/bin/mysql_secure_installation I get the following:
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and you
haven't set the root password yet, the password will be blank, so you
should just press enter here.
Enter current password for root (enter for none):
This is where the problems start. Apparently Plesk 11 does not create a root user account, using "admin" instead. None of my passwords work here, neither my actual SSH root password, my admin password, or any other password I've assigned. I even started mysql with this script to ensure I had the correct root password:
>UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
>FLUSH PRIVILEGES;
I tried this to ensure I had the correct password: /usr/local/psa/bin/admin --show-password
None of this has worked, and I am unable to run the command. How can I get around this? If I skip that command (GoDaddy support advised me that it was only configuring MySql, which is already installed with Plesk) and try to run
mysqladmin -u root -p create openemm
I am again asked for a root password and none work. I also tried this command instead, using the admin password but still had the same problem.
mysqladmin -u admin -p create openemm
I suspect I'll have to create a database called openemm through Plesk. Any ideas?
If you haven't set the mysql root password you can set it through the command
`$> mysqladmin -u root password "yourpassword"`
and if you want to change (or update) a root password, then you need to use the following command:
$> mysqladmin -u root -p'oldpassword' password newpass
Then you can create your database. In your case I think the mysql root password is just entered as the secure script asked you.
I cannot figure out my MySQL root password; how can I find this out? Is there any file where this password is stored?
I am following this link but I do not have directadmin directory in local.
thanks to #thusharaK I could reset the root password without knowing the old password.
On ubuntu I did the following:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking
Then run mysql in a new terminal:
mysql -u root
And run the following queries to change the password:
UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;
In MySQL 5.7, the password field in mysql.user table field was removed, now the field name is 'authentication_string'.
Quit the mysql safe mode and start mysql service by:
mysqladmin shutdown
sudo service mysql start
You can't view the hashed password; the only thing you can do is reset it!
Stop MySQL:
sudo service mysql stop
or
$ sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
$ sudo mysqld_safe --skip-grant-tables
(above line is the whole command)
This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
$ mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
MySQL 5.7 and over:
mysql> use mysql;
mysql> update user set authentication_string=password('password') where user='root';
Exit the MySQL CLI:
mysql> exit
Restart MySQL in normal mode, first stopping the safe mode instance:
$ mysqladmin -u root -p shutdown # (when prompted, enter the new password just set)
$ sudo service mysql start
or
$ sudo /usr/local/mysql/support-files/mysql.server start
Your new password is 'password'.
MySQL 5.7 and above saves root in MySQL log file.
Please try this:
sudo grep 'temporary password' /var/log/mysqld.log
One thing that tripped me up on a new install of MySQL and wondering why I couldn't get the default password to work and why even the reset methods where not working.
Well turns out that on Ubuntu 18 the most recent version of MySQL server does not use password auth at all for the root user by default. So this means it doesn't matter what you set it to, it won't let you use it. It's expecting you to login from a privileged socket.
mysql -u root -p
This will not work, even if you are using the correct password.
Instead, you need to use:
sudo mysql
that will work with out any password.
then once you in you need type in
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'Password you want to use';
Then log out and now it will accept your password.
Follow these steps to reset password in Windows system
Stop Mysql service from task manager
Create a text file and paste the below statement
MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('yournewpassword');
MySQL 5.7.6 and later:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'yournewpassword';
Save as mysql-init.txt and place it in 'C' drive.
Open command prompt and paste the following
C:\> mysqld --init-file=C:\\mysql-init.txt
You cannot find it. It is stored in a database, which you need the root password to access, and even if you did get access somehow, it is hashed with a one-way hash. You can reset it: How to Reset the Root Password
This worked for me:
On terminal type the following
$ sudo mysql -u root -p
Enter password://just press enter
mysql>
Unless the package manager requests you to type the root password during installation, the default root password is the empty string. To connect to freshly installed server, type:
shell> mysql -u root --password=
mysql>
To change the password, get back the unix shell and type:
shell> mysqladmin -u root --password= password root
The new password is 'root'. Now connect to the server:
shell> mysql -u root --password=
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Oops, the password has changed. Use the new one, root:
shell> mysql -u root --password=root
...
blah, blah, blah : mysql welcome banner
...
mysql>
Bingo! New do something interesting
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
Maurycy
As addition to the other answers, in a cpanel installation, the mysql root password is stored in a file named /root/.my.cnf. (and the cpanel service resets it back on change, so the other answers here won't help)
you can view mysql root password , well i have tried it on mysql 5.5 so do not know about other new version well work or not
nano ~/.my.cnf
The default password which worked for me after immediate installation of mysql server is : mysql
The procedure changes depending the version of MySql. Follow the procedure exactly as described for your version:
HINTS - Read before the instructions page for your version of MySql*
In step 5: Instead of run CMD, create a shortcut on your desktop calling CDM.exe. Then right-click on the shortcut and select "Execute as Administrator".
In step 6: Skip the first proposed version of the command and execute the second one, the one with the --defaults-file parameter
Once you execute the command, if everything is ok, the CMD window remains open and the command of step 6 continues executing. Simply close the window (click 'x'), and then force close MySQl from the Task Manager.
Delete the file with the SQL commands, and start again MySQL. The password must be changed now.
5.0
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
5.1
http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html
... just change the version in the link (5.5, 5.6, 5.7)
In your "hostname".err file inside the data folder MySQL works on, try to look for a string that starts with:
"A temporary password is generated for roor#localhost "
you can use
less /mysql/data/dir/hostname.err
then slash command followed by the string you wish to look for
/"A temporary password"
Then press n, to go to the Next result.
I solved this a different way, this may be easier for some.
I did it this way because I tried starting in safe mode but cannot connect with the error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
What I did was to connect normally as root:
$ sudo mysql -u root
Then I created a new super user:
mysql> grant all privileges on *.* to 'myuser'#'%' identified by 'mypassword' with grant option;
mysql> quit
Then log in as myuser
$ mysql -u myuser -p -h localhost
Trying to change the password gave me no errors but did nothing for me so I dropped and re-created the root user
mysql> drop user 'root'#'localhost;
mysql> mysql> grant all privileges on *.* to 'root'#'localhost' identified by 'mypassword' with grant option;
The root user is now working with the new password
Using Debian / Ubuntu mysql packages, you can login with user debian-sys-maint, which has all the expected privileges, the password is stored in the file /etc/mysql/debian.cnf
Answers provided here did not seem to work for me, the trick turned out to be:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'test';
(complete answer here: Change user password in MySQL 5.7 with “plugin: auth_socket”)
System:
CentOS Linux 7
mysql Ver 14.14 Distrib 5.7.25
Procedure:
Open two shell sessions, logging in to one as the Linux root user
and the other as a nonroot user with access to the mysql command.
In your root session, stop the normal mysqld listener and start a
listener which bypasses password authentication (note: this is a
significant security risk as anyone with access to the mysql
command may access your databases without a password. You may want
to close active shell sessions and/or disable shell access before
doing this):
# systemctl stop mysqld
# /usr/sbin/mysqld --skip-grant-tables -u mysql &
In your nonroot session, log in to mysql and set the mysql root password:
$ mysql
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> quit;
In your root session, kill the passwordless instance of mysqld and restore the normal mysqld listener to service:
# kill %1
# systemctl start mysqld
In your nonroot session, test the new root password you configured above:
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql>
I was stuck with this problem for a couple of minutes and the following was the only solution that actually worked:
https://phoenixnap.com/kb/access-denied-for-user-root-localhost
sudo mysql
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password';
mysql -u root -p
In case you already set a password in the past the mysql -uroot -p solution will not work,
In my case I used some of the answers above to solve this (Ubuntu 16). The result was:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
if you see this text in the screen:
mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
then do:
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo mysqld_safe --skip-grant-tables & # Look at the & at the end!
Enter other terminal to set your password like this:
sudo mysql -u root
mysql> use mysql;
mysql> SET PASSWORD FOR 'root'#'localhost'=PASSWORD('__NEW__PASSWORD__');
mysql> flush privileges;
mysql> quit;
then restart the service and login
# end mysqld_safe in the other terminal
sudo service mysql start
sudo mysql -h 127.0.0.1 -uroot -p
For MySQL 5.5 on Windows 10
You can't find the password as it is hashed in the table, so resetting it is the only option.
The solution of importing the new password script by .txt file, as offered by Lokesh kumar Chippada, didn't work for me. I found that the command prompt just froze after initiating the import.
I added skip-grant-tables to the my.ini file as per the top the answer on this SO post by tonycoupland.
I was then able to login to mysql from the command line
$> mysql
and then in mysql
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
See 'B.3.3.2.3 Resetting the Root Password: Generic Instructions' on mysql dev page. I have now removed skip-grant-tables from the my.ini file, and I can login as a root user using the new password I created.
Go to phpMyAdmin > config.inc.php > $cfg['Servers'][$i]['password'] = '';
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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I am trying to set the root password for MySQL in the terminal in Mac OS X Lion, and I am having issues. Every time I use the line:
/usr/local/mysql/bin/mysqladmin -u root password ****** (where ****** is the password I want to set)
I receive the error:
/usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
I have not set a password previously, so I do not know why I am receiving this error.
Here is the procedure to reset password of root user.
1) Stop mysql (Kill mysql process or run following command)
sudo /usr/local/mysql/support-files/mysql.server stop
2) Start it in safe mode
sudo mysqld_safe --skip-grant-tables
3) Open another terminal and run the following command (Keep last terminal open)
mysql -u root
4) Run the following command with suitable new password on the mysql console
For MySQL 5.7+:
mysql > UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
For earlier versions:
mysql > UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
5) mysql > FLUSH PRIVILEGES;
6) Quit from both terminals and open new terminal and connect to mysql with root user and new password
mysql -uroot -p
Type:/usr/local/mysql/bin/mysqladmin -u root -p password
When it asks for a password, not not enter anything, just hit enter.
It will then ask you to enter new password, then confirm.
Finished.
for creating password first time use
mysqladmin -u root password NEWPASSWORD
updating old password use
mysqladmin -u root -p'oldpassword' password newpass
Source = http://www.cyberciti.biz/faq/mysql-change-root-password/
I'm on Yosemite, but on Maverick has the same problem.
- Fix the 2002 socket error first if you haven’t done
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
An then try
sudo /usr/local/mysql/bin/mysqladmin -u root -p password
That isn't how you set the password. That is how you login to mysql.
If you don't have a password set, you login using:
mysql -u root
and that will get you to the MySQL command line.
Instead of doing that just use the following to change the password.
mysqladmin -u root password NEWPASSWORD
cd /usr/local/mysql/bin
./mysqladmin -u root password root
To set your root password after installing:
Ensure MySQL is not running, stop it if you ran it.
On a Terminal do sudo mysqld_safe --skip-grant-tables to run MySQL bypassing the authentication.
Inside mysql do FLUSH PRIVILEGES;
Then reset by SET PASSWORD FOR root#'localhost' = PASSWORD('password'); where 'password' is your chosen password.
FLUSH PRIVILEGES; one more time
This fix it for me:
After this is going to ask you for your Super User password and then for the new password.
sudo /usr/local/mysql/bin/mysqladmin -u root -p password
You want to reset or set a new root password?
Steps for MySQL 5.7.5 and earlier:
Open a Terminal Window:
Stop mysql server if it is running:
sudo /usr/local/mysql/support-files/mysql.server stop
Restart it with the --skip-grant-tables option:
sudo mysqld_safe --skip-grant-tables
Open another Terminal Window:
Type:
mysql -u root
Reset root password (i.e. for localhost)
UPDATE mysql.user
SET authentication_string = PASSWORD(‘MyNewPass’), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
Now your password for root#localhost is MyNewPass. You can change it:
Close all Terminal Windows. Open a new Terminal Window and type:
mysqladmin -u root -p'MyNewPass' password '123456'
Now your root password is 123456
You should see below warning message, you can ignore it if you are changing your root#localhost password:
mysqladmin: [Warning] Using a password on the command line interface
can be insecure. Warning: Since password will be sent to server in
plain text, use ssl connection to ensure password safety.
Check if your root password is successfully changed:
mysql -u root -p'123456' -e 'show databases;'
Output:
mysql: [Warning] Using a password on the command line interface can be
insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
This is working on macOS Sierra
step 1: open terminal
step 2: paste the following command
sudo /usr/local/mysql/support-files/mysql.server restart
Your terminal should show this :
Users-MacBook-Air:~ usr$ sudo /usr/local/mysql/support-files/mysql.server restart
Password:
ERROR! MySQL server PID file could not be found!
Starting MySQL
.. SUCCESS!
Step 3: Make sure SQL server is running
Step 4: Open the MYSQL working and click the local instance
Step 5: type old password and new password
You will lose all databases
step 1: open terminal
step 2: delete folder mysql
sudo rm -rf /usr/local/mysql
step 3: installed mysql again, after the installation is generated a new password
Step 1:
mysql -u root -p
It will ask
Enter password:
Welcome to the MySQL monitor.
You can check default databases
mysql> show databases;
mysql> show tables;