After changing mysql password, I did executed skip-grant-tables, so when I try to login to mysql without password I cannot login. It gives access denied message. Why is that
Following are the steps I did. First I installed mysql and changed the password
1) sudo yum install mysql-community-server
2) sudo service mysqld start
3) sudo grep 'temporary password' /var/log/mysqld.log
4) mysql -uroot -p
5) ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass4!';
Then tried to login with skip grant tables
6) sudo service mysqld stop
7) mysqld_safe --skip-grant-tables &
Now I get Access denied message
I recently upgrade my Ubuntu 16.04 to 18.04 and this has worked for me:
First, connect in sudo mysql
sudo mysql -u root
Check your accounts present in your db
SELECT User,Host FROM mysql.user;
+------------------+-----------+
| User | Host |
+------------------+-----------+
| admin | localhost |
| debian-sys-maint | localhost |
| magento_user | localhost |
| mysql.sys | localhost |
| root | localhost |
Delete current root#localhost account
mysql> DROP USER 'root'#'localhost';
Query OK, 0 rows affected (0,00 sec)
Recreate your user
mysql> CREATE USER 'root'#'%' IDENTIFIED BY '';
Query OK, 0 rows affected (0,00 sec)
Give permissions to your user (don't forget to flush privileges)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'#'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0,00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0,01 sec)
Exit MySQL and try to reconnect without sudo.
This will make you login.
Related
Hi if I use mysql itself I can see my tables and databases and I checked the port on the MySQL variables and it was the same as 3306.
I am not sure what's wrong. I also granted privileges to localhost for the user.
Here is a screenshot of what it shows me:
I think I just updated my PhpStorm and now it is not working any more.
mysql> SELECT
-> user
-> FROM
-> mysql.user;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 49
Current database: *** NONE ***
+---------------+
| user |
+---------------+
| imdi_mg2 |
| mysql.session |
| mysql.sys |
| root |
+---------------+
4 rows in set (0.11 sec)
I am not sure why mysql goes away and comes back in the middle
not sure how but grant should be on % not on localhost this was really annoying:
create user 'user'#'%' identified by 'pass'
GRANT ALL PRIVILEGES ON imdi_mg2.* TO 'user'#'%' WITH GRANT OPTION;
there will be people having this issue hopefully helps someone!
I'm installing MySQL 5.7 on a new Ubuntu 16.04 server. Since my installation uses Ansible, no root password is defined at installation time, and I set it up later with the mysql_user role in ansible, but the root password stays empty.
I therefore tried to run the command directly on MySQL, without Ansible, but I get the same behaviour : no error on the alter user command but password is not set.
My server configuration :
OS :
Distributor ID: Ubuntu
Description: Ubuntu 16.04.1 LTS
Release: 16.04
Codename: xenial
Database : MySQL 5.7.12-0ubuntu1.1
Step to reproduce :
Install mysql-server-5.7 package without providing a root password.
Connect to mysql from the system root account
And then run the mysql commands :
mysql> select authentication_string from user where host='localhost' and user='root';
+-----------------------+
| authentication_string |
+-----------------------+
| |
+-----------------------+
1 row in set (0,00 sec)
mysql> alter user root#localhost identified by 'mypassword';
Query OK, 0 rows affected (0,00 sec)
mysql> select authentication_string from user where host='localhost' and user='root';
+-----------------------+
| authentication_string |
+-----------------------+
| |
+-----------------------+
1 row in set (0,00 sec)
However, running the same command with a hashed value works :
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH 'mysql_native_password' AS '*D7B8FEAED940F8F2A0055864C0A59782B4BCED02';
mysql> select authentication_string from user where host='localhost' and user='root';
+-------------------------------------------+
| authentication_string |
+-------------------------------------------+
| *D7B8FEAED940F8F2A0055864C0A59782B4BCED02 |
+-------------------------------------------+
1 row in set (0,00 sec)
And then, I can change the password with the original request :
mysql> alter user root#localhost identified by 'mypassword';
Query OK, 0 rows affected (0,00 sec)
mysql> select authentication_string from user where host='localhost' and user='root';
+-------------------------------------------+
| authentication_string |
+-------------------------------------------+
| *FABE5482D5AADF36D028AC443D117BE1180B9725 |
+-------------------------------------------+
1 row in set (0,00 sec)
Why does the "unhashed" version not work the first time ? Am I missing something or is this a bug in this version of MySQL ?
I am trying to setup conection to my local db (mysql) via PyCharm. I am working on macbook pro.
I am using this video.
But, when i trying to test connections, i am getting this error:
Connection to Data Source failed
java.sql.SQLException: Access denied for user 'root'#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:927)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1709)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1252)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2486)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2519)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2304)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
in RemoteDriverImpl.connect(RemoteDriverImpl.java:27)
at com.sun.proxy.$Proxy87.connect(Unknown Source)
in LocalDataSource.getConnection(LocalDataSource.java:158)
But i have no problem connect to mysql via terminal
mysql -u root --password=123
UPD
mysql -u root -p -h 127.0.0.1 -D lp
Access denied for user 'root'#'localhost' (using password: YES)
mysql -u root -p -h 127.0.0.1 lp
Access denied for user 'root'#'localhost' (using password: YES)
mysql -u root -p -h localhost lp
connected
UPD
mysql> select host, user, password != '' from mysql.user;
+-----------+------+----------------+
| host | user | password != '' |
+-----------+------+----------------+
| localhost | root | 1 |
| 127.0.0.1 | root | 1 |
| ::1 | root | 1 |
+-----------+------+----------------+
3 rows in set (0.00 sec)
mysql> select user(), current_user();
+----------------+----------------+
| user() | current_user() |
+----------------+----------------+
| root#localhost | root#localhost |
+----------------+----------------+
1 row in set (0.00 sec)
Here is screenshot of my settings:
Any ideas?
Some or both of these should fix your problem:
Check the results of select host, user, password, Select_priv from mysql.user;.
If the password field is not the same for all rows then do:
SET PASSWORD FOR 'root'#'127.0.0.1' = PASSWORD('123');
SET PASSWORD FOR 'root'#'::1' = PASSWORD('123');
If Select_priv is not 'Y' for all rows then do:
GRANT ALL ON *.* TO 'root'#'127.0.0.1' WITH GRANT OPTION;
GRANT ALL ON *.* TO 'root'#'::1' WITH GRANT OPTION;
EDIT
As neither of these was true, the only option left was that there was more than one instance of MySQL running on the machine, and one was receiving the connections made via socket and the other one was receiving the connections made via TCP.
maybe you dont have permission to the schema ?
try this:
mysql -u root -p -h 127.0.0.1 -D lp
Update
You have access to the database but you dont have access to the schema.
GRANT ALL ON `lp`.* TO 'root'#'localhost';
I can't seem to login to my tutorial database development environment:
Ayman$ mysql -u blog -p blog_development
Enter password:
ERROR 1049 (42000): Unknown database 'blog_development'
I can login to the database fine without the blog_development portion:
Ayman$ mysql -u blog -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1858
Not sure what gives as I granted all access:
mysql> GRANT ALL PRIVILEGES ON blog_development.*
-> TO 'blog'#'localhost'
-> IDENTIFIED BY 'newpassword';
Query OK, 0 rows affected (0.01 sec)
mysql> SHOW GRANTS FOR 'blog'#'localhost'
-> ;
+----------------------------------------------------------------------------------------- --------------------+
| Grants for blog#localhost |
+----------------------------------------------------------------------------------------- --------------------+
| GRANT USAGE ON *.* TO 'blog'#'localhost' IDENTIFIED BY PASSWORD '*FE4F2D624C07AAEBB979DA5C980D0250C37D8F63' |
| GRANT ALL PRIVILEGES ON `blog`.* TO 'blog'#'localhost' |
| GRANT ALL PRIVILEGES ON `blog_development`.* TO 'blog'#'localhost' |
+----------------------------------------------------------------------------------------- --------------------+
3 rows in set (0.00 sec)
Anybody have a clue what to try? Thanks! Also, side note- is it weird I have multiple root users?:
mysql> select User from mysql.user;
+------+
| User |
+------+
| root |
| root |
| |
| root |
| |
| blog |
| root |
+------+
7 rows in set (0.00 sec)
Edit: for those asking- I created the database blog with the CREATE DATABASE command in MySql. Here are my active databases:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| blog |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
blog_development doesn't exist
You can see this in sql by the 0 rows affected message
create it in mysql with
mysql> create database blog_development
However as you are using rails you should get used to using
$ rake db:create
to do the same task. It will use your database.yml file settings, which should include something like:
development:
adapter: mysql2
database: blog_development
pool: 5
Also become familiar with:
$ rake db:migrate # Run the database migration
$ rake db:seed # Run thew seeds file create statements
$ rake db:drop # Drop the database
Very simple solution.
Just rename your database and configure your new database name in your project.
The problem is the when you import your database, you got any errors and then the database will be corrupted. The log files will have the corrupted database name.
You can rename your database easily using phpmyadmin for mysql.
phpmyadmin -> operations -> Rename database to
Its a common error which happens when we try to access a database which doesn't exist. So create the database using
CREATE DATABASE blog_development;
The error commonly occours when we have dropped the database using
DROP DATABASE blog_development;
and then try to access the database.
I setup a database & user along with grant permissions how I normally do and I'm still getting access denied and I'm not sure why:
[root#server23 redditonrails]# mysql -u redditonrails -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 431954
Server version: 5.0.45 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> use redditonrails_development;
Database changed
mysql> create table test;
ERROR 1142 (42000): CREATE command denied to user 'redditonrails'#'localhost' for table 'test'
mysql> show grants;
+------------------------------------------------------------------------------------------------+
| Grants for redditonrails#localhost |
+------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'redditonrails'#'localhost' IDENTIFIED BY PASSWORD '*******' |
| GRANT ALL PRIVILEGES ON `redditonrails_test`.`localhost` TO 'redditonrails'#'localhost' |
| GRANT ALL PRIVILEGES ON `redditonrails_development`.`localhost` TO 'redditonrails'#'localhost' |
| GRANT ALL PRIVILEGES ON `redditonrails`.`localhost` TO 'redditonrails'#'localhost' |
+------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)
mysql> SELECT USER(),CURRENT_USER();
+-------------------------+-------------------------+
| USER() | CURRENT_USER() |
+-------------------------+-------------------------+
| redditonrails#localhost | redditonrails#localhost |
+-------------------------+-------------------------+
1 row in set (0.00 sec)
I don't believe your syntax is right. You're specifying:
GRANT ALL PRIVILEGES ON
redditonrails_development.localhost
The expected syntax for db-level GRANT is: ON $db.$table. Based on this, you're only granting on the table named "localhost". Change to:
GRANT ALL PRIVILEGES ON
redditonrails_development.*
It would seem that your user redditonrails has all privilages on
redditonrails_development.localhost
which would mean redditonrails_development database and localhost table. what you want is to have there
redditonrails_development.*
witch would mean you have all privilages on all tables (even the new ones you're trying to create)
or at least that's how I see it.