Install Mysql On Mac Catalina

Question or issue on macOS:

This section contains tutorials for installing CatDV on Mac OS X Catalina (10.15). Please use the left hand menu to navigate through the sections. Hello Friends,In this video tutorial, you will learn to install mysql database server on mac os x catalina. I have explained the whole process of installatio. How to install MySQL Community Server on macOS Big Sur version 11.x (2021) March 10, 2021 Using MySQL Workbench on macOS Big Sur version 11.x (2021) Apple M1 device March 10, 2021 Python Tutorial – How to make a JSON REST API Call September 24, 2018. MySQL for Mac is a software tool used for most popular programming languages, like PHP, Java, Perl, C, C , and others. In short, it is a database management system (DBMS), which allows you to connect to the database, run SQL queries and receive a response.

I’m setting up my development environment in the new macOS Sierra .

First of all, I installed Rbenv, Ruby (2.3.1), Homebrew and so the latest version of MySQL (5.7.15).

Ok, MySQL was initialized. Time to install the mysql2 gem…

But it didn’t work. 😞

How to solve this problem?

Solution no. 1:

I just had the same problem, tried all of the solutions listed above, then commenced to bang my head against they keyboard for a couple of hours.

I then thought to try and install/reinstall the Xcode Command Line Tools:

Once I did that the mysql2 gem installed w/ no problems. I hope that does the trick!

Solution no. 2:

When you install openssl via brew, you should get the following message:


Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you’ll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

You can set these build flags (for the local application) by running the following:

This worked for me.

See bundler’s documentation for more information.

Solution no. 3:

Lots of great answers, I was able to combine them into this:

because I was not comfortable with bundle config

Install mysql on mac catalina

Solution no. 4:

I am here to share my fix, since the other answers didn’t work.

For my environment, I need MySQL 5.6 so I had to use:

brew install mysql56 instead of brew install mysql

Bundle installing the mysql2 gem kept failing, until:

brew link mysql56

I also ran afterwards:

mysql.server start

The last step might be unnecessary, but just in case.

Solution no. 5:

With Mac OS 10.15 Catalina when I tried Alessandro’s fix the gem and extensions could be installed correctly but bundle install failed. What worked was just:

without the cppflags part.

Solution no. 6:

Here’s what worked for me.

Originally I ran:

then

I received an error in /Users/…/.bundle/ruby/2.5.0/extensions/x86_64-darwin-18/2.5.0/mysql2-0.5.3/mkmf.log :

clang: error: unsupported option ‘–with-cppflags=-I/usr/local/opt/openssl/include’

So I removed “–with-cppflags=-I/usr/local/opt/openssl/include”

Then ran:

followed by:

Which worked.

Solution no. 7:

Almost the same scenario as @Caio Tarifa, Ruby 2.3.3, mysql 5.6 and mysql2. Tried on couple of solutions above and finally make it work with @kylekeesling’s approach.

First, tried on solution 1 by @spickermann:

Nothing happened, same error shown.

Second, tried on solution by @Alessandro Berardi:

This got different but more errors since it overwrite gem extension’s config so all gem extension installation failed.

Finally, tried on @kylekeesling solution:

It fix mysql gem issue as well as nikogiri. Since I already intall Xcode, in my case it’s reinstall the Xcode Command Line Tools.

Solution no. 8:

Try installing xcode-select –install

Solution no. 9:

So I ran into this similar issue and for me it turned out to be a wrong ruby version and incompatible MySQL version. I use ruby 2.3 on most of my projects but inherited a 2.1 project. Changing to rvm to use 2.1 got me a little further.

Then I found this: https://github.com/brianmario/mysql2/issues/603 that said you had to use mysql2 gem version greater than 0.3.17 with MySQL version 5.7

Updated gem to 0.3.17 and it fired right up. Hope this helps someone.

Solution no. 10:

If none of the above works .. like in my case, doing this solved the issue
brew install openssl

FYI: i am using MacOS Catalina

Hope this helps!

Question or issue on macOS:

I’m trying to setup up MySQL on mac os 10.6 using Homebrew by brew install mysql 5.1.52.

Everything goes well and I am also successful with the mysql_install_db.
However when I try to connect to the server using:

Install Mysql On Mac Catalina

I get:

I’ve tried to access mysqladmin or mysql using -u root -proot as well,
but it doesn’t work with or without password.

This is a brand new installation on a brand new machine and as far as I know the new installation must be accessible without a root password. I also tried:

but I also get

How to solve this problem?

Solution no. 1:

I think one can end up in this position with older versions of mysql already installed. I had the same problem and none of the above solutions worked for me. I fixed it thus:

Used brew’s remove & cleanup commands, unloaded the launchctl script, then deleted the mysql directory in /usr/local/var, deleted my existing /etc/my.cnf (leave that one up to you, should it apply) and launchctl plist

Updated the string for the plist. Note also your alternate security script directory will be based on which version of MySQL you are installing.

Step-by-step:

I then started from scratch:

  1. installed mysql with brew install mysql
  2. ran the commands brew suggested: (see note: below)

  3. Start mysql with mysql.server start command, to be able to log on it

  4. Used the alternate security script:

  5. Followed the launchctl section from the brew package script output such as,

