How to Set Default Access for MySQL - mysql

I'm sure this is an easy question, but I can't seem to find the answer anywhere.
When I log into the command line mysql program, I want to have root access by just typing mysql. However, I need to type mysql -uroot -p, and then enter my password. How can I change this?
Thanks,
Adam

Here is a tutorial on getting MySql to log you in automatically.
Just follow the steps and you should be able to login to MySql by simply typing mysql, as shown in the following image:

When you first install mysql, the furst thing you should do is give root#localhost a password. To set the password to mys3cr3t, run the following:
UPDATE mysql.user SET password=password('mys3cr3t')
WHERE host='localhost' and user='root';
FLUSH PRIVILEGES;
EXIT
Now, you have to login with mysql -uroot -p
Next, you need to cleanup all security hazards. There is a script called mysql_secure_installation. Run it ASAP. Here is what is does: https://dba.stackexchange.com/a/13350/877
If you do not, there is a possibility of a Disk Level database attack : https://dba.stackexchange.com/a/13363/877
To test to see whether you have proper user authentication, run this:
SELECT USER(),CURRENT_USER();
What does this query tell you ???
USER() reports how you attempted to authenticate in MySQL
CURRENT_USER() reports how you were allowed to authenticate in MySQL
If CURRENT_USER() reports any anonymous users, go run mysql_secure_installation now !!!

Related

mysql cannot grant privilege to user, getting error: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

I am in the process of moving a new application to the Production environment which includes a MySQL DB.
While attempting to grant the required privileges using the command:
GRANT ALTER,CREATE ON `MyDB`.`*` to `ThisUser`#`*` ;
I'm getting the error: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements.
and this, while the passwords (of the root user as well as of the ThisUser) fully satisfy the current policy:
The length of the passwords are above 8 chars,
They include both upper and lower case, as well as digits and special chars (like "!", "#", "$", etc.).
I tried setting the validate_password_policy to LOW but it didn't help either.
Can anyone explain what the issue is and how to resolve it?
Thanks.
To solve this problem change validate_password_policy value:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements:
$ mysql -u root -p
mysql> SET GLOBAL validate_password_policy=LOW;
And grant privileges to your user:
mysql> grant all privileges on DB_NAME.* to 'USER_NAME'#'localhost' identified by 'USER_PASS';
mysql> FLUSH PRIVILEGES;
mysql> exit
$ sudo service mysql reload
$ brew services restart mysql
For me it work when I have added IDENTIFIED BY clause in the GRANT query. You need to use IDENTIFY BY clause when you don't have user already added to mysql.
GRANT ALTER,CREATE ON MyDB.* to 'UserName'#'%' IDENTIFIED BY 'UserPassword';
Eventually, the issue was related to some phantom definition of a user as described in here.
This error some time occurs when you've changed some fields like user host or password but forgotten to flush privileges.
So try:
mysql>flush privileges;
The problem is as a result of the policy difference between your password and the server password policy, what you need to do is to reset the password policy of the server to match that no of your server. Type in the following commands to access the plug-in for the password policies
Sudo MySQL
msql> SHOW VARIABLES LIKE 'validate_password%';
This commands should take you to the table with the password policies of the MySQL server. Now you need to write down your password on a piece of paper and reset the server password policies to match that of your password. To do the type in the following commands.
MySQL> SET GLOBAL validate_password_length = 5; ( this should be according to the length of your password)
MySQL> SET GLOBAL validate_number_count = 0;
MySQL> SET GLOBAL validate_password.policy =LOW;
MySQL> SET GLOBAL validate_password_special_char_count = 0;
Note that there are other policies you could change to suit your current password needs.
Incase you are using a password generator it's best to delete the password plug in all together, use the following commands in case you want to delete all password policies.
MySQL> uninstall plugin validate_password;
I was able to solve this ONLY by first adding the phpmyadmin database and user, then running the installation procedure and entering the same password for the phpmyadmin user there as well. Unfortunately, none of the apache configuration files were set up. I'm switchting to ubuntu from amazon linux 2.

ownCloud Setup: SQLSTATE[HY000][1045] Access denied for user 'owncloud'#localhost' (using password:YES)

