user2849739
user2849739

Reputation: 11

MYSQL no access/privileges how to change from a useless user to root?

The problem I have is when I get into the commandline for mysql I enter as ''@'localhost' and have no access to anything useful, I'm trying at the moment to get data back to a php page so I need a valid username and password. Is there a way I can create a user account with my feeble resources? Is there a way I can enter the MySQL commandline as root?

Any help appreciated.

Upvotes: 1

Views: 73

Answers (3)

jds
jds

Reputation: 8259

Previously, I was getting Access denied... errors for every command, but I was able to resolve the issue after reading RobbieE's suggestion and this documentation:

  1. First, start mysql from the command line as the root user; this is the solution to your original question:

mysql -u root

Now if you'd like to password-protect root...

  1. To see which accounts exist and check their passwords, execute:

SELECT User, Host, Password FROM mysql.user;

You should see an ASCII table, something like this:

+------+--------------------+----------+
| User | Host               | Password |
+------+--------------------+----------+
| root | localhost          |          |
| root | 127.0.0.1          |          |
|      | localhost          |          |
+------+--------------------+----------+
  1. Finally, set the password for each root user a la:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('plaintext-password');

Re-execute statement 2 to verify the password was set correctly. You now have a useful and protected MySQL user for localhost. Do this again for 127.0.0.1 and any other hosts you may have.

Upvotes: 0

Sasanka Panguluri
Sasanka Panguluri

Reputation: 3128

When you install MySQL, it asks you to enter credentials for the root user. If you had not done something like that, I recommend you to reinstall.

Moreover, I would recommend you to use a good package like PHPMyadmin to simplify your operations with databases. http://www.phpmyadmin.net/home_page/news.php

You could also try Xampp, which has everything in a package - PHP, Tomcat, Mercury , Filezilla, PHPMyadmin and more if you'd like. You will spend almost 0 time configuring anything. http://www.apachefriends.org/en/xampp.html

Upvotes: 0

Guillaume Poussel
Guillaume Poussel

Reputation: 9822

If you user is root without any password (like a default MySQL setup), you should be able to connect using:

mysql --user=root

If you need to specify pwd as password:

mysql --user=root -ppwd

Check MySQL command line guide for other details.

Upvotes: 1

Related Questions