Note: the --force bit on brew cleanup will also cleanup outdated kegs, think it’s a new-ish homebrew feature.

Note the second: a commenter says step 2 is not required. I don’t want to test it, so YMMV!

Solution no. 2:

Here are detailed instructions combining getting rid of all MySQL from your Mac then installing it The Brew Way as Sedorner wrote above:

Remove MySQL completely per The Tech Lab
  • ps -ax | grep mysql
  • stop and kill any MySQL processes
  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/var/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
  • edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
  • rm -rf ~/Library/PreferencePanes/My*
  • sudo rm -rf /Library/Receipts/mysql*
  • sudo rm -rf /Library/Receipts/MySQL*
  • sudo rm -rf /private/var/db/receipts/*mysql*
  • sudo rm -rf /tmp/mysql*
  • try to run mysql, it shouldn’t work
Brew install MySQL per user Sedorner from this StackOverflow answer
  • brew doctor and fix any errors

  • brew remove mysql

  • brew cleanup

  • brew update

  • brew install mysql

  • unset TMPDIR

  • mysql.server start

  • run the commands Brew suggests, add MySQL to launchctl so it automatically launches at startup

mysql should now work and be running all the time as expected

Godspeed.

Solution no. 3:

Had the same problem. Seems like there is something wrong with the set up instructions or the initial tables that are being created. This is how I got mysqld running on my machine.

If the mysqld server is already running on your Mac, stop it first with:

launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist

Start the mysqld server with the following command which lets anyone log in with full permissions.

mysqld_safe --skip-grant-tables

Then run mysql -u root which should now let you log in successfully without a password. The following command should reset all the root passwords.

UPDATE mysql.user SET Password=PASSWORD('NewPassword') WHERE User='root'; FLUSH PRIVILEGES;

Now if you kill the running copy of mysqld_safe and start it up again without the skip-grant-tables option, you should be able to log in with mysql -u root -p and the new password you just set.

Solution no. 4:

If brew installed MySQL 5.7, the process is a bit different than for previous versions.
In order to reset the root password, proceed as follows:

A temporary password will be printed to the console and it can only be used for updating the root password:

Solution no. 5:

Okay I had the same issue and solved it. For some reason the mysql_secure_installation script doesn’t work out of the box when using Homebrew to install mysql, so I did it manually. On the CLI enter:

That should get you into mysql. Now do the following (taken from mysql_secure_installation):

Now exit and get back into mysql with: mysql -u root -p

Solution no. 6:

I had the same problem just now. If you brew info mysql and follow the steps it looks like the root password should be new-password if I remember correctly. I was seeing the same thing you are seeing. This article helped me the most.

It turned out I didn’t have any accounts created for me. When I logged in after running mysqld_safe and did select * from user; no rows were returned. I opened the MySQLWorkbench with the mysqld_safe running and added a root account with all the privs I expected. This are working well for me now.

Solution no. 7:

If mysql is already installed

Stop mysql completely.

  1. mysql.server stop <– may need editing based on your version
  2. ps -ef | grep mysql <– lists processes with mysql in their name
  3. kill [PID] <– kill the processes by PID

Remove files. Instructions above are good. I’ll add:

  1. sudo find /. -name '*mysql*'
  2. Using your judgement, rm -rf these files. Note that many programs have drivers for mysql which you do not want to remove. For example, don’t delete stuff in a PHP install’s directory. Do remove stuff in its own mysql directory.

Install

Hopefully you have homebrew. If not, download it.

I like to run brew as root, but I don’t think you have to. Edit 2018: you can’t run brew as root anymore

  1. sudo brew update
  2. sudo brew install cmake <– dependency for mysql, useful
  3. sudo brew install openssl <– dependency for mysql, useful
  4. sudo brew info mysql <– skim through this… it gives you some idea of what’s coming next
  5. sudo brew install mysql --with-embedded; say done <– Installs mysql with the embedded server. Tells you when it finishes (my install took 10 minutes)

Afterwards

  1. sudo chown -R mysql /usr/local/var/mysql/ <– mysql wouldn’t work for me until I ran this command
  2. sudo mysql.server start <– once again, the exact syntax may vary
  3. Create users in mysql (http://dev.mysql.com/doc/refman/5.7/en/create-user.html). Remember to add a password for the root user.

Solution no. 8:

brew info mysql

mysql.service start

or mysql -u root

I’m looking for a solution for some time but I can not solve my problem. I tried several solutions in stackoverflow.com but no this helping me.

Solution no. 9:

TL;DR

MySQL server might not be running after installation with Brew. Try brew services start mysql or just mysql.server start if you don’t want MySQL to run as a background service.

Full Story:

I just installed MySQL (stable) 5.7.17 on a new MacBook Pro running Sierra and also got an error when running mysql_secure_installation:

Say what?

According to the installation info from Brew, mysql_secure_installation should prompt me to… secure the installation. I figured the MySQL server might not be running and rightly so. Running brew services start mysql and then mysql_secure_installation worked like a charm.

Solution no. 10:

Here is an update for MySQL 5.7

Can I Install Mysql On Mac

Hope this helps!