MySQL: ERROR 2027 (HY000): Malformed packet - mysql

I am not able to connect a MySQL server remotely.
The connection seems to be ok because with telnet [ip] [port] I get response:
4.1.3b-beta-nt-max▒ <0v '[uZ,? B {efSLa $, Q4N
When executed by command line or by MySQL Workbench 6.3
mysql -u [user] -p -h [host]
I get the same error:
ERROR 2027 (HY000): Malformed packet

It is a mysql client bug, I've searched about it and it is a old auth switch request. Your client it is out of date, using a old protocol communication, now, if it is a Workbench problem too your just the Client, you need to update or downgrade the MySQL Client first and try to run it alone.
Here, it is the same question with a more complete answer:
https://dba.stackexchange.com/questions/135343/server-responds-with-empty-packet-during-session-negotiation-resulting-in-client
And, for the new Auth protocol, on connection phase:
https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_connection_phase.html

You must upgrade the "old_password" hashed password:
SET PASSWORD FOR 'existinguser'#'localhost' = PASSWORD('existingpass');
So you can login in an "old" MySQL server, using a recent Workbench version

If you need to connect to pre-4.1 MySQL servers from later MySQL versions (5.7+), you will need to use "--skip-secure-auth" option from the client. And the client version cannot be newer than v5.7.4 because this option had been removed in 5.7.5. You can download version 5.7.4_m14 from mysql's archive website. For example,
$ mysql -uuser -p -hserver --skip-secure-auth

I had the same error trying to connect to a MariaDB server with the MySQL client mysql-client. I solved it by installing mariadb-client (that overwrites the mysql binary, so use the same command to connect).

I did face this issue for normal select query. It was weird that when I was using small-case 's' in the query statement, it was giving me the same error. The I figured out that this happens as internally it is trying to retrieve the data from mysql cache.
It was not because of the case of 's' in the select query.
//Returned Error
select * from foo;
//This worked fine
Select * from foo;
//This also worked fine
select SQL_NO_CACHE * from foo;
From this I was able to conclude that it was the issue as it was using Cached data.

