0

I just recently installed mySQL on my Mac running 10.10.3, but I can't create any tables or modify anything associated with my databases. When I start mysql I logs me in as '@localhost'

mysql> select user();
+-----------------------+
| user()                |
+-----------------------+
| username@localhost    |
+-----------------------+
1 row in set (0.00 sec)

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

mysql> CREATE DATABASE ign;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'ign'

I even try running this to log into my sql.

mysql -u username -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'username'@'localhost' (using password: YES)

I am so lost and any help would be greatly appreciated.

Emre801
  • 3,043
  • 5
  • 25
  • 28
  • mysql -uUSERNAME -pPASSWORD – Drew Jun 18 '15 at 22:37
  • 2
    Space between the -u flag and username is fine, unlike -p where it should be omitted. Are you trying to log in as root or who? – ficuscr Jun 18 '15 at 22:38
  • mysql --user=fred7 --password=OpenSesame – Drew Jun 18 '15 at 22:39
  • I want to log in as root, whatever allows me to edit my databases – Emre801 Jun 18 '15 at 22:39
  • possible duplicate of [MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)](http://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw) – Machavity Jun 18 '15 at 22:40
  • mysql -u root -p `(will prompt for password)` – Drew Jun 18 '15 at 22:40
  • @DrewPierce when I do that I get the following, mysql -u root -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) – Emre801 Jun 18 '15 at 22:41

1 Answers1

3

If you just installed it and do not know the root password, or are unsure of the password, try resetting the root password (assuming you have admin rights on the machine). Then create a user and apply the applicable grant permissions.

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
Cohan
  • 4,384
  • 2
  • 22
  • 40
  • 1
    root on one ain't the same as root on the other – Drew Jun 18 '15 at 23:01
  • 1
    If you're referring to root in the OS vs root in the MySQL, you are correct, but if you are root on the machine, you can stop the MySQL process and then restart it telling it to ignore the grant tables (so you don't need the MySQL root password) and then you can just set the password for MySQL root. When you're done, you can restart the MySQL process again so that it starts normally. – Cohan Jun 18 '15 at 23:04
  • Step # 4: Set a new root password.how would I do that? – Emre801 Jun 19 '15 at 00:00
  • I've had to do this a few times. I'm happy to make it easier for someone else. – Cohan Jun 19 '15 at 01:14