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.]
Related
I have a brand new Mac running Mojave. I've installed MySQL multiple times on my older Mac and never had a problem. But this install, for whatever reason, isn't getting off the ground.
I have installed MySQL and started the server. At this point, all I wanted to do was verify the version from the command line, and this is what I get:
> mysql -v
ERROR 1045 (28000): Access denied for user 'milnuts'#'localhost' (using password: NO)
> mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I've scoured the plethora of other posts, this one being the closest, but almost all solutions require actually being able to connect to MySQL as root. I can't even do that. I never specified a password during the install process, so what am I missing here? Is there some new config in Mojave somewhere that I don't know about?
Try using MySQL Workbench. You can install it on their site, or if you are using homebrew (which I strongly recommend), simply brew cask install mysqlworkbench.
You might need to try reinstalling mysql. This can be a pain if you didn't install it using homebrew. But, if you did, you can simply brew uninstall mysql then brew install mysql.
homebrew makes permission problems like these almost non existent! Honestly you should install literally everything using it.
I finally got this working. With the latest version of MySQL, v8.0.15, (and maybe before as well), during the configuration step it asks you to configure the server using one of two options.
Use Strong Password Encryption
Use Legacy Password Encryption
The first four or five times I installed, I selected option #1 which says...
MySQL 8 supports a new, stronger authentication method based on
SHA256. All new installations of the MySQL Server should use the this
method.
Connectors and clients that don't support this method will be unable
to connect to MySQL Server. Currently, connectors and community
drivers that use libmysqlclient 8.0 support the new method.
On my last install, I selected option #2. That seemed to clear up all the problems I was experiencing. So it obviously had something to do with the authentication process.
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)
I'm new to MySql environment and installed :
MySQL with the following commands:
sudo apt-get update
sudo apt-get install mysql-server
mysql_secure_installation
and also installed mysql workbench.
But when I'm trying to connect my localhost getting the follow error:
"Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory"
and even this is the first time I'm posting a question in stackoverflow, sorry for my presentation errors and syntax.
So I found the reason for that error message (at least for my case).
It's because MySQL as of version 8.04 and onwards uses caching_sha2_password as default authentication plugin where previously mysql_native_password has been used.
This obviously causes compatibility issues with older services that expect mysql_native_password authentication.
Solutions:
Check for an updated version of the client service you are
using (most recent workbench for instance).
Downgrade the MySQL Server to a version below that change.
Change the authentication plugin on a per user basis (I didn't find a global option, maybe there exists one though).
Now regarding option 3 this is as simple as altering the user:
ALTER USER user
IDENTIFIED WITH mysql_native_password
BY 'pw';
or when creating the user:
CREATE USER 'username'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
See MySQL Server Blog
See Oracle
Some more details coming here:
That caching_sha2_password plugin is the new default authentication plugin on MySQL 8 server. Only the libmysql library from that MySQL 8 distribution owns this plugin, and it is built statically into libmysql - the C-connector for various clients. That caching_sha2_password is not available separately for downloading.
This is the very first time that libmysql has an important plugin statically included. And this causes any other libmysql (including libmariadb and also older libmysql's) not to connect to MySQL 8 with a user which is defined to use that caching_sha2_password authentication.
I just hope that the guys from MariaDB are so nice to also include that caching_sha2_password in their libmariadb, to restore the drop-in-compatibility between MySQL and MariaDB.
From MySQL's server blog:
Support for caching_sha2_password was added in MySQL 8.0.3. Older
versions of libmysqlclient do not support this plugin. So, although
client tools that use libmysqlclient older than one available with
MySQL 8.0.3 can connect to MySQL 8.0.4 server using users that use
other authentication plugins such as mysql_native_password or
sha256_password, such client cannot connect to MySQL 8.0.4 server
using users which require caching_sha2_password support. For an
upgraded database, it means connecting using an existing user account
should not face any issues.
In the my.cnf file add the following line:
default-authentication-plugin=mysql_native_password
then restart the server.
The latest MYSQL versions have 'caching_sha2_password' as the default authentication type. Which does not allow remote connections to MYSQL and results in caching_sha2_password plugin error.
I have fixed it using
ALTER USER 'yourusername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
Now it allows your user to access MySQL from localhost.
If you want to access MySQL from multiple remote hosts then do the following,
**
ALTER USER 'yourusername'#'%' IDENTIFIED WITH mysql_native_password BY
'youpassword';
**
After every alter command in SQL run the following to take effect.
FLUSH PRIVILEGES;
OR restart MySQL server
Login to Mysql or your workbench, and run the following statement for any user who has this issue:
alter USER 'YOURUSERFORMYSQL'#'localhost' identified with mysql_native_password by 'YOURPASSWORD'
In case you did not create the user yet, you can activate this feature during the user creation.
create USER 'NEWUSER'#'localhost' identified with mysql_native_password by 'NEWPASSWORD'
Do I have to install MySQL on Windows to be able to connect to a MySQL server running on Linux and edit the files from windows ? Because I was installing the Workbench for SQL (I'm using MySQL Workbench Guide, Source: MySQL Workbench), then allow access to Linux (vps) from my pc, when I tried to install it, I'm stuck in the Windows config settings. Can someone help? (Screenshot provided.)
1 more thing: the program said "installing wmi" then "Could not set up connection: Could not connect to target machine."
you can install only workbench in windows without installing mysql server but you need to create a user on linux mysql server, who can then access it from the windows machine:
CREATE USER 'newuser'#'IP of the windows machine' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'#'IP of the windows machine';
FLUSH PRIVILEGES;
if you want the user to access regardless IP then you can use '%' instead of IP
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