I've faced the same issue with latest MySQL Client (>5.7) while trying to connect lower versions of MySQL like 5.1.xx.
To avoid this issue (ERROR 2027 (HY000): Malformed packet), create a user with latest password authentication.
ex:
Login to MySQL 5.1.xx server and execute..
mysql> create user 'testuser'#'xx.xx.xxx.%' identified by 'testuser_Secret1';
Check if you have old_passwords enabled, then disable it for that session.
mysql> show session variables like 'old_passwords';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| old_passwords | ON |
+-----------------+-------+
mysql> set session old_passwords = 0;
mysql> GRANT select on test.* TO 'testuser'#'xx.xx.xxx.%' identified by 'testuser_Secret1';
Verify password that should begin with "*SOMETHING1123SHOWNBELOW3034".
mysql> select user,host,password from mysql.user where user = 'testuser';
+-----------+---------------+-------------------------------------------+
| user | host | password |
+-----------+---------------+-------------------------------------------+
| testuser | xx.xx.xxx.% | *053CB27FDD2AE63F03D4A0B919E471E0E88DA262 |
+-----------+---------------+-------------------------------------------+
Now try logging from MySQL 5.7.xx Client and try to establish a connection to MySQL 5.1.xx server.
[testuser#localhost]# mysql -V
mysql Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using EditLine wrapper
[testuser#localhost]# mysql -hxx.xx.xxx.xxx -u testuser -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1528853
Server version: 5.1.73-log Source distribution
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

For the people that has this error when the execute the query (not when connecting to DB), the problem is the cache configuration in database.
You can find the bug description here:
https://bugs.mysql.com/bug.php?id=86318
The solution:
disable the cache configuration:
query_cache_limit = 0
query_cache_size = 0
query_cache_type = 0
In the long term there are no negative repercussions, since the latest versions of MySQL no longer support this feature. With little data the cache works correctly, but in large quantities it generates a bottleneck.
More info about the cache removed from mysql 8.0:
https://mysqlserverteam.com/mysql-8-0-retiring-support-for-the-query-cache/

i solved this issue. i was facing this issue in my PHP 7.2. First i created a new user and upgrade it in my script. Then i upgrade PHP 7.2 to 7.3. And it worked. :)

Related

Cannot connect to mysql : Unable to load authentication plugin 'caching_sha2_password

I'm quite stuck, I installed the new version of mysql (8.0.12) with homebrew.
Then I dumped my databases from mysql (I was using the MAMP stack and did that to get rid of it...).
However when importing the dump the databases were created, everything seemed to be in order. then I tried to connect my IDE (phpstorm) to it, and I got an error saying "Unable to load authentication plugin 'caching_sha2_password'." (I think this was introduced with this new version...).
I created a my.cnf file and put:
[mysqld]
default_authentication_plugin=mysql_native_password
Still did have the same issue...
So I also tried creating a user with a password to be under this new algorithm (caching_sha2_password). Did not work as well, I logged in as sudo to mysql and it gave me the below:
MacBookAir$ sudo mysql
Password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.12 Homebrew
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
ERROR 1726 (HY000): Storage engine 'MyISAM' does not support system tables. [mysql.db]
Last but not least, I changed the configuration in my.cnf file using this below:
default_authentication_plugin=mysql_native_password
Any idea guys?
Cheers
MyISAM is based on the older (and no longer available) ISAM storage
engine
... See https://dev.mysql.com/doc/refman/8.0/en/myisam-storage-engine.html
There are several checks you can run ON your MySQL 5.* installation to see if you can upgrade ( these are just examples):
mysqlcheck -u root -p --all-databases --check-upgrade
mysql_upgrade --user=root -p --host=localhost —force
If you have the mysql shell:
mysqlsh -- util checkForServerUpgrade root#localhost:3306 --target-version=8.0.16 --config-path=/etc/my.cnf
Those commands may fix, upgrade or repair problems with your database.
On your 5.* installation, I recommend you convert your MyISAM tables to InnoDB and use the new default character set utf8mb4 which has wider support for more character sets.
ALTER TABLE table_name ENGINE=InnoDB;
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4;
Use mysqldump to save your schema.
Install MySQL 8 separately. (don't upgrade your 5.* installation to 8.)
Import your mysqldump file into your mysql 8 installation under the new database you created.
Create user accounts:
The user accounts must be created using the old authentication plugin - it's the only way PHP can connect. Also, you must be using PHP 7.2.4 or higher.
CREATE USER 'user_name'#'localhost' IDENTIFIED WITH mysql_native_password BY 'my_password';
Grant your user access to the appropriate schema. Something like:
GRANT ALL PRIVILEGES ON *.* TO 'user_name'#'localhost';
NOTE:
PHP's mysql native driver ( mysqlnd ) has not been updated to use the new default authentication plugin (caching_sha2_password)
Tell mysql to use the old authentication plugin when creating user accounts by adding this to your /etc/my.cnf file:
default_authentication_plugin=mysql_native_password
But if you don't include the above directive in your my.cnf file, you can still issue the create user statement with the "IDENTIFIED WITH mysql_native_password" clause to use the old auth plugin!
So I decided to remove mysql 8, and install 5.7 which then works fine for me and obviously no compatibility issues.
This is a quick and dirty alternative to the compatibility issue between mysql server 5.* and 8.0.
The issue was that I migrated my databases from mysql v 5.* (MAMP stack) to mysql server 8.0 (installed separately), therefore the dump was creating some of the system tables with MyIsam engine (as it seems that in prior version, I think Innodb couldn't be used for system tables...?).
However, this was causing me a lots of issues in altering any system tables (user password etc...), I'm not sure whether it is because they are trying to get rid of the MyIsam engine and so new plugins are not adapted such as caching_sha2_password (and btw changing my.cnf file and adding "default_authentication_plugin=mysql_native_password" did not work for me...)
Thanks

Mysql Error:The user specified as a definer ('mysql.infoschema'#'localhost') does not exist' when trying to dump tablespaces

After I upgraded MySQL 5.7 to MySQL 8.0, I started MySQL again and I got an error:The user specified as a definer ('mysql.infoschema'#'localhost') does not exist' when trying to dump tablespaces.
I don't understand why this problem occurs. And I want to know how to solve it
I had the same error when I accidentally downgraded my MySQL version from 8 to 5.7. At the first start the older version broke something so that version 8 was showing the error above.
In my case I had to enter the docker container where MySQL was running first
docker exec -it mysql bash
Then I basically followed the steps here
mysql -u root -p
mysql> SET GLOBAL innodb_fast_shutdown = 1;
mysql_upgrade -u root -p
This took some minutes but then everything was working again.
It may occur after some time after you set up your new system.
As a suggested solution, just try on Windows
1) open cmd.exe as Administrator
2) run mysql_upgrade.exe -uyour_user_name -pyour_password
mysql_upgrade.exe can be located at
C:\Program Files\MySQL\MySQL Server 8.0\bin
Then run the following to see if the infoschema user has appeared.
select user, host from mysql.user;
In my case, such error was caused by that I had changed the host of the dba user from % to localhost to strengthen the security.
I used "abcdba" with DDL right to create db schema, and used "abc" with CURD right for the Web service to use the DB. After the change, the read operations were OK but the write operations failed with the error message in the OP.
Flush privilege or restarting the server did not solve the problem. Then I changed to host of the dba user back to %. Then things have become normal again.
Apparently mysql does not like the changes of host of the dba user, and existing databases created by that dba user will have problem if the host of the dba user is changed.
Essentially, changing the host of the dba user is actually removing user abcdba#% and creating a new user abcdba#localhost. Here had come the error message, since abcdba#% and abcdba#localhost are 2 differently fully qualified usernames.

MySQL 5.7.17 startup log showing [Note] Access denied for user 'UNKNOWN_MYSQL_USER'

I have MySQL Community Server version 5.7.17 running on Centos 6, everything comes with clean install, Centos 6 installed with "minimal" options, MySQL installed by official yum repo.
When I start MySQL server, the log "/var/log/mysqld.log" showing:
[Note] Access denied for user 'UNKNOWN_MYSQL_USER'#'localhost' (using password: NO)
It appears at the last line of the log, I tried to:
mysql> select * from mysql.user;
I can only see "root" and "mysql.sys" which comes by default, may I know what is the user 'UNKNOWN_MYSQL_USER'#'localhost'? is that something new in the version 5.7.17?
Thanks.
Nothing to worry about :)
You are receiving this message because someone/something tried to access MySQL server, but connection failed. You can reproduce this behaviour by attempting to connect to MySQL with wrong user and/or password and watch the error log file.
In your case, looks like it's the /etc/init.d/mysqld itself trying to test if MySQL server is up and running.
TIMEOUT="$STARTTIMEOUT"
while [ $TIMEOUT -gt 0 ]; do
RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
By default, in MySQL 5.7 the error log verbosity is set to 3 (errors, warnings and notes), this is why you're seeing this message in the error log file.
mysql> show variables like 'log_error_verbosity';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| log_error_verbosity | 3 |
+---------------------+-------+
I think it's just Mysql script to make sure your Mysql server db secure or not. If your log doesn't show this line, it mean they can access to db with 'UNKNOWN_MYSQL_USER'#'localhost' without password.

Play Framework 2.3 - Can't connect to remote database Linux (Play) -> Win 7 (MySQL)

I have a Linux machine (on 10.0.0.10) which I deployed my Play app to using:
activator dist
I have a Windows machine (on 10.0.0.51) running MySQL.
The database has 3 user accounts set up root#localhost, db_user#localhost, db_user#% all users have all permissions (it's just for testing).
I can access the db from the Linux machine using the mysql shell:
[neil#localhost ~]$ mysql -u db_user -p -h 10.0.0.51
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.12 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test_db |
| mysql |
| performance_schema |
| sakila |
| test |
| world |
+--------------------+
8 rows in set (0.04 sec)
mysql>
Where test_db is the test database I set up on the Windows machine.
However when I try to run the Play application I get the following:
[neil#localhost ~]$ ~/TEST_APP-1.0-SNAPSHOT/bin/test_app
Play server process ID is 5908
[error] c.j.b.h.AbstractConnectionHook - Failed to obtain initial
connection Sleeping for 0ms and trying again. Attempts left: 0.
Exception: java.net.ConnectException: Connection
refused.Message:Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
Oops, cannot start the server.
Configuration error: Configuration error[Cannot connect to database
[db_user]]
at play.api.Configuration$.play$api$Configuration$$configError
(Configuration.scala:94)
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
...
Here is the db config in my application.conf:
db.db_user.driver=com.mysql.jdbc.Driver
db.db_user.url="jdbc:mysql://10.0.0.51:3306/test_db?allowMultiQueries=true"
db.db_user.user=db_user
db.db_user.pass="password"
db.db_user.partitionCount=3
db.db_user.maxConnectionsPerPartition=20
db.db_user.minConnectionsPerPartition=5
db.db_user.acquireIncrement=5
It is worth noting that this configuration works when I am running the app in dev mode on Windows. But I do not know what's wrong on the Linux box and I have run out of things to try. (note I tried this with all firewalls turned off and got the same issue).
UPDATE
Within the play application I use:
public static final String DB_USER = "db_user";
...
JdbcTemplate jt = new JdbcTemplate(DB.getDataSource(DB_USER));
So I shouldn't have to use db.default.etc... in the conf? Is this not correct?
UPDATE 2
I don't know how I missed this but there was something else further down in the stack trace that is indicative of the problem (the stack trace is quite long so I didn't want to list the whole thing, maybe I should have):
Caused by: java.net.ConnectException: Connection refused
So... the server is listening on port 3306, on the windows server running netstat -an yields:
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING
TCP [::]:3306 [::]:0 LISTENING
The firewall is turned off (I know... just for testing).
And MySQL is accepting connections from the CLI.
I've just had a brain wave though.... The application.conf was generated on windows... I wonder if I need to run dos2unix on the config file which would be why it cannot find "db_user".
UPDATE 3
No :(
You need to use db.default in conf.
from JavaDatabase
I think the correct key to specify the password is not pass, but password:
db.db_user.password="password"
Also you can try to use db.default.* and DB.getDataSource(), but I guess that will not make much difference...

On MySql Is it possible to GRANT Select to ALL users?

My question is simple, can I GRANT permission to ALL (as in any user with any pwd coming from any machine) users ?
I know it COULD BE problematic in some cases. But ours is a demo database, with users unknown. So please spare us the rod.
From what I know and what I have tried the Answer is NO, we can not do it. I am posting this question to confirm my understanding.
AFAIK, we can't. Is there a way to hack around this ?
As people have said in the comments - this is probably a bad idea. But, I thought, why not have a crack and see how it can be done.
The most simple place to start would be to create a MySQL user without a username:
GRANT ALL ON *.* TO ''#'%' IDENTIFIED BY '';
This will let you login with any username - and a blank password. This might be what some people are looking for - but it sounds like you want any username any password.
To do that - I suggest using mysql-proxy. I would download the source code. If you're on Ubuntu then you will need the following packages to build it:
apt-get install libmysqlclient-dev \
pkg-config \
lua5.1 liblua5.1-0-dev liblua5.1-0 \
libglib2.0-dev \
libevent-1.4-2 libevent1-dev
If you do compile it then you'll need to run /sbin/ldconfig afterwards as root.
Then we can write a lua script to set the username and password for every connection. The mysql-proxy client has some example scripts, but the relevant examples/tutorial-scramble.lua file is old and doesn't work with the current version. You can use the following script:
local CLIENT_PROTOCOL_41 = 512 -- New 4.1 protocol
local CLIENT_SECURE_CONNECTION = 32768 -- New 4.1 authentication
local MYSQL_AUTH_CAPABILITIES = ( CLIENT_PROTOCOL_41 + CLIENT_SECURE_CONNECTION )
local password = assert(require("mysql.password"))
local proto = assert(require("mysql.proto"))
function read_auth()
local c = proxy.connection.client
local s = proxy.connection.server
local challenge = (s.scramble_buffer):sub(1,20)
local default_username = "foo"
local default_password = "bar"
proxy.queries:append(1,
proto.to_response_packet({
username = default_username,
response = password.scramble(challenge, password.hash(default_password)),
charset = 8, -- default charset
database = c.default_db,
max_packet_size = 1 * 1024 * 1024,
server_capabilities = MYSQL_AUTH_CAPABILITIES
})
)
return proxy.PROXY_SEND_QUERY
end
Save this as any-user-any-pass.lua or something. Then you will need to create the user in the database which I refer to in the script (username foo, password bar):
GRANT ALL ON *.* TO 'foo'#'localhost' IDENTIFIED BY 'bar';
Then we can start up mysql-proxy - we will connect it to the local mysql server on port 3306 and it will listen on port 3307. Use a command similar to this:
mysql-proxy --proxy-lua-script=`pwd`/any-user-any-pass.lua \
--proxy-backend-addresses=localhost:3306 \
--proxy-address=localhost:3307
Test it out in a different terminal:
ubuntu#test:~$ mysql -h 127.0.0.1 -P 3306 -u ANYTHING -pSOMETHING
ERROR 1045 (28000): Access denied for user 'ANYTHING'#'localhost' (using password: YES)
ubuntu#test:~$ mysql -h 127.0.0.1 -P 3307 -u ANYTHING -pSOMETHING
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 752
Server version: 5.5.29-0ubuntu1 (Ubuntu)
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| foo#localhost |
+----------------+
1 row in set (0.00 sec)
mysql>
As you can see - first I test connecting straight to MySQL - it rejects the ANYTHING/SOMETHING credentials. Then I connect to the MySQL proxy on 3307 and it lets me straight in because the lua script is changing the username and password the connection is using.