# Have problems to start MySQL 5.7



## Neveroldmilk (Jun 15, 2016)

I used pkg(8) to install MySQL 5.7 by this command:

`$ sudo pkg install mysql57-server`

Then I have problems to start MySQL, and the command and output is listed below:

```
$ sudo sysrc mysql_enable=yes
mysql_enable:  -> yes

$ sudo service mysql-server start
/usr/local/etc/rc.d/mysql-server: WARNING: failed precmd routine for mysql
```
And I search by google and someone said the /usr/local/etc/rc.d/mysql-server file have to be modified. The line 
	
	



```
eval $mysql_install_db $mysql_install_db_args >/dev/null 2>/dev/null
```
 should comment the string 
	
	



```
">/dev/null 2>/dev/null"
```
.

I follow this order, and finally get these errors:

```
$ sudo service mysql-server start
2016-06-15 22:55:14 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-06-15 22:55:14 [ERROR]   Child process: /usr/local/libexec/mysqldterminated prematurely with errno= 32
2016-06-15 22:55:14 [ERROR]   Failed to execute /usr/local/libexec/mysqld --defaults-extra-file=/usr/local/etc/mysql/my.cnf --bootstrap --datadir=/var/db/mysql --lc-messages-dir=/usr/local/share/mysql --lc-messages=en_US --basedir=/usr/local
-- server log begin --
mysqld:
-- server log end --
/usr/local/etc/rc.d/mysql-server: WARNING: failed precmd routine for mysql
```
Please help me ,thanks!


----------



## SirDice (Jun 15, 2016)

You never have to edit any of the rc(8) files. 

Assuming this is a new install:

```
service mysql-server stop # make sure it's not running
rm -rf /var/db/mysql/*
chown mysql:mysql /var/db/mysql # In case the permissions are wrong
service mysql-server start
```


----------



## Neveroldmilk (Jun 16, 2016)

SirDice said:


> You never have to edit any of the rc(8) files.
> 
> Assuming this is a new install:
> 
> ...



I follow your instructions, but this error still comes out:

```
% sudo service mysql-server start
/usr/local/etc/rc.d/mysql-server: WARNING: failed precmd routine for mysql
```


----------



## SirDice (Jun 16, 2016)

Did you try to use your own my.cnf?


----------



## max21 (Jun 16, 2016)

So I was not along.  If this is in a jail see this:
https://forums.freebsd.org/threads/56564/

And if not, that would mean that we both have a dependency problem. I now believe it is the order in which to include each dependency, and believe me, it was a chore downloading each pkg as I needed them.  This way I did not miss anything.  Order was important in at least two places that I saw with my own eyes but forgot where.

If it works for you, that will answer all our questions.


----------



## xavi (Jun 17, 2016)

There's a similar problem solved on SO at this link.
Solution paraphrased here in case the link dies:

<snip>
Check that you've created a MySQL root user.
Not all installation scripts create them automatically.

To create a root user, run: 
`mysqld --initialize --user=mysql [with random root password]`
</snip>


----------



## Michel P (Jun 17, 2016)

You can also have trouble with an unreadable my.cnf file,
cf. https://forums.freebsd.org/threads/56631/


----------



## bishop__ (Aug 1, 2018)

SirDice said:


> You never have to edit any of the rc(8) files.
> 
> Assuming this is a new install:
> 
> ...



Thank you so much! This has solved the problem I've been facing for 2hrs.


----------



## dvl@ (Dec 3, 2020)

I came here with the same problem. It was the first search result. It didn't help.

I went to the second search result. That helped.

From my own blog post earlier this year:

*This loses your configuration and your data.*


```
sudo pkg delete mysql57-server
sudo rm -rf /usr/local/etc/mysql
sudo rm -rf /var/db/mysql
sudo pkg install mysql57-server
sudo service mysql-server start
```


----------



## SirDice (Dec 3, 2020)

If you have an existing install you need to be aware the socket has changed location recently (from /tmp/mysql.socket to /var/run/mysql.socket). Also the standard location for my.cnf changed some time ago, this used to be /var/db/mysql/my.cnf but is now /usr/local/etc/mysql/my.cnf.


----------



## richardtoohey2 (Dec 17, 2020)

Neveroldmilk said:


> I follow your instructions, but this error still comes out:
> 
> ```
> % sudo service mysql-server start
> ...


Think I've hit the same issue (too late to help the OP, but might help future searchers!) - look here: https://forums.freebsd.org/threads/...-disappeared-during-update.59525/#post-487252


----------

