Access denied for user 'root'#'localhost' immediately after install - mysql

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.

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.]

Mysql won't start server during installation

I am trying to install mysql5.54 on windows 10 (1909) on a computer. Using Mysql latest installer.
Using port 3308
I have two issues:
1: I have to uncheck "Server data file" to complete install. (If I leave it checked, it always tells me it failed during installation)
During "Apply configuration", it stops in "Starting the server" for ever.
Can someone tell me how to trace the problem? I've installed this for many times, never had this problem previously.
I have mysql 5.7 installed on another port 3306, I don't think this will be the case.
I tried to run mysql.exe cmd line, it said:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
why it is denied my root user?
Thanks,
you should consider using docker or a vm, running two sql server on one computer can cause trouble obviously.
But i think you should choose only a different path for your second server
https://dev.mysql.com/doc/mysql-installer/en/mysql-installer-change-path-proc.html
So mysql can use it to store its cnf/ini filr an use a different data folder

MySql Access Denied when running python app [Ubuntu 1604/NGINX/uWSGI]

I am trying to deploy a test python app on digitalocean for the first time. (Ubuntu 16.04, uWSGI, NGINX). I've added a user and granted all privileges (and triple checked privileges). When I try and run the app, none of my tables get created and when I check the mysql error logs I see: "Access denied for user 'user'#'localhost' (using password: NO)"
The app itself runs fine without errors. It's just that none of my tables get created so when I enter a flask route that has a database query I get the 500 error
In my uWSGI, when defining database, I have the following:
ENVIRONMENT=DATABASE_URL=mysql://user:userpw#localhost:3306/databasename
command i ran to install mysql:
sudo apt-get install mysql-server
What might I be missing? Its driving me crazy...
I followed this tutorial very carefully, but changed postgres to mysql:
https://github.com/CristianoYL/Tutorials/blob/master/How%20To%20Deploy%20Python%20App%20Using%20uWSGI%20And%20Nginx.md
No mention so far, but how about FLUSH PRIVILEGES?
I'm also assuming there is no password. Password "NO" (as in none provided). I would look at the users table to see if they are set or not. It might be easier to test from the mysql cli vs. HTTP 500 errors :)
I tried this as a comment first, but it said I need 50 rep. I'll edit this post until I figure out a better way...

mysql cant log in as a regular user using root, same as phpmyadmin

I installedd LLMP on default, fresh Linux Mint 18 Mate install. Everything is updated and pretty fresh. Then the strange problem occured with logging into the database.
My exact steps:
1. Installed lighttpd. It crashed until I installed also gamin package, then it works.
Installed php7 with php-mysql
Installed mariadb-server
Run mysql_secure_install, defined new root password, answered all Y for deleting test db, disabling anonymous accounts and disallowing root login from tcp, etc. Everything was suggested as a valid, default answer.
Installed phpmyadmin, this fails on post-install, but running apt-get install -f repaired it and finished install correctly.
WTF1: Now, as root user I can login without password to mysql in the console.
WTF2: I can't login to mysql as a regular user, even when I give good password. It says "ERROR 1698 (28000): Access denied for user 'root'#'localhost'"
WTF3: I can't also login to database using phpmyadmin, using root account and proper password, when run on my localhost workstation via lighttpd.
What the heck is going on? My expectation was it should work out of the box, allowing me to login ONLY with root password either on CLI or via phpmyadmin. What is wrong?
I solved this and the answer is in the comment to the question.

sudo user doesn't have correct mysql permissions

I am trying to use wp-deploy (which makes use of Capistrano) to deploy my Wordpress site to a Digital Ocean Droplet. I think I have everything configured properly but when I try to run the ...
bundle exec cap staging db:pull
... I get an error
SSHKit::Runner::ExecuteError: Exception while executing as sudousername#xxx.xxx.xxx.xxx: wp exit status: 127
(username and IP changed for privacy of course). So I SSH into my droplet and try to just connect to mysql using
mysql -u sudousername -p
and get the following error...
ERROR 1045 (28000): Access denied for user 'sudousername'#'localhost' (using password: YES)
I think this is because sudousername belongs to the sudo group and that group doesn't have permission to manage the DB?
I was hoping to find one of two solutions:
Grant the appropriate permissions to sudousername so it can do what it needs to on the DB
Pass along a second username and pass with Capistrano for the DB user (I created a user with phpmyadmin when I setup the database for Wordpress). The thought here being that when Capistrano is already SSH'd in and trying to perform functions on the DB it would use this other username and password.
I have looked for a solution for a couple hours now but I am a server n00b and haven't been able to find anything (and probably not sure what I am looking for).
Is anyone able to help? Thanks in advance!
I have figured out what the issue was. wp-deploy was using my sudo users credentials to SSH in and execute some shell commands. One of which was trying to use the WP Cli tool which I didn't have installed. Once I installed the WP Cli tool the scripts SSH'd in and ran wp db export and does so as the correct DB user. Thanks to #JuanTomas for helping me narrow that down.
For those that are having the same issue I also had to grant my DB user permissions for "LOCK TABLES'. Also, if you are using Wordpress 4.4+ you need WP Cli version 0.24 minimum or there will be compatibility issues. Use wp --info to check what version you have.