简体   繁体   中英

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

I know this question is asked many times, and I read al lot of questions going about this, but I think mine is different.

I use a Mac with version 10.10.3 and a Terminal to do my commands.

I am trying to create a local database (and I did it before), but for some reason the access is constantly denied.

This is how my terminal looks like:

iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -v
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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.

Reading history-file /Users/639/.mysql_history
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit;
Writing history-file /Users/639/.mysql_history
Bye
iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, 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> create database wordpress_db;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'wordpress_db'

As you can see I can login to mysql, but I have no permission to create a database.

I tried to login like:

$ /usr/local/mysql/bin/mysql -u root

And:

$ /usr/local/mysql/bin/mysql -u root -p

I have no password, but I can enter mysql without one, but then I cannot create a database.

Select current_user(); returns this:

mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| @localhost     |
+----------------+
1 row in set (0,00 sec)

try to start mysql with --skip-grant-tables

mysqld --skip-grant-tables

then connect to your mysqld without username/password using mysql command line

shell> mysql

then issue command

> mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
>        WHERE User='root'; mysql> FLUSH PRIVILEGES;

First, try this command:

sudo dpkg-reconfigure mysql-server-5.5

but replace 5.5 with your current mysql-server version, and you will be asked for the new root password.

If that doesn't work, try these instructions from the manual.

I had the same issue. All I had to do was to log out of the shell and log in again using mysql -u root -p into my mysql shell.

This will then prompt for a password. Since I didn't use a password while setting up, I pressed enter and that was it for me.

I hope this works for you too :) .

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