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,
Open macOS system preferences and select the MySQL preference panel, and then execute Start MySQL Server. The Instances page includes an option to start or stop MySQL, and Initialize Database recreates the data/ directory.
The mysql Command not found error occurs because your computer can't find a program associated with the command on your computer's PATH environment variable. The PATH environment variable is a list of directories specifying where your computer should look for a program to run from the Terminal.
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
That should allow you to run mysql -u root -p
and use the new password set in #4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With