I wanted to setup my owncloud installation on my raspberry pi 2. So, I created an mysql database and user.
CREATE DATABASE owncloud;
CREATE USER 'owncloud'#'localhost' IDENTIFIED BY 'Password';
GRANT ALL PRIVILEGES ON owncloud. * TO 'owncloud'#'localhost';
FLUSH PRIVILEGES;
After I type all nessesairy parameters into the webinterface of the owncloud-setup, I recevied:
Error while trying to create admin user: Failed to connect the database: An exeption occured in driver: SQLSTATE[HY000][1045] Access denied for user 'owncloud'#'localhost' (using password:YES)
Sadly, my resent sreach on similar topics didn't result in any functional hint on this problem. So, I would be happy about further suggestions.
Look at this: https://doc.owncloud.org/server/9.0/admin_manual/installation/installation_wizard.html#database-choice
In Terminal: mysql_upgrade --force -u root -p
Use administrative MySQL »root«-user and password with the Installation Wizard
Check that the Database not exist which you create with the Installation Wizard
If nothing helps, start with sqlite, then migrate to mysql like this: https://doc.owncloud.org/server/9.0/admin_manual/configuration_database/db_conversion.html
Just replace localhost for 127.0.0.1 in Owncloud's setup form for MySQL as mentioned in comments above by Askaga
For some reason, explicitly re-access the database from the terminal solves the problem for me. Just give mysql an empty line with
mysql -u root -e ";"
This should be an individual command after you created database and database user.
Sure, you should always check whether
There are users with an empty username. Remove them.
Remove "test" database.
Grant appropriate permission to your database user.
Last but not least FLUSH PRIVILEGES;.
Search other posts for instructions. I'm just providing a possible solution if you come across a situation where none of the above works.
Here's a good example to properly setup mysql after installation. FYI.
Mask the DB password in the installation screen (the password should not be visible, only dots) and retry.
Ubuntu 18.04.1, Owncloud 10.
Check the contents of config.php in my case located at /var/www/owncloud/config/.
Specialy items dbuser and dbpasswrd.
Read config.sample.php in the same directory for info.

Phpmyadmin - Mysql no privileges

I installed wamp 2.1 on windows 7. However when i open phpMyAdmin, I get the error, Mysql 'No Provileges'. I uninstalled wamp and reinstalled it a few times, but it doesn't help. Does anyone know how to solve this issue?
Also, when i tried creating a database from mysql console, i am getting the following error:
ERROR 1044 <42000>: Access denied for user ''#'localhost' to database 'a_db_name'
Thank God and to all helped.
Its simple.
Must! click logout icon in phpadmin page
In login page, type:
username:root password: (blank)
surprise. now you can happily create your database.
Are you logging into MySQL as root? You have to explicitly grant privileges to your "regular" MySQL user account while logged in as MySQL root.
First set up a root account for your MySQL database.
In the terminal type:
mysqladmin -u root password 'password'
To log into MySQL, use this:
mysql -u root -p
Edit:
To set the privileges manually start the server with the skip-grant-tables option, open mysql client and manually update the mysql.user table and/or the mysql.db tables. This can be a tedious task though so if what you need is an account with all privs I would do the following.
Start the server with the skip-grant-tables option
Start mysql client (without a username/password)
Issue the command
flush privileges;
which forces the grant tables to be loaded.
Create a new account with the GRANT command something like this (but replacing username and password with whatever you want to use.
GRANT ALL on *.* to 'username'#'localhost' identified by 'password';
Restart the server in normal mode (without skip-grant-tables) and log in with your newly created account.
Refer this MySQL docs.
Take a look at my topic regarding this issue, which takes some of the above.
MAMP mysql broken root user
You need to shutdown your mysql install and restart it from the command line properly like is indicated above. In my topic I have full clear instructions on how to do so. My instructions are for MAMP but you should be able to adapt it for your install.
Simple solution. Just find the icon right to "home" in PhpMyAdmin and click to logout. Then login using username "root" and password ""(blank). This will work accordingly.
username ought to be root and keep the password null(keep the password field blank)
right click on the wamp icon and goto mysql console.
Login with password if you have set any.By default the password is blank and username is 'root'
Once you are in mysql prompt execute
FLUSH PRIVILEGES;
now quit the command prompt and you are good to go.
in step 1 .inter your databasevery important.
in step 2 .select your database via all tables .
in step 3. backup type=replace & export.
in step 4 import database in my sql.
attention please:in import your database...
all table must view & selected in step 4.

unable to change to different user in mysql

I am also using windows 7.I installed mysql server 5.1.
Created a user as 'user#localhost' using mysql console. But unable to login to that user.
I tried to run using command prompt.
When I created a user with name "user". when i tried mysql -u user -p
It says Access Denied to 'user#localhost' ..
Even trying with mysql console is not helping out here. .
A few things to try:
Make sure your user has the correct privileges set (global or schema level privileges)
try running FLUSH PRIVILEGES
To help us troubleshoot, what does this command return? SHOW GRANTS FOR 'user'#'localhost';

Access denied for user 'root'#'localhost' (using password: YES) (Mysql::Error)

I tried to deploy web application on my server and I am getting this mysql database exception
Access denied for user 'root'#'localhost' (using password: YES) (Mysql::Error)
I tried to access the database from the command prompt using mysql -u root -p I am able to do all the database operations.
what is the error
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:771)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3649)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1176)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2558)
at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(DriverManager.java:620)
at java.sql.DriverManager.getConnection(DriverManager.java:200)
at com.mpigeon.DbConnection.DbConn(DbConnection.java:26)
at com.mpigeon.CheckLoginHome.doGet(CheckLoginHome.java:39)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
You need to grant access to root from localhost. Check this ubuntu help
try using root like..
mysql -uroot
then you can check different user and host after you logged in by using
select user,host,password from mysql.user;
check you are putting blank space in password.
From my answer here, thought this might be useful:
I tried many steps to get this issue corrected. There are so many sources for possible solutions to this issue that is is hard to filter out the sense from the nonsense. I finally found a good solution here:
Step 1: Identify the Database Version
$ mysql --version
You'll see some output like this with MySQL:
$ mysql Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using EditLine wrapper
Or output like this for MariaDB:
mysql Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1
Make note of which database and which version you're running, as you'll use them later. Next, you need to stop the database so you can access it manually.
Step 2: Stopping the Database Server
To change the root password, you have to shut down the database server beforehand.
You can do that for MySQL with:
$ sudo systemctl stop mysql
And for MariaDB with:
$ sudo systemctl stop mariadb
Step 3: Restarting the Database Server Without Permission Checking
If you run MySQL and MariaDB without loading information about user privileges, it will allow you to access the database command line with root privileges without providing a password. This will allow you to gain access to the database without knowing it.
To do this, you need to stop the database from loading the grant tables, which store user privilege information. Because this is a bit of a security risk, you should also skip networking as well to prevent other clients from connecting.
Start the database without loading the grant tables or enabling networking:
$ sudo mysqld_safe --skip-grant-tables --skip-networking &
The ampersand at the end of this command will make this process run in the background so you can continue to use your terminal.
Now you can connect to the database as the root user, which should not ask for a password.
$ mysql -u root
You'll immediately see a database shell prompt instead.
MySQL Prompt
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
MariaDB Prompt
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
Now that you have root access, you can change the root password.
Step 4: Changing the Root Password
mysql> FLUSH PRIVILEGES;
Now we can actually change the root password.
For MySQL 5.7.6 and newer as well as MariaDB 10.1.20 and newer, use the following command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'new_password';
For MySQL 5.7.5 and older as well as MariaDB 10.1.20 and older, use:
mysql> SET PASSWORD FOR 'root'#'localhost' = PASSWORD('new_password');
Make sure to replace new_password with your new password of choice.
Note: If the ALTER USER command doesn't work, it's usually indicative of a bigger problem. However, you can try UPDATE ... SET to reset the root password instead.
[IMPORTANT] This is the specific line that fixed my particular issue:
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHERE User = 'root' AND Host = 'localhost';
Remember to reload the grant tables after this.
In either case, you should see confirmation that the command has been successfully executed.
Query OK, 0 rows affected (0.00 sec)
The password has been changed, so you can now stop the manual instance of the database server and restart it as it was before.
Step 5: Restart the Database Server Normally
The tutorial goes into some further steps to restart the database, but the only piece I used was this:
For MySQL, use:
$ sudo systemctl start mysql
For MariaDB, use:
$ sudo systemctl start mariadb
Now you can confirm that the new password has been applied correctly by running:
$ mysql -u root -p
The command should now prompt for the newly assigned password. Enter it, and you should gain access to the database prompt as expected.
Conclusion
You now have administrative access to the MySQL or MariaDB server restored. Make sure the new root password you choose is strong and secure and keep it in safe place.
I faced the same error after upgrading MySQL server from 5.1.73 to 5.5.45
There is another way to fix that error.
In my case I was able to connect to MySQL using root password but MySQL actively refused to GRANT PRIVILEGES to any user;
Connect to MySQL as root
mysql -u root -p
then enter your MySQL root password;
Select database;
use mysql;
Most probably there is only one record for root in mysql.user table allowing to connect only from localhost (that was in my case) but by the default there should be two records for root, one for localhost and another one for 127.0.0.1;
Create additional record for root user with Host='127.0.0.1' if it's not there;
SET #s = CONCAT('INSERT INTO mysql.user SELECT ',
REPLACE((SELECT GROUP_CONCAT(COLUMN_NAME)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'user' AND TABLE_SCHEMA = 'mysql')
,"Host","'127.0.0.1'"),
' FROM mysql.user WHERE User="root"');
PREPARE stmt FROM #s;
EXECUTE stmt;
Additionally to that you can execute mysql_upgrade -u -p
to see if everything is ok.
This error happens if you did not set the password on install, in this case the mysql using unix-socket plugin.
But if delete the plugin link from settings (table mysql.user) will other problem. This does not fix the problem and creates another problem. To fix the deleted link and set password ("PWD") do:
1) Run with --skip-grant-tables as said above.
If it doesnt works then add the string skip-grant-tables in section [mysqld] of /etc/mysql/mysql.conf.d/mysqld.cnf. Then do sudo service mysql restart.
2) Run mysql -u root -p, then (change "PWD"):
update mysql.user
set authentication_string=PASSWORD("PWD"), plugin="mysql_native_password"
where User='root' and Host='localhost';
flush privileges;
quit
then sudo service mysql restart. Check: mysql -u root -p.
Before restart remove that string from file mysqld.cnf, if you set it there.
#bl79 is the author of this answer, i've just reposted it, because it does help!
My application is using Mura CMS and I faced this issue. However the solution was the password mismatch between my mysql local server and the password in the config files. As soon as I synched them it worked.
I solved this problem by deleting the empty users creating by MySQL. I only have root user and my own user. I deleted the rest.
Update the empty password in the table mysql.user of mysql
use mysql;
select host,user,password from mysql.user;
update mysql.user set password = PASSWORD('123456') where password = '';
flush privileges;
Update user table in mysql DB. And set some password where it is blank, i was using root user so i set password for root user.
update mysql.user set password = PASSWORD('123456') where password = '';
flush privileges;
And then again tried from ATG CIM by providing password and it worked fine.
http://i.stack.imgur.com/3Lchp.png
I got this problem today while installing SugarCRM (a free CRM).
The system was not able to connect to the database using the root user. I could definitively log in as root from the console... so what was the problem?
I found out that in my situation, I was getting exactly the same error, but that was because the password was sent to mysql directly from the $_POST data, in other words, the < character from my password was sent to mysql as < which means the password was wrong.
Everything else did not help a bit. The list of users in mysql were correct, including the anonymous user (which appears after the root entries.)
I googled a lot but did not find a definite answer to my problem. I used KeyPass to generate a strong password and could use it successfully on mysql workbench to connect but not from the command line. So I changed the psw to an easy one and it worked on the command line. I have managed to create a strong password that was able to connect from the terminal. So my advise is, try with an easy password first before trying all kind of things.
I was running UTs and I started receiving error messages. I am not sure what was the problem. But when I changed my encoding style in INTELLIJ to UTF8 it started working again.
access denied for user 'root'#'localhost' (using password yes)
hibernate
this is my URL
db.url=jdbc:mysql://localhost:3306/somedb?useUnicode=true&connectionCollation=utf8_general_ci&characterSetResults=utf8&characterEncoding=utf8
Add a user option in msyql.
GRANT PROXY ON ''#'' TO 'root'#'localhost' WITH GRANT OPTION;
and this link will be useful.