MySQL Error 2049: Authentication protocol error - mysql

I'm having a problem while trying to remotely connect to my database server from my other server.
I receive the following error when i try to make a connection:
ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol ref
used (client option 'secure_auth' enabled)
I've checked the secure_auth option on the database server, and it is off, and my client seems to have this option activated as the message says.
Is there any way to fix this by only modifying the settings on the database server?

I was having this EXACT same problem, and this finally worked for me:
I uninstalled my local mysql client (I was running MySQL 5.6) and installed MySQL 5.5, and then restarted my computer.
I'm using Homebrew on my Mac, so I did this:
brew uninstall mysql
brew tap homebrew/versions
brew install mysql55
brew link --force mysql55
ln -sfv /usr/local/opt/mysql55/*.plist ~/Library/LaunchAgents
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql55.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql55.plist
Apparently my 5.6 client didn't want to use the less secure passwords that my company's servers were using, even though I had tried to turn off secure_auth locally. MySQL 5.5 doesn't complain about passwords being less secure, but 5.6 does.

This is happening because you have user accounts with passwords that used the ancient old hashing algorithm. Create a new user with new-style hash, and now use that new user with no trouble. Check here the related information

Related

installing legacy mysql for older version of Rails

I need to run an old Rails 4.0 application with mysql and its related data. Rails gem is mysql2 (0.4.2) Database data is coming from a server versions 5.6.44
bash_profile has
export PATH="/usr/local/opt/mysql#5.6/bin:$PATH"
bundle install process completes as expected, but when launching the server, the connection to the database is failing
rbenv/versions/2.2.10/lib/ruby/gems/2.2.0/gems/mysql2-0.4.2/lib/mysql2/client.rb:87:in `connect': Access denied for user
I attempt to adjust my connection mechanism by the sql command:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '<password>';
however, upon:
sudo mysql
Password:
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/Cellar/mysql#5.6/5.6.47/lib/plugin/caching_sha2_password.so, 2): image not found
So it appears I am in a sort of logical loop as there is no plugin download for the caching_sha2_password
What is the way out of this?
Bottom line: In this context, the following cannot be executed
create user 'USER_NAME'#'localhost' identified by 'PASSWORD';
as Homebrew has versions 5.6, 5.7 and 8.0 but ones where the set-up requires the caching_sha2_password plugin (introduced sometime during the 5.6 cycle apparently). Although root has no password, one cannot login as root mysql -uroot for this very reason.
Once it is accepted that this is a damned-if-you-do, damned-if-you-don't situation, time to move unconventionally...
I attempted to install both 5.6 and 8.0 via homebrew to import the mysql database under 8, but access it as 5.6. Whale fail. Exact same behaviour: root invariably needs access via sha2_password.
Solution
the mysql2 gem requires a version to hook up to. Given the version on the application 0.4.2, this meant
brew install mysql#5.6
go to https://downloads.mysql.com and find the appropriate community server installer for the OS to run on. Install. This application will allow root to login.
But now the connection to the database has to be the one to the downloaded application, not the homebrew keg (that's there to allow the application's gem to run). So the .bash_profile needs to have
export PATH=$PATH:/usr/local/mysql/bin
which points to the installed version rather than the homebrew one.
Now:
create user 'deploy'#'localhost' identified by 'some_nasty_string';
bundle exec rails db < my_db.sql
rails s
Get on with working.
One could also ponder about the interestingly seamless consequence of importing a mysql 5.6 database into 8.0
[Posted for anyone who has to dig up old material and make it evolve & to remember these hoops.]

New MySQL Workbench Install (Will not connect to root) Ubuntu 18.04

My newly installed MySQL workbench is refusing to connect to the root of my newly installed MySQL Community Server. Whenever I attempt to access "Local Instance 3306" (the default MySQL connection) I get the following error message.
This error message does change if I open "Local Instance 3306" via the "edit connection" tab and then "test connection". I'll get a different but similar error code.
I can access the server via the command line
and can confirm that the server appears to be active also via command line.
It is a fresh install of MySQLCommunity Server and MySQL Workbench running on Ubuntu 18.04 with only one user account. I installed both the server and workbench using apt and used the guide created by DevAnswers.co here.
After installing the server and workbench I attempted to access the server using the workbench BEFORE I ran the sudo mysql_secure_installation command. I got the same two errors. I then ran the secure installation command and assigned a password which I do remember and did input into the password field of mySQL workbench albeit with the same results. I am very new to mySQL and databases and am trying to install mySQL to learn how to use SQL. I'd appreciate any help you all can provide in resolving this issue.
Additional pictures:
and .
I suspect that you just need to follow this short guide to set a root password:
https://whs-dot-hk.github.io/ubuntu-18.04/install-mysql.html
After setting a root password, you should be able to connect to mysql-workbench.
In short the root user in MySQL is authenticated using an auth socket, not a password. That's what's giving the message you're getting in the first screenshot.
(I'm assuming this is for a development project, for a production project you should keep the default config)

How to restart remote MySQL server running on Ubuntu linux?

I'm using Ubuntu 12.04 LTS.
There is on MySQL server situated remotely. I want to restart it.
Can someone please give me in detail step-by-step instructions to restart the MySQL server?
Following are the Database server details of MYSQL I got from phpMyAdmin UI:
Server: Localhost via UNIX socket
Server type: MySQL
Server version: 5.5.40-0ubuntu0.14.04.1 - (Ubuntu)
Protocol version: 10
User: root#localhost
Server charset: UTF-8 Unicode (utf8)
Can someone please help me?
SSH into the machine. Using the proper credentials and ip address, ssh root#128.0.0.1. This should provide you with shell access to the Ubuntu server.
Restart the mySQL service. sudo service mysql restart should do the job.
If your mySQL service is named something else like mysqld you may have to change the command accordingly or try this: sudo /etc/init.d/mysql restart
sudo service mysql stop;
sudo service mysql start;
If the above process will not work let's check one the given code above you can stop Mysql server and again start server
Another way is:
systemctl restart mysql
To restart mysql use this command
sudo service mysql restart
Or
sudo restart mysql
Reference
I SSH'ed into my AWS Lightsail wordpress instance, the following worked:
sudo /opt/bitnami/ctlscript.sh restart mysql
I learnt this here:
https://docs.bitnami.com/aws/infrastructure/mysql/administration/control-services/
I have had a problem with my WordPress site, the connection with MySql has gone away, and to get it back I had to restart the server. This has been an annoying issue as I do not have that high traffic on the site.
I tried to check if MySQL is up and make the cronjob restart it but that does not work that well. I have been looking at the log, using.
tail /var/log/mysql/error.log
In the log, I looked for shutdown messages or errors. I identified that the MySQL connection crashed when the server run out of memory, so why did it run out of memory. I started to optimize Mysql resources by using the optimization tool from Percona tools.
I also checked when my WordPress is running smoothly or what is causing heavy traffic peaks to your DB. One way is to increase the size of the server, I did not have that much traffic, so I installed the New Relic tool on my server to monitor the server resources to find out which processes are consuming memory.
I found out that the server did not have enough memory and MySQL can’t allocate what it needs so it crashes, what I did was add swap space to help this.
here is the method to Add Swap Space
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04
If that's not enough, you may need to consider upgrading to a larger server. Either way, you should take a closer look at your memory consumption to better understand the problem.
You can simply run from your local terminal
ssh username#www.remoteserver.com -- sudo service mysqld restart
What worked for me on an Amazon EC2 server was:
sudo service mysqld restart

Cannot connect to Database server (mysql workbench)

Could you help me solve this problem ?
When I try to click "query database" under database menu in Mysql workbench. it gives me an error:
Cannot Connect to Database Server
Your connection attempt failed for user 'root' from your host to server at
127.0.0.1:3306:Can't connect to mysql server on '127.0.0.1'(10061)
Please:
Check that mysql is running on server 127.0.0.1
Check that mysql is running on port 3306 (note: 3306 is the default, but this can be changed)
Check the root has rights to connect to 127.0.0.1 from your address (mysql rights define what clients can connect to the server and from which machines)
Make sure you are both providing a password if needed and using the correct password for 127.0.0.1 connecting from the host address you're connecting from
The issue is likely due to socket authentication being enabled for the root user by default when no password is set, during the upgrade to ubuntu 16.04.
The solution is to revert back to native password authentication. You can do this by logging in to MySQL using socket authentication by doing:
sudo mysql -u root
Once logged in:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
which will revert back to the native (old default) password authentication.
Now use password as the password whenever required by MySQL.
Try opening services.msc from the start menu search box and try manually starting the MySQL service or directly write services.msc in Run box
It looks like there are a lot of causes of this error.
My Cause / Solution
In my case, the cause was that my server was configured to only accept connections from localhost. I fixed it by following this article: How Do I Enable Remote Access To MySQL Database Server?. My my.cnf file had no skip-networking line, so I just changed the line
bind-address = 127.0.0.1
to
bind-address = 0.0.0.0
This allows connections from any IP, not just 127.0.0.1.
Then, I created a MySql user that could connect from my client machine by running the following terminal commands:
# mysql -u root -p
mysql> CREATE USER 'username'#'1.2.3.4' IDENTIFIED BY 'password';
-> GRANT ALL PRIVILEGES ON *.* TO 'username'#'1.2.3.4' WITH GRANT OPTION;
-> \q
where 1.2.3.4 is the IP of the client you are trying to connect from. If you really have trouble, you can use '%' instead of '1.2.3.4' to allow the user to connect from any IP.
Other Causes
For a fairly extensive list, see Causes of Access-Denied Errors.
Did you try to determine if this is a problem with Workbench or a general connection problem? Try this:
Open a terminal
Type mysql -u root -p -h 127.0.0.1 -P 3306
If you can connect successfully you will see a mysql prompt after you type your password (type quit and Enter there to exit).
Report back how this worked.
I had a similar issue on Mac OS and I was able to fix it this way:
From the terminal, run:
mysql -u root -p -h 127.0.0.1 -P 3306
Then, I was asked to enter the password. I just pressed enter since no password was setup.
I got a message as follows:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL
connection id is 181. Server version: 8.0.11 Homebrew.
If you succeeded to log into mysql>, run the following command:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
You should get a message like this:
Query OK, 0 rows affected (0.19 sec)
Now, your password is "password" and your username is "root".
Happy coding :)
Run the ALTER USER command. Be sure to change password to a strong password of your choosing.
sudo mysql # Login to mysql`
Run the below command
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Now you can access it by using the new password.
Ref : https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04
I had to start Workbench as Administrator. Apparently it didn't have the required permissions to connect to my localhost database server process.
Right-click the Workbench shortcut and select Run as Administrator. In the shortcut's Properties window, you can click on "Advanced" and tick the box next to "Run as Administrator" to always run the Workbench with Admin privileges.
The error occur because the mysql server is not starting on your computer. You should start it manually. Do following steps:
Download and install wamp server according to your bit version(32bit or 64bit) in your computer(http://wampserver-64bit.en.softonic.com/) this link allows you to download wamp server for 64bit.
As soon as you install it you can double click and run it..(you can see a icon in the right hand of the taskbar.It may be hidden .so you can click the arrow which show you the hide apps runing).So click the icon and go to Mysql
Then go to Service and there you can find Start/Resume Services click on it..
And now it is done.Open mysql workbench and see.It will work..
I had same problem with Workbench on Ubuntu, problem was with permission.
Find Workbench app
Click button Permissions
Give all permission for this app
I struggled with this problem for awhile and did several reinstalls of MySQL before discovering this.
I know that MySQL server was running OK because I could access all my DB's using the command line.
Hope this works for you.
In MySQL Workbench (5.2.47 CE)
click Mange Server Instances (bottom right corner)
click Connection
in the Connection box select:
Local Instance ($ServerName) - root#127.0.0.1:3306 '<'Standard(TCP/IP)>
click Edit Selected...
under Parameters, Hostname change localhost or 127.0.0.1 to your NetBIOS name
click Test Connection
If this works for you, great. If not change the hostname back to what it was.
Even I faced a similar error when I opened MySQL Workbench.
The solution that worked for me was:
Click on the Start button on a Windows machine
Type services and press Enter
Find MySQL and click on it
On the top side of the left panel, you will find an option as Start the service
Click on Start which is visible as a hyperlink
Forr me reason was that I tried to use newest MySQL Workbench 8.x to connect to MySQL Server 5.1 (both running on Windows Server 2012).
When I uninstalled MySQL Workbench 8.x and installed MySQL Workbench 6.3.10 it successfully connected to localhost database
For those who ignored that the initial error message displaying is the following one:
The name org.freedesktop.secrets was not provided by any .service files
Make sure to install gnome-keyring using the following
sudo apt install gnome-keyring
I tried these steps -
Step 1 : Go to Ubuntu Software Center
Step 2 : Searched for MySql Workbench
Step 3 : And Click on Permissions
Step 4 : Enable Read, add, change or remove saved passwords
Then, enter Login Password
And then, I found that my problem solved
The problem is that MySQL server is not installed.
You can get the installer from here.
Then watch this 6-minute installation tutorial.
If then creating a new connection in MySQL Workbench is not working, make sure you run that connection as root as show below:
If you don't find your .ini file, check this answer (also written below).
Enter "services.msc" on the Start menu search box.
Find MySQL service under Name column, for example, MySQL56.
Right click on MySQL service, and select Properties menu.
Look for "Path To Executable" under General tab, and there is your .ini file, for instance, "C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" MYSQL56
I was in similar situations before and last time I found it was some Windows update issue(not sure). This time, I opened MySQL workbench and found no connection to my local database. I cannot see my tables, but yesterday I could connect to the database.
I found that my cause is that, after letting my computer sleeping for some time and wake it again, the mysql service is not running.
My solution: restart the service named "mysql" and rerun the workbench. Restarting the service takes a while, but it works.
To be up to date for upper versions and later visitors :
Currently I'm working on a win7 64bit having different tools on it including python 2.7.4 as a prerequisite for google android ...
When I upgraded from WB 6.0.8-win32 to upper versions to have 64bit performance I had some problems for example on 6.3.5-winx64 I had a bug in the details view of tables (disordered view) caused me to downgrade to 6.2.5-winx64.
As a GUI user, easy forward/backward engineering and db server relative items were working well but when we try to Database>Connect to Database we will have Not connected and will have python error if we try to execute a query however the DB server service is absolutely ran and is working well and this problem is not from the server and is from workbench. To resolve it we must use Query>Reconnect to Server to choose the DB connection explicitly and then almost everything looks good (this may be due to my multiple db connections and I couldn't find some solution to define the default db connection in workbench).
As a note : because I'm using latest Xampp version (even in linux addictively :) ), recently Xampp uses mariadb 10 instead of mysql 5.x causes the mysql file version to be 10 may cause some problems such as forward engineering of procedures which can be resolved via mysql_upgrade.exe but still when we try to check a db connection wb will inform about the wrong version however it is not critical and works well.
Conclusion : Thus sometimes db connection problems in workbench may be due to itself and not server (if you don't have other db connection relative problems).
My problem was that the MySQL server wasn't actually installed. I had run the MySQL Installer, but it didn't install the MySQL server.
I reran the installer, click "Add", and then added MySQL server to the list. Now it works fine.
In my case I have just installed MySQL Workbench but after uninstalling MySQL Workbench and installing MySQL installer and is same for both 32 and 64 bit then after it working like a charm. Hope it could be useful.
I just use:
sudo snap connect mysql-workbench-community:ssh-keys
sudo snap connect mysql-workbench-community:password-manager-service
I also struggled with this problem for quite a while.
I came accross this interesting thread from MySQL forum: http://forums.mysql.com/read.php?11,11388,11388#msg-11388
I also came accross (obviously) some good SO Q/A.
It seems that the message mentioned in "user948950" 's question can be coming from a wide range of reasons: log file too big, incorrect mysql.ini file values, spaces in the file path, security/acl issue, old entries in the registry, and so on.
So, after trying for 3h to fix this... I abandonned and decided to do a good old re-install.
This is where this post from (again) this MySQL thread came in useful, I quote:
Gary Williams wrote: Hi Guys,
I've had exactly the same problem and this is how I got it working
for me, starting with a non working installation.
Stop the windows service for any existing mysql installation.
Uninstall Mysql.
As with most uninstalls, old files are left behind. If your directory
is C:\mysql\ etc then delete the innob, etc, files but leave the
directories themselves as well as any existing databases in 'data'.
If your directory is C:\Program Files\ etc, delete all the mysql
directories.
It's now worth running regedit to make sure the old registry entries are deleted as well by the uninstall. If not, delete them.
It's ok to use the new .msi installer (essential files only), however ....
Do not use their default install path! Some genius set a path with spaces in it! Choose the custom install and select a sensible path,
ie, C:\mysql (note from Adrien: C:\mysqldata for ... the data)
Do not choose to alter the security settings. Uncheck the relevant box and the install will complete without having to set a root
password.
I think I have remembered everything.
Good luck
Gary
I did get into troubles when simply copy/pasting the databases I had in my previous "data" directory to the new one. So the work around I found was to export each database (I know... a lot of fun) and then re-import them one by one.
FYI: I used the following command to import C:/<MySQLInstallDir>/My SQL Server x.x/bin/mysql -u root -p <dbName> < "<dirPathOfDump>\<dumpName>.sql", that is for instance C:/mysql/MySQL Server 5.6/bin/mysql -u root -p mySupaCoolDb < "C:\mySupaCoolDbDump20130901.sql"
2022 and beyond this works for me:
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
change
bind-address = 127.0.0.1
to
bind-address = 0.0.0.0
Then remember to restart mysql sudo systemctl restart mysql
Initially I was confused, but I was able to solve the problem.
If your workbench was downloaded through the Snap package manager you could easily use this command to solve the problem, very simple:
sudo snap connect mysql-workbench-community:password-manager-service :password-manager-service
Go to services.msc and find MySQL.
If "Log on As" section is 'Network Service', then:
Double click on the MySQL row to open a pop-up
go to "Log on" tab
Select Log on as: "Local System account" and check "Allow service to interact with desktop"
Voilà, now you can start your service on localhost and make sure you enter correct root/user password on your MySQL Workbench, and you are good to go.
If you are using snap to install mysql workbench, try this:
sudo snap connect mysql-workbench-community:password-manager-service :password-manager-service to allow sandboxed package to access password service
askubuntu.com/a/1242777/1621549
This Solution was made as a comment before by Rohim Chou

Setting up MySQL server on OSX 10.7 (Lion) using Homebrew

I have successfully installed MySQL using Homebrew. However, whenever I type the command mysql I receive this error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I suspect this is a permission problem, as I have confirmed my system is looking for MySQL in the right location. However, I a novice with Unix(OSX) and don't know how to rectify the problem.
I am using OSX 10.7 (Lion)
which mysql produces /usr/local/bin/mysql
When you type 'mysql' you are running the MySQL client. The client needs to communicate with the server. If you simply run 'mysql' without any argument it assumes you are trying to connect to a mysql server that is located on 'localhost' using the user name as the user you are running the command as and without a password.
From the error it seems your server is not running yet. Start it by typing:
mysql.server start