I just installed MySQL on Mac OS X. The next step was setting the root user password, so I did this next:
- Launch the terminal app to access the Unix command line.
Under the Unix prompt I executed these commands:
$ cd /usr/local/mysql/bin $ ./mysqladmin -u root password 'password'
But, when I execute the command
$ ./mysql -u root
, this is the answer:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 224
Server version: 5.5.13 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
I can get into the mysql
command line without any password!
Why is this?
Much has changed for MySQL 8. I've found the following modification of the MySQL 8.0 "How to Reset the Root Password" documentation works with Mac OS X.
Create a temp file
$HOME/mysql.root.txt
with the SQL to update the root password:ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<new-password>';
This uses
mysql_native_password
to avoid the Authentication plugin 'caching_sha2_password' cannot be loaded error, which I get if I omit the option.Stop the server, start with an
--init-file
option to set the root password, then restart the server:mysql.server stop mysql.server start --init-file=$HOME/mysql.root.txt mysql.server stop mysql.server start
The instructions provided in the mysql website is so clear, than the above mentioned
$ sudo /usr/local/mysql/support-files/mysql.server stop
$ sudo /usr/local/mysql/support-files/mysql.server start --skip-grant-tables
/usr/local/mysql/support-files/mysql
exit
or Ctrl + z$ sudo /usr/local/mysql/support-files/mysql.server start
/usr/local/mysql/support-files/mysql -u root -p
Reference: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
In the terminal, write
mysql -u root -p
and hit Return. Enter the current mysql password that you must have noted down. And set the passwordSET PASSWORD = PASSWORD('new_password');
Please refer to this documentation here for more details.
When I installed OS X Yosemite,I got problem with Mysql. I tried lot of methods but none worked. I actually found a quite easy way. Try this out.
sudo su
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
mysql -u root
UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
FLUSH PRIVILEGES;
For new Mysql 5.7 for some reason bin commands of Mysql not attached to the shell:
Restart the Mac after install.
Start Mysql:
System Preferences > Mysql > Start button
Go to Mysql install folder in terminal:
$ cd /usr/local/mysql/bin/
Access to Mysql:
$ ./mysql -u root -p
and enter the initial password given to the installation.
In Mysql terminal change password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword';
Once you've installed MySQL, you'll need to establish the "root" password. If you don't establish a root password, then, well, there is no root password, and you don't need a password to log in.
So, that being said, you need to establish a root password.
Using terminal enter the following:
Installation: Set root user password:
If you've made a mistake, or need to change the root password use the following:
Change root password: