How to uninstall MySQL 5.6 when installed by brew on macOS? - mysql

Installed MySQL by issuing the following commands:
$ brew install mysql56
$ brew services start mysql#5.6
Now I can't access it:
$ mysql -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Want to uninstall it and tried the following:
brew remove mysql
brew cleanup
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/MySql*
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
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*
(Restart computer)
Now work.
When I install it again and run:
brew intall mysql56
brew services start mysql#5.6
It shows:
Service `mysql#5.6` already started, use `brew services restart mysql#5.6` to restart.
But I can't find it in the process list.

to Stack Overflow.
I will answer this but, please be sure to check for existing questions as this has already been asked.
Try this
brew uninstall --force mysql
Or From Google First result being from CoderWall
Find Any Running Instances
ps -ax | grep mysql | grep -v grep
# OR for only the running `PID`
ps -ef | grep mysql | grep -v grep | awk '{print $2}'
# OR this If you have this on your machine, I recommend using
pgrep -f mysql
If running the kill process
kill 24024824082408 # change this number to what was returned in the grep
Save your database data
This will save your MySQL Data Folder to your desktop in a folder mysqldata.
# I backup my data from mysql to my desktop
mkdir ~/Desktop/mysqldata/
# data
cp -r /usr/local/mysql/data ~/Desktop/mysqldata
Save your MySQL Workbench Data for migration.
# MySQL workbench active sessions including the unsaved query windows
cp -r ~/Library/Application\ Support/MySQL/Workbench/sql_* ~/Desktop/mysqldata
# data this is a log containing queries that were logged at some point, more of a `just in case`
cp ~/Library/Application\ Support/MySQL/Workbench/log/sql_actions_unconnected.log ~/Desktop/mysqldata/sql_actions_unconnected.sql
# data of user snippets as people forget about this.
cp /Users/`id -un`/Library/Application\ Support/MySQL/Workbench/snippets/User\ Snippets.txt ~/Desktop/mysqldata/UserSnippets.txt
Removal and Cleanup
brew remove mysql
brew cleanup
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
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*
Edit (if applicable) vi /etc/hostconfig and remove the line MYSQLCOM=-YES-
Restart your computer if you want to ensure any MySQL processes are killed
Try to run mysql, it shouldn't work.
Don't worry about some of the rm's failing they are just nonexistent.
Hope this helps & have a great day!

Related

mysql_secure_installation is asking previous password

I am repeatedly facing issue while running mysql_secure_installation command after installing mysql version 5.7 on mac pro. I tried uninstalling the mysql with below commands
$ brew services stop mysql#5.7
$ brew unlink mysql#5.7
$ brew remove mysql#5.7
$ 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*
$ rm -rf ~/Library/PreferencePanes/My*
$ sudo rm -rf /Library/Receipts/mysql*
$ sudo rm -rf /Library/Receipts/MySQL*
Later I re-installed the mysql version 5.7 using homebrew and tried to set password for root user. Unfortunately, mysql_secure_installation is again asking old password to enter which I am not aware of, but I need to set new password for root user. Please help me to resolve this issue.

How to completely uninstall MySQL on MacOS

I followed another stackoverflow post to completely uninstall all instances of MySQL (I had 5..)
$ sudo rm /usr/local/mysql
$ sudo rm -rf /usr/local/mysql*
$ sudo rm -rf /Library/StartupItems/MySQLCOM
$ sudo rm -rf /Library/PreferencePanes/My*
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 /var/db/receipts/com.mysql.mysql*
And reinstalled using
brew install mysql
but when I start the server, I have to put in the old root user password, which means it's still storing the passwords somewhere.
Brew prompted me change the password which I did, and then I got this error
... Failed! Error: File './mysql/user.MYD' not found (Errcode: 2 - No such file or directory)
So clearly mysql hasn't been completely uninstalled.
Ended up solving it by running
ps -ax | grep mysql
then going to each of the folders and removing any mysql data
then uninstalling XAMPP
then restarting computer
then
brew install mysql

'./mysql/user.MYD' not found (Errcode: 13 - Permission denied)

I am trying to do a fresh install of Mac OSX LAMP and running the command
mysql_secure_installation
I have inputting the root password and I have to now input a new password when I'm hit with this error, has anyone got any experience with this?
Re-enter new password:
... Failed! Error: File './mysql/user.MYD' not found (Errcode: 13 - Permission denied)
Please retry to completely remove mysql by executing:
brew remove mysql
brew cleanup
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*
And then restart your computer to make sure that all the processes have been killed.
Then execute these commands to install MySQL:
brew update
brew install mysql
unset TMPDIR
mysql_install_db --verbose --user='<your-username>' --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
mysql.server start
This should do the trick.
I think there was a corruption within the install and decided to delete and use brew to install and all is now well! Follow these steps
Open a terminal window
Use mysqldump to backup your databases to text files!
Stop the database server
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
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*
Then installed via Brew
brew install mysql

mariadb 10.1.21 mysql.server start error on macOS Sierra

I have just installed mariadb 10.1.21 latest with brew.
here is what i got with command
> mysql.server start
or
/usr/local/Cellar/mariadb/10.1.21/support-files/mysql.server start
whatever.
Starting MySQL
.170225 03:41:19 mysqld_safe Logging to '/usr/local/var/mysql/mac-615.err'.
170225 03:41:19 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
ERROR!
I do not know any reason why I cannot even start mysql daemon.
I had the same problem today. What I did was just uninstalling both mariaDB and mysql.
Remember doing a backup of your DB's in case you need it.
Just run the following commands in you terminal:
For mysql:
brew remove mysql
For mariaDB:
brew remove mariadb
Then, remove mysql folders and files:
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
vi /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*
Maybe, most of the folders and files won't exist, just to be sure they won't mess with the installation, do it.
After you have removed mysql and mariaDB files, run
brew cleanup
to ensure cache is gone.
Once it's done, you should be able to do a clean installation of mariadb with
brew install mariadb
Try your installation by running
mysql.server start
If hangs at starting, try restarting mysql with
mysql.server restart -f
By doing this, I was able to run mariadb, I hope it works for you.

MySQL will not run on OSX El capitan for any reason whatsoever

First of all let me start by saying that I have read and tried all approaches that I found on the web and stack overflow.
What I get when I try to run
mysql.server start
or
sudo /usr/local/mysql/support-files/mysql.server start
is
ERROR! The server quit without updating PID file (/usr/local/var/mysql/hostname.local.pid).
What I get when I try to run:
mysql
is
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
I also tried:
sudo mysqld_safe &
Clicking the mysql start button on system preferences.
Restart the computer
Reinstall mysql
Install older version of mysql
killall and then try to run mysql
sudo chmod -R 777 /usr/local/mysql/
`sudo chown -R mysql /var/lib/mysql/
rm /usr/local/var/mysql/localhost.err
sudo /usr/local/mysql/bin/mysqld_safe start
tried everything here: How to auto-load MySQL on startup on OS X Yosemite / El Capitan
I am out of ideas, I don't know what to do.
What I did to actually make it work:
killall -u username
brew remove mysql
brew cleanup
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
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*
*Restart the computer
brew doctor and fix any errors
brew update
brew install mysql
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
mysql.server start