Launching MySQL without a password [closed] - mysql

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have installed MySQL. During the process of installation I was asked whether I want to determine a password for root user. Well, I entered a password.
Now I can access it through
mysql -u root -p
Well, it works.
The question is what will happen if I use just mysql command?
Well. This is what appears:
mysql>
I'm a bit confused. If I organize a password, how can I get access without entering it.
What privileges do I have in this case?

You are connected as ROOT (you can create,detele, alter,procedures,triggers,tables,configurations, users, Dbs, etc) , so you can do whatever you want. It's the same if you do:
mysql -u root -p
or
mysql -u root -p "my_root_pass"
(of course if you have one)
the mysql> just mean that you are connected to your database, however it's not recommended that use that user, also you should give him a password with the grant command.
if you want to see the user that you are using, you can use:
mysql> select current_user;

The fact that you can "enter" MySQL doesn't mean that you have the ability to do anything. Try and create a database without supplying a password. Try and access a database without the password... I'm fairly sure that you won't be able to do either.

Try to access your database / tables when you see mysql> If it doesn't give you an error, then your password most likely is still not set for the root account. If this is the case, you can go ahead and execute this query to set your root password.
grant all privileges on *.* to 'root'#'localhost' identified by 'your new password';

Related

MySQL rejects valid password via Command line on Windows [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
After successfully creating new users 'u1' and 'u2' in mysql.user table and setting their passwords to pass and PASSWORD('pass') respectively, I am unable to log in as either user. Please review the commands below and help me figure out what I'm missing. Note that each concealed password is just the string "pass"
Why is access denied? Note that I was the root user (with all privileges) when I created the users u1 and u2
CREATE USER 'u3'#'localhost' IDENTIFIED BY 'pass';
CREATE USER 'u4'#'localhost' IDENTIFIED BY 'pass';
A good question from the OP prompted this: The two users just created above have basically no privileges to the server yet, except to login and sit there. They are awaiting the Grant command to allow them various access rights to certain databases.
Then try them. There is a reason the create user command was created.
After that you deal with grants to particular databases. And revisit the host issue.
But this is just a test.
Then to login from o/s command line, it is mysql -uu3 -p and ENTER. You will then be prompted for password. It is highly recommended not to login as root unless you know you are doing maintenance. Also, do not bake the password into a script file such as mysql -uu3 -ppass as your file could be poached and your password too. Note, no space after -u and -p in my example.
And yes, with the -p switch, when you are prompted for password, it is not visible.
Create User command from the Manual.
Drop User command from the Manual.
Grant command from the Manual. Be very careful not to use wildcards and WITH GRANT OPTION with the Grant command. You need to be careful to grant the minimal rights for users necessary for them, versus being lazy and applying wildcards.
Have you tried restarting the server before connecting? From The MySQL Documentation:
If you modify the grant tables directly using statements such as INSERT, UPDATE, or DELETE, your changes have no effect on privilege checking until you either restart the server or tell it to reload the tables. If you change the grant tables directly but forget to reload them, your changes have no effect until you restart the server. This may leave you wondering why your changes do not seem to make any difference!

Deleted all users on mysql [duplicate]

This question already has answers here:
mysql: cannot create user after delete the user with phpmyadmin
(2 answers)
Closed 9 years ago.
I accidentally all my user accesses to phpMyAdmin and I have no clue how to re institute a user so I can access mysql again.
Right now I have no access to even sign in MySQL when using the commandline and phpMyAdmin just displays an error.
Well, if you managed to delete the root user, I assume you have the ability to restart the mysql daemon. Try killing mysql, and restarting it:
mysqld –skip-grant-tables
then
mysql
Which should give you unfettered access to your user table.
Resetting the Root Password
Connect to the mysqld server with this command:
shell> mysql
Issue the following statements in the mysql client. Replace the password with the password that you want to use.
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
Looks like you've not just delete the table, but also the entire mysql permission database. You need now to find the script 'mysql_install_db'. Once you run it, you will recreate the mysql permissions database. Now you need recreate users for any application you've set up previously.

Access MySQL databases with only root password [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
so I have a dilemma. I am taking over from another developer and there's a box to which I only have root access, and I need to download the MySQL database from it. So I root in, and type mysql in the command line and get:
Access denied for user 'root'#'localhost' (using password: NO)
Then, I try mysql --user=root --password={myrootpassword} and it says:
Access denied for user 'root'#'localhost' (using password: YES)
I have no other information than the root password. Obviously this should be enough; how do I access my databases? Is the solution to create a new MySQL username?
Stop the mysql daemon, and start it up again with the --skip-grant-tables option. Once it's started up, you'll be able to log in as root with no password. You can do everything with the databases, change passwords, all that.
Note, you and everyone else will be able to log in without a password. You'll probably want to block off port 3306 or take the machine off the internet altogether til you're done what you need to do.
Once you've gotten the data or changed passwords or whatever, stop the service again and restart it normally to reenable permissions.
MySQL root and server root are two different accounts. Even if you have server root access it won't necessarily mean its same as MySQL root. However with server root access you can change MySQL root password. Depending upon the administration panel installed on your server there can be many different ways to do that.
First login as root
su root;
You can then set password by
root paswd;
It will ask for password, u can set whichever u wish.
Then logout from their & login as root as Username

MAMP mysql broken root user [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I've read many threads on SO and a few other places and haven't been able to fix my mysql installation in MAMP.
Background. I made a change to my root user the other day in an attempt to get a local service to connect properly. After rebooting my machine phpmyadmin in mamp no longer displayed any of my dbs and showed "No Privileges" to create a database. I tried many things to restore the privileges that I read here and elsewhere to no avail. --skip-grant-tables does not seem to work. Connecting as root in the shell I don't have permission as localhost but I do as 127.0.0.1.
show grants for root#localhost;
GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION
I've installed a fresh installation of MAMP and copied over my DBs. While it works, I've run into instances where DBs are not showing all the tables.
So I have to solve one of two problems. I either have to fix the original install or make it so the all tables show for my dbs in my fresh mamp install.
Lesson learned here is don't be lazy and screw around with your root user locally and just create another login.
UPDATE
When I connect as:
/Applications/MAMP/Library/bin/mysql -uroot -h127.0.0.1 -p
mysql> SHOW GRANTS FOR 'root'#'localhost';
+------------------------------------------------------------------------+
| Grants for root#localhost |
+------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT OPTION |
| GRANT ALL PRIVILEGES ON `db`.* TO 'root'#'localhost' WITH GRANT OPTION |
+------------------------------------------------------------------------+
But when I connect as:
/Applications/MAMP/Library/bin/mysql -uroot -hlocalhost -p
mysql> SHOW GRANTS FOR 'root'#'localhost';
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'mysql'
mysql> SELECT user();
+----------------+
| user() |
+----------------+
| root#localhost |
+----------------+
mysql> SELECT current_user();
+----------------+
| current_user() |
+----------------+
| #localhost |
+----------------+
So when I connect as localhost either by IP or socket I am somehow not logged in as root. I find this very confusing?
After several days of beating my head on this I discovered the solution. It took a while to put the pieces together because the MAMP installation is a bit different then a standard mysql installation. I still don't understand a few of the details but here we go.
Even though I was logging in as root the reality was that I was an anonymous user indicated by the above and ''#'localhost'. So there is obviously a permissions error which has three parts: username, password, and host. So something about my root account changed (I believe it was the password), but how the whole thing responded was a bit wonky, as in instead of telling me my password and username combo was incorrect, I was getting logged in with no permissions. I believe I exacerbated this situation a bit by running some commands like the below.
mysqladmin -u root password 'password'
In the end here is what I did, and I want to make clear this is the instructions for a MAMP installation on OS X, although I'm sure they can be easily adapted for Windoz.
Big thanks to this thread for helping me see the light on how to resolve this.
Open the Activity Monitor.
Shut down MAMP
Ensure that mysql is shut off in Activity Monitor. Now, you might see a _mysqld process running which might be the default OSX mysql running.
Run the following command, replacing the port number with the one you use. This will start mysql minus the user permissions.
/Applications/MAMP/Library/libexec/mysqld --skip-grant-tables --port=8889 --socket=/Applications/MAMP/tmp/mysql/mysql.sock
In your console login to mysql with no creds.
mysql
Run the below commands.
FLUSH PRIVILEGES;
GRANT ALL ON *.* TO 'username'#'localhost' IDENTIFIED BY 'password';
Shut down mysqld and restart it without the skip-grant-tables option
Login to mysql to confirm that things work.
You will need to fix your phpmyadmin as well. I want to preface this with for some reason I do not understand these changes to not propagate quickly, and suddenly just start working.
Go into /Application/MAMP/bin/phpMyAdmin/config.inc.php and enter the correct credentials for your newly created login. Make sure they are exact including host.
Lastly after phpmyadmin is working go into the mysql.user table and see where things could have gone wrong. It's important to understand what got messed up.
There are a few things about what happened in the above that I would love some clarification on, like why MAMPs phpmyadmin credential changes do not work immediately.
Hope all this helps!

MySQL munging username on linux [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
This question does not appear to be about programming within the scope defined in the help center.
Improve this question
I'm writing a script to perform some database maintenance, and MySQL is not accepting the username I'm trying to pass it.
I have a MySQL user and database named 'abc_wpsites', as well as a user and database named 'abc_wpsitesdev'. Here, I'm trying to access abc_wpsitesdev, but MySQL continually attempts to access with the account 'abc_wpsites' instead.
abc.com [~]# mysql -uabc_wpsitesdev --password='(redacted)' -h localhost abc_wpsitesdev
ERROR 1045 (28000): Access denied for user 'abc_wpsites'#'localhost' (using password: YES)
abc.com [~]# mysql --user='abc_wpsitesdev' --password='(redacted)' -h localhost abc_wpsitesdev
ERROR 1045 (28000): Access denied for user 'abc_wpsites'#'localhost' (using password: YES)
abc.com [~]# mysql --user='abc_wpsitesfff' --password='(redacted)' -h localhost abc_wpsitesdev
ERROR 1045 (28000): Access denied for user 'abc_wpsites'#'localhost' (using password: YES)
Notice how each attempt at experimenting with the username still results in an attempt to access MySQL via the 'abc_wpsites' account. Any thoughts on what's going on here?
Also, I should mention that I can connect via other methods with the appropriate credentials (e.g. via MySQL), so this seems to be some sort of problem with my understanding/the operation of MySQL's CLI interface.
I wouldn't suggest passing your login information that way. This means your password is
Visible in the processlist (some distro's will filter that but)
It's either stored in a crontab or your bash .history file
Instead create at script.cnf file that is NOT world readable.
The contents will look like
[client]
user=abc_wspitesdev
password=your_password
Change your command line call to
mysql --defaults-file=/path/to/script.cnf -h localhost abc_wpsitesdev
mysql
Edit
Your other comment said you could connect as other users. If you have root access to this db run
select user, host, passowrd from mysql.users;
Compare the one that's not working with others that are.
The passwords that are stored will be hashes of the actual values. Are they all the same length? If one is significantly longer or shorter it could be the password was stored with an old password hashing method used in versions 4.x and earlier.
What is the host for the account you are trying to connect through? Is it 'localhost' or an IP address? If it is your IP address this likely might be the problem. Since your command line call is connecting to localhost this will tell it to connect through a unix socket (/var/lib/mysql/mysql.sock perhaps). MySQL differentiates these connections from ones coming through the TCP stack.
You could alternatively specify your full (non 127.0.0.1) IP address on the commandline if this is the case like
mysql -u blah -pblah -h 1.2.3.4
"Where" is user "abc_wpsitesdev" allowed to connect from as opposed to where the "abc_wpsites" user is allowed to connect from -- any difference?
If you did "grant all privileges on abcwpsitedev to 'abc_wpsitesdev'#'%' identified by 'thedevpassword';" that won't work for accessing from localhost as explained in the last pargraph in the post from the manual below:
From the MySQL manual:
After connecting to the server as root, you can add new accounts. The following statements use GRANT to set up four new accounts:
mysql> GRANT ALL PRIVILEGES ON . TO 'monty'#'localhost'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON . TO 'monty'#'%'
-> IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT RELOAD,PROCESS ON . TO 'admin'#'localhost';
mysql> GRANT USAGE ON . TO 'dummy'#'localhost';
The accounts created by these statements have the following properties:
Two of the accounts have a user name of monty and a password of some_pass. Both accounts are superuser accounts with full privileges to do anything. The 'monty'#'localhost' account can be used only when connecting from the local host. The 'monty'#'%' account uses the '%' wildcard for the host part, so it can be used to connect from any host.
It is necessary to have both accounts for monty to be able to connect from anywhere as monty. Without the localhost account, the anonymous-user account for localhost that is created by mysql_install_db would take precedence when monty connects from the local host. As a result, monty would be treated as an anonymous user. The reason for this is that the anonymous-user account has a more specific Host column value than the 'monty'#'%' account and thus comes earlier in the user table sort order. (user table sorting is discussed in Section 5.5.4, “Access Control, Stage 1: Connection Verification”.)
the problem with your line
mysql -uabc_wpsitesdev --password='(redacted)' -h localhost abc_wpsitesdev
is, that you need a space after -u
(and no space after -p)
this is the form I use:
mysql -u abc_wpsitesdev -p(redacted) -h localhost abc_wpsitesdev