I know this is a frequently asked question, but I am really struggling.
I have recently tried to install MySQL with Homebrew on my Mac OS El-Capitan. However, I have encountered some problems with it and I want to reinstall it. Yet whenever I try doing that it gives me:
Error: Permission denied # rb_sysopen - /usr/local/var/homebrew/locks/mysql.formula.lock
I tried to bypass this error by simply sorting the named files out manually in the root account, but there were way too many files.
So I tried uninstalling it with root, but it gave me this error:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
I looked at many articles, including this link! Many of them suggested that I chown the /usr/local folder directly to my own user account with root, so I can run brew without any permission problems, but it is too dangerous.
I tried to run:
sudo chown root /usr/local/bin/brew
But this did not work as well.
Is there any ways I can bypass this error, and run brew as root?
Many of them suggested that I chown the /usr/local folder directly to my own user account with root, so I can run brew without any permission problems, but it is too dangerous.
chowning all of /usr/local/ is probably a bad idea because it's not entirely under Homebrew's control. But just /usr/local/var/homebrew/locks/mysql.formula.lock should be ok.
chown $USER /usr/local/var/homebrew/locks/mysql.formula.lock
And follow the advice of brew doctor.
tried to run: sudo chown root /usr/local/bin/brew But this did not work as well.
All this accomplished was to make the file /usr/local/bin/brew owned by root. It doesn't make it run as root. You should change it back to being owned by your user else you won't be able to upgrade brew.
To make it run as root you'd use setuid. Do not do this. It's inherently dangerous, and doubly so with your current understanding of permissions. Nothing personal, permissions take a while to get used to and appreciate.
Homebrew does not run as root to limit the damage possible by a malicious package or a simple mistake. By running as your user it can only damage what is accessible to your user. This walls off important things like system files. This is the purpose of the Unix permission system: to limit how much damage is possible. If you run brew as root all bets are off.
Furthermore, if /usr/local/var/homebrew/locks/mysql.formula.lock is owned by root that means MySQL ran as root. If you run MySQL as root and it is compromised your whole system is compromised. If you run MySQL as your user or a special limited mysql user, only your user files or mysql's own files can be compromised. Run it as proscribed by homebrew.
It's very much worth it to learn to run with as few permissions as possible.
Using brew as root is a bad idea due security reasons. Instead you can change the brew file ownership to the current logged in user. Type this single command:
sudo chown $USER /usr/local/bin/brew
i thought i would chime in to this conversation since it's one of the top hits on google still
To make it run as root you'd use setuid
i played with this today, this does not work since brew is a bash script, not an executable
One option that you have is to sudo touch /.dockerenv on linux: https://github.com/Homebrew/brew/blob/4eaaa867de30a1e09bfbf303f46493826dc746e7/Library/Homebrew/brew.sh#L182
You can also do this on macOS but it requires unsealing the root volume, which is considerably more work than what I was going to undertake today
My fix was to add a second test just like this one that whitelists brew info as a not-harmful command directly into brew.sh
i plan to submit this as an upstream patch
Related
In Google compute engine I do not have sudo ability on my VM.
According to the documentation and other threads on this topic, it should automatically be created when I SSH in from the Google Console. It worked this way for a week or two and now prompts for a password (I also rebuilt a vm that did this same thing a couple of weeks ago).
I have tried letting my keys expire, opening and closing a new session, and external ssh and they all display the same problem.
Here is a screenshot from a new browser instance:
You can try using “sudo -s” command from any user to directly switch to root and use sudo access. Also root password can be changed by using “passwd root” command after sudo access have been got.
That being said, the screen that you are getting is the lecture that is set to be displayed every time sudo is used. This can be changed in /etc/sudoers file by setting Defaults lecture=once as explained in this article. If the lecture is set to once, it will force the sudo command to show the prompt you are getting for the first time only.
Ok I have a mess of a problem. MySQL was installed on my machine (mac) already but I could not login via terminal (fairly new machine, to me). I had already been working with a couple databases via a SequelPro and decided to login via terminal for a couple jobs.
I couldn't and couldn't figure out why not. I ran brew install mysql and to my surprise it installed mysql. When logging in via terminal I was taken to this instance of MySQL that did not have my databases. Now, I restart SequelPro and it now logs into the new instance vs the one that has my data.
Any idea where I can find my databases and get them to use this new instance? Or any thoughts on how to clean things up in general?
---update---
The DB is InnoDB
/usr/local/bin/mysql
/usr/local/Cellar/mysql
/usr/local/Cellar/mysql/5.6.25/bin/mysql
/usr/local/Cellar/mysql/5.6.25/include/mysql
/usr/local/Cellar/mysql/5.6.25/include/mysql/mysql
/usr/local/Cellar/mysql/5.6.25/share/doc/mysql
/usr/local/Cellar/mysql/5.6.25/share/mysql
/usr/local/include/mysql
/usr/local/Library/LinkedKegs/mysql
/usr/local/opt/mysql
/usr/local/share/doc/mysql
/usr/local/share/mysql
/usr/local/var/mysql
/usr/local/var/mysql/mysql
/usr/local/var/mysql is where my databases from the first instance are. /Cellar is where homebrew installed MySQL. I got a recommendation in the comments to add a symlink...not sure which folder I should use as source or target in this case.
Also, not sure how I would start the database from the old location either.
Any help is most appreciated!
Short script to get the old db running:
GO to the working database data location
Go up one directory
Shutdown any mysqld.
mv database_directory database_directory.backup
Symlink the data directory of any other mysql:
ln -s old_data_directory database_directory
I'm kind of stuck on what to do with this. There were several options I found between this site and the mysql site on how to resolve a forgotten root password, but I think I've now broken it.
I was unable to use the line command with the created reset text file that mysql.com recommended here
So I uninstalled WAMP which is what I had used to install it to begin with. That also failed because after reinstall I had a new version and I couldnt log into either of them. Apparently both versions were still there as uninstalling WAMP didnt uninstall MySQL.
So I tried the make-sure-everything-is-deleted steps here and rebooted and reinstalled WAMP. No go, won't take default password.
Tried to run the command line command using the newest version and got this error.
Now I can't do anything I need to get done and all other posts I find on this seem to be variants of these things I've already tried.
This time around, the newer version of mysql let me log in with no password. I was able to get it fixed from the command line and get it reset to what I wanted. Tried that multiple times before, so I cannot say I understand what changed now, but it did.
Try to reset you password as described here
stop the mysql service (likely requires user to be admin/root)
write ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass'; into new file and save it under C:\mysql-init.txt (for windows)
Open cmd.exe (with admin privilges) and enter commands (see below)
Commands
C:\> cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
C:\> mysqld --init-file=C:\\mysql-init.txt
It worked for me.
I am a a newbie to database programming and I want to try out MySQL.
I just installed MySQL from the official website, I am running mac 10.8.2.
Anyways, whenever I try to run a simple command like $>mysql.server start
it says Permission denied.
I am able to open it through sudo but I would love to get this fixed as this is annoying me, that it wont work properly. I have been searching for the last two hours without finding a fix, so I was hoping anyone could give me a helping hand.
The easiest way is to install the MySQL Startup Item. Then you get a Preference pane for MySQL.
See http://dev.mysql.com/doc/refman/5.5/en/macosx-installation-startupitem.html for full instructions.
Re your comment:
It's often required for services like mysql.server need to run as a uid other than your user login. For instance, the MySQL data directory may only be writeable by the mysql uid. So starting such a service must be done from a user that can change the uid of the process. The root uid can do that, so it's necessary to use sudo to launch service processes like mysql.server.
TL;DR: YOU HAVE TO USE SUDO.
If you a absolute newbie to MYSQL and you just want to use the MYSQL server to test your code on you local MAC I would advice you to take a look at XAMPP / MAMP. Xampp offers a complete out of the box install for everything you need for a development servers (Apache server, MySQL, PHP, etc). Note, that I XAMPP / MAMP is not suitable for production server setting.
I personally use the XAMPP Windows version. I haven't tried MAMP but I have come across it many times . The XAMPP for Mac version seem not to have been update for a while so I suggest you give MAMP a try.
You could of course try to get your current install to work but that might require some work. Also with regard to firewall / security issues. With the out of the box version you will have to do a lot less. Why reinvent the wheel if you can easily install a out of the box version.
A while back I installed xampp and could not get it to run because the ports were already being used. Someone recommended that I type .. I believe it was: kill all, into the terminal to, I guess, kill the conflicting connections. This worked and I was able to access phpMyAdmin, but then I started having the problem again so i switched to MAMP. Now I can not access MySQL through the terminal. This is what I type in and this is what I get:
Macintosh:~ scottmcpherson$ mysql -u root --password=This_is_where_I_typed_my_pw
-bash: mysql: command not found
Macintosh:~ scottmcpherson$
I can, however access my database through phpMyAdmin. But the tutorials I'm following only show you how to create a database through the terminal plus I would really like to learn how to do it both ways. So, I'm thinking that the killall command screwed something up, or the other command that someone recommended a while back- which I can't remember.
You need to adjust your PATH environment variable. Details are here: http://www.metaltoad.com/blog/getting-command-line-access-php-and-mysql-running-mamp-osx
In short, open (or create) a .profile file in your home directory, and add this line:
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:$PATH
Paths may need to be adjusted depending on the location of your MAMP install.