简体   繁体   中英

Access denied for user 'root'@'localhost'

I'm using Mysql on My MacBookPro osx 10.9. when i type the command in the terminal

Mihikas-MacBook-Pro:~ mihika$ mysql mysql does indeed start.

But when i show databases:

mysql> show databases;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+

2 rows in set (0.00 sec)***

and i can't add any databases to this

mysql> create database db;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database '

i even tried this command:

Mihikas-MacBook-Pro:~ mihika$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Basically for any command i type it gives me "access denied". i even tried creating new user..but i guess i need to be the root user. when i was logging in as root ,it constantly denied my password whereas it's actually right.

I installed mysql using: bash <(curl -Ls http://git.io/eUx7rg)

i am new to Mac OSX please give me a step by step guide on this. and also tell em how to switch between users.

i even uninstalled and reinstalled mysql to try solving the problem.

thanks in advance. :)

The script you used to install MySQL generated you a password, and you need to use that password to connect to the database.

From the script:

mypass="$(cat /dev/urandom | base64 | tr -dc A-Za-z0-9_ | head -c8)"
echo $mypass > ~/Desktop/MYSQL_PASSWORD

From the lines above, I'd guess that there's a password on your desktop named MYSQL_PASSWORD . You can use it to connect to the database using this command:

mysql -uroot -p

When prompted, enter the password from the file on the desktop.

To be extra tricky, you could use this command to connect to the database:

mysql -uroot -p`cat ~/Desktop/MYSQL_PASSWORD`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM