Getting this error when trying to run the command /usr/local/mysql/bin/mysqld_safe:
mysqld_safe Logging to '/usr/local/mysql/data/Users-MacBook-Pro.local.err'.
cat: /usr/local/mysql/data/Users-MacBook-Pro.local.pid: Permission denied
rm: cannot remove ‘/usr/local/mysql/data/Users-MacBook-Pro.local.pid’:
Permission denied
140313 11:09:18 mysqld_safe Fatal error: Can't remove the pid file:
/usr/local/mysql/data/Users-MacBook-Pro.local.pid
Please remove it manually and start /usr/local/mysql/bin/mysqld_safe again;
mysqld daemon not started
/usr/local/mysql/bin/mysqld_safe: line 129:
/usr/local/mysql/data/Users-MacBook- Pro.local.err: Permission denied
Shoould I remove the file? Is it safe to remove it?
Remove this pid file, make sure all the instances are stopped (kill any processes not going down), check nothing is listening the MySQL port 3306 (netstat should help) and try to start MySQL again.
To troubleshoot this see the permission you user has on the folder where the pid needs to be stored !
Try running the command with SUDO in front of it, like this
sudo /usr/local/mysql/bin/mysqld_safe
Enter your password. This will most likely resolve your problem.
The reason you are getting these errors is because the command you are running to start mysql requires access to certain files (listed in the error message). You need root access to these files to start mysql, so by adding sudo to the start of the command, you are giving root access.
Related
I am trying to get MySQL running on my localhost. This never happened to me before, but upon installation sudo apt-get install mysql-server did not ask me for the initial password.
After searching for answers to "reset" my password and battling with directory permissions, i am currently at this state:
The mysqld_safe solution:
After rebooting my computer, mysql -u root -p will ask me for my password, and after i enter it, it will complain with ERROR 1698 (28000): Access denied for user 'root'#'localhost'
If i instead try mysql -u root (no password), it will say ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
If i run the advice that other people have posted about resetting the password via mysqld_safe --skip-grant-tables, then i run across some hiccups along the way:
First i run sudo service mysql stop
Then sudo mysql_safe --skip-grant-tables will say mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
I can fix that if i do sudo mkdir -p /var/run/mysqld and sudo chown mysql /var/run/mysqld
After this, running mysqld_safe will run with the message Starting mysqld daemon with databases from /var/lib/mysql and then hang. And Ctrl+C doesn't get me out of that.
In a new terminal window i can now actually connect with mysql -u root and get the mysql> prompt.
I can set a new password with use mysql; update user set authentication_string=password('0000') where user='root';flush privileges; which will tell me it successfully updated the row with the message Rows matched: 1 Changed: 1 Warnings: 1
The warning only states: 'PASSWORD' is deprecated and will be removed in a future release.
And after all this, i'm back at square one: The process still hangs, so i have to reboot because killall mysqld_safe says no process found. After rebooting and entering my new password 0000, i will get access denied.
The system is Linux 4.15.0-48-generic #51-Ubuntu SMP.
The mysqladmin solution
If i run mysqladmin -u root password '0000' (without sudo), i get:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost''
If i run it with sudo, i get:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
This last one doesn't really tell me anything in regards of whether the password change happened or not; has it been refused or not (since it's a warning, not an error, i would assume it should go through), but in either case, trying to connect with 0000 still says "access denied".
Any advice on how to fix this is greatly appreciated.
I didn't quite solve the problems with mysql directly; However for myself, the acceptable solution was switching to a different database software, but it's still a MySQL system, and it got me up and running. So if anyone gets stuck on existing solutions not working like i did, maybe this comes in handy to get you on the road and finally writing code again.
What i did was:
Purged mysql off my system
Manually deleted /etc/mysql and /var/lib/mysql (don't know if this step was necessary)
apt clean, apt autoremove, apt update
Installed mariadb
Followed these instructions to rid myself of the timeout bug
Used the mysqld_safe --skip-grant-tables method to create a new user with all privileges, since connecting with root always kept failing
PHP + MariaDB now working again.
When trying to start mysql, I receive the following error message:
ERROR 3118 (HY000): Access denied for user 'root'#'localhost'. Account is locked.
I've installed MySQL via homebrew on my OSX and have not encountered such an issue until yesterday. When I try to run mysqld_safe, I receive:
mysqld_safe mysqld from pid file /usr/local/var/mysql/****.pid ended.
If I try sudo mysqld stop, I receive:
Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
I am unable to sudo restart mysql.server as I receive:
ERROR! MySQL server PID file could not be found!
I looked into running a data dump of my db but I am prevented from doing this as well.
Thanks for your attention to this matter and any insight you can provide in this matter. I greatly appreciate it.
I just downloaded MySQL and I tried to run it, and it gives the following error:
Starting MySQL
./usr/local/Cellar/mysql/5.7.15/bin/mysqld_safe: line 135: /usr/local/var/mysql/<host_name>.err: Permission denied
/usr/local/Cellar/mysql/5.7.15/bin/mysqld_safe: line 169: /usr/local/var/mysql/<host_name>.err: Permission denied
/usr/local/Cellar/mysql/5.7.15/bin/mysqld_safe: line 135: /usr/local/var/mysql/<host_name>.err: Permission denied
ERROR! The server quit without updating PID file (/usr/local/var/mysql/<host_name>.pid).
I referred to other StackOverflow posts, but the solutions do not seem to work for me, not sure where I am going wrong.
Further details:
restarting gives me following error:
MySQL server PID file could not be found!
I tried deleting the .err file in usr/local/mysql/data but it did not help
I cannot see any PID file in usr/local/mysql
/usr/local/var/ directory does not exist
As you can see you have a Permission denied error this error tells you that Mysql service does not have the proper permissions in order to modify the contents of /usr/local/var/mysql
./usr/local/Cellar/mysql/5.7.15/bin/mysqld_safe: line 135: /usr/local/var/mysql/<host_name>.err: Permission denied
if you have created this path manually /usr/local/var/mysql/ make sure that its permission is mysql:mysql. you can change it using the following command:
chown mysql:mysql /usr/local/var/mysql/ -R
Here is my problem: I cannot login to MySQL since I forgot the temporary password, i.e., the one that was assigned to me when I installed MySQL (if I type mysql in the command line, I receive this error: ERROR 1045 (28000): Access denied for user 'mona'#'localhost' (using password: NO). I receive the same error when I try with mysql -u root), so I tried the following to fix it:
I turned off MySQL
Then I created a file called restore in which I wrote SET PASSWORD FOR root#localhost=PASSWORD('');
Finally, sudo mysqld_safe --init-file=/usr/local/mysql/support-files/restore which didn't work. Then I tried step 3 with this command sudo /usr/local/mysql/support-files/mysql.server start and I got this error ERROR! The server quit without updating PID file (/var/run/mysqld/mysqld.pid).
In order to fix the last error, I tried the followings:
ps aux | grep mysql and killed MySQL processes. Then I started MySQL server but I received the same error again.
I checked my.cnf file in /private/etc (everything was commented in this file except this line: pid-file = /var/run/mysqld/mysqld.pid, but I found there is no mysqld folder in /var/run, instead it is located in this path: /usr/local/mysql-5.7.11-osx10.9-x86_64/bin/).
Now, I feel confused: why in /usr/local/, there are both mysql folder and mysql-5.7.11-osx10.9-x86_64?? what is their difference then? (I know the one I installed is the latter one)
How can I fix this issue?
I have installed MariaDB 10.0.14 following the official instructions in mariadb.com line by line.
I'm running Ubuntu 14.04 (upgraded from 12.04) and already have MySQL server installed. When I try to run mariadb I first stop the MySQL service:
$ sudo /etc/init.d/mysql stop
$ sudo /etc/init.d/mariadb start
but nothing happens. Apparently mariadb.sock cannot be created:
$ mysql -e "SELECT VERSION();" --socket=/opt/mariadb-data/mariadb.sock
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/mariadb-data/mariadb.sock' (111)
My error log is:
141112 13:50:37 mysqld_safe Starting mysqld daemon with databases from /opt/mariadb-data
141112 13:50:37 [Note] Server socket created on IP: '::'.
141112 13:50:37 [ERROR] mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 "Permission denied")
141112 13:50:37 [ERROR] Can't start server: can't create PID file: Permission denied
141112 13:50:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
I can't understand why I get permissions denied upon starting the service. I've created new system group and user, both called mariadb, that should handle this, as stated in the instructions.
Perhaps I should grant full r/w rights for my /opt/mariadb-data directory, but I'm not sure this is a good approach. What should I do?
Even though #hartmut-holzgraefe provides a nice solution in his answer, I decided to try a different approach. Since it works really well and independently from my MySQL server I thought I might share it with everybody as well.
Going with a Docker container for MariaDB (tutum/mariadb) turns out to be a quicker and perhaps cleaner solution than trying to install it alongside MySQL.
Steps
The steps to run mariadb via docker are:
Install Docker
Pull whichever version of MariaDB you want from tutum-docker-mariadb (in my case 10.1)
Build an image and run it to set up a container
Commands
The commands for step 3 are listed in the repo's README.
I'll only mention you may want to explicitly preset the hostname and the port of your machines, like so:
# build the image
docker build -t tutum/mariadb .
# run it
docker run -d -p 127.0.0.1:3307:3306 -e MARIADB_PASS="mypass" tutum/mariadb
# connect to mariadb
mysql -uadmin -pmypass -h127.0.0.1 -P3307
admin is a default user created with the initial run of the
container
mypass is a custom pass to override the random
password that is initially generated (otherwise you'd have to use
docker logs to get it it)
127.0.0.1:3307:3306
means you are binding the 3306 port inside the container with the
3307 port on you localhost.
Are you sure you got the --defaults-file=/opt/mariadb-data/my.cnf modifications to the /etc/init.d/mariadb correctly applied?
Problem is that mysqld still tries to create the .pid file in /var/run/mysql, not under /opt/mariadb. The /var/run/mysql directory belongs to the "mysql" system user, not the "mariadb" user you created according to the instructions.
And the /var/run/mysql setting can only come from the system /etc/mysql/my.cnf file, which is read by mysqld_safe / mysqld by default, UNLESS this is overridden with --defaults-file=...
Also note that --defaults-file needs to be the very first command line option