# Installing and Starting MySQL on FreeBSD



## dub_c80 (Dec 6, 2017)

I am new to FreeBSD.  I would appreciate any help in getting MySQL running.  I have created a jail on my network and I'm trying to install and start MySQL on the jail. 

I used

```
pkg install mysql57-server mysql57-client
```

to install the software.  Then, following tutorials I found online, I removed the folder /var/db/mysql using:


```
rm -rf /var/db/mysql
```

I also edited /etc/rc.conf so that it now includes:


```
mysql_enable="YES"
```

Then, following the instructions here:

http://www.gamecreatures.com/blog/2016/02/22/freebsd-mysql-server-failed-precmd-routine/

I modified /usr/local/etc/rc.d/mysql-server according to those instructions.

Now, after rebooting my server, when I try to start mysql-server, I get the following errors:


```
root@mysql:/ # service mysql-server start                                      
2017-12-06 16:09:16 [WARNING] mysql_install_db is deprecated. Please consider sw
itching to mysqld --initialize                                                
2017-12-06 16:09:16 [ERROR]   Child process: /usr/local/libexec/mysqldterminated
 prematurely with errno= 32                                                    
2017-12-06 16:09:16 [ERROR]   Failed to execute /usr/local/libexec/mysqld --defa
ults-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/loca
l                                                                              
-- server log begin --                                                        
2017-12-06T21:09:16.398758Z 0 [Warning] --bootstrap is deprecated. Please consid
er using --initialize instead                                                  
2017-12-06T21:09:16.400483Z 0 [Warning] Could not increase number of max_open_fi
les to more than 1024 (request: 32929)                                        
2017-12-06T21:09:16.400511Z 0 [Warning] Changed limits: table_open_cache: 431 (r
equested 16384)                                                                
/usr/local/libexec/mysqld: Undefined symbol "fdatasync"                        
                                                                              
-- server log end --                                                          
/usr/local/etc/rc.d/mysql-server: WARNING: failed precmd routine for mysql
```

I noted the first line above, so I tried running mysqld --initialize, but I get this:


```
root@mysql:/ # /usr/local/libexec/mysqld --initialize                          
/usr/local/libexec/mysqld: Undefined symbol "fdatasync"
```

I tried searching online for "mysql fdatasync" and other strings like that, but I couldn't find any similar errors.  I'm not sure what fdatasync is or what this error means.

I would appreciate any help or guidance.  Thanks.


----------



## Snurg (Dec 6, 2017)

It is about one year here that I installed+configured mysql last time. I never did experience any run time error.
The only tutorials I used were the man pages.

I see you have taken "advice" from some "internet pages" which quality is unknown.
Best idea would be to rip down that jail and recreate it, so you get a clean unbotched fresh installation to start from.

And there is one thing I'd advise you to do. Always use pkg with the `pkg - j <jailname>` option.
This prevents nasty mistakes, for example to install things accidentally on the host instead of the jail, what might lead to strange results.
(It's a similar reason why people some time in their life make some experience, and no longer use 'rm -rf *', but instead always use that command with full path. Just an example...)


----------



## dub_c80 (Dec 6, 2017)

Thanks very much for your advice.

I deleted the jail, created a new jail.  I installed installed mysql57-server and mysql57-client using pkg -j.  When I tried to start mysql-server, I got a message saying I had to modify rc.conf like I did last time.  I installed nano and updated rc.conf as above.  I am still getting the same errors as before.


----------



## Snurg (Dec 6, 2017)

Hm. I looked, and that jail's rc.conf contains `mysql_optfile="/usr/local/etc/mysql.conf"` in addition to what you have in the rc.conf.
I have to admit, that I do not remember exactly why I added that line more than 1 year ago, though. Not sure, but it could have been because some programs use some undesirable defaults if they do not get told where to look for a configuration file. If that does not fix things, I can look into the actual conf file.


----------



## dub_c80 (Dec 7, 2017)

Thanks for checking.  I tried adding that line to the jail's rc.conf.  I rebooted the server, uninstalled mysql57-server and mysql57-client, then re-installed and tried again ... same problems.

I was thinking of starting over, creating a new jail, and installing from the tar.gz download from the MySQL web site.  

Does this seem like a reasonable idea?


----------



## Snurg (Dec 7, 2017)

I logged into my jail running mysql57 looking whether i have done anything special. I do not find anything, I only remember that I did the usual configuration and it just worked.

I guess the best idea would be to wait until the sysadmin gurus (SirDice and others) that are on the board come back online. It's 3 am in central Europe and they are most active around 10-10 o'clock (time here).
These guys know all the pitfalls and tricks to get around them.


----------



## SirDice (Dec 7, 2017)

fdatasync(2):

```
HISTORY
     The fsync() system call appeared in 4.2BSD.  The fdatasync() system call
     appeared in FreeBSD 11.1.
```

I'm guessing your jail is running 11.0-RELEASE instead of 11.1.


----------



## dub_c80 (Dec 7, 2017)

command freebsd-version shows:

11.0-RELEASE-p1


Should I try to change to 11.1?  Is there an easy way to do that?

Thanks.


----------



## SirDice (Dec 7, 2017)

Easiest solution, destroy the jail and build a new one with the correct version.


----------



## dub_c80 (Dec 7, 2017)

Thanks.  I'm not sure how to build a jail with 11.1-RELEASE.  I created my jail through freenas - they have an interface that creates jails for you, but it defaults to 11.0-RELEASE.

I tried to run:


```
freebsd-update -r 11.1-RELEASE upgrade
```

but I got an error about 'fetching public keys failed'.  I did some googling and tried using:


```
freebsd-update -s update6.freebsd.org -r 11.1-RELEASE upgrade
```
 
but I got a similar error.  

I know that freenas allows me to install a jail using a template for a specific OS.  I found a template that I can download for "freebsd11" but I'm not sure if that is 11.0 or 11.1, so I'm not sure if I should try that.

I assume there is a way I can create a jail from the freebsd shell that would allow me to choose what version the jail should run, but I haven't been able to find how to do that.  

If there are suggestions about where I can find information about how to create the jail with 11.1-RELEASE, then I could try the suggestion from SirDice above.


----------



## ShelLuser (Dec 7, 2017)

Well, 11.0 is not going to work anymore because that version has become obsoleted a few days ago: it's no longer supported, see this page for an overview. So your only option to get this to work is to upgrade to 11.1.

Normally done using either the source tree or freebsd-update. However, FreeNAS isn't a vanilla FreeBSD environment as far as I know so there could be some issues there. I only run FreeBSD and no derivative so... can't really say how they planned this.


----------



## grandwigg (Dec 8, 2017)

I just took a look at the FreeNAS 11.1 info, and it will be updating to FreeBSD 11.1 for the base OS.  (By the way, I'm thrilled they finally decided to match up release numbers with the base OS).

The update is due in about 4 days, and while their track record isn't great, there only four open issues at the moment.  The 11.1 Prerelease is available in the UI at the moment, as well, for those inclined.  I'd prefer to just sit on it for a few days or a week before going that route.  By then I can hope to have the full release.

Also, I wanted to thank SirDice as well for his excellent job pointing out the fdatasync()  history/newness.  I had been hitting my head against the same wall all evening.  An odd thing I noticed when checking the man page a few minutes ago was a difference in the second line :

```
HISTORY
     The fsync() system call appeared in 4.2BSD.  The fdatasync() system call
     appeared in FreeBSD 12.0
```

I know it doesn't apply to the current situation, but just thought it odd.  I'll try to remember to reply here if the update drops on time and solves the problem for me.

Again, thanks.


Edit:  I just checked the redmine and it has 5 open issues still.  I'll keep an eye out  and try to  update as necessary.

--UPDATE--

I upgraded to the new version, and there are a few things to note.

First, prior jails and plugins only show up in the old interface only (warden type jails).  Jails and plugins in the new interface are iocage type.  Both of these are expected.

To create iocage jails using the 11.1-RELEASE I needed to run iocage fetch to access the necessary files for it to work successfully.  I don't know if its only on upgraded systems or not.  It may need a bug report or just a wider notice.

I'll update again upon my success (or failure) with  MariaDB.

Edit[2018-01-13] : after a few weeks off, I got back to work on it, and was able to create an iocage jail in the UI.  However, it wouldn't start.  I logged in via ssh and ran iocage start [jail name].  It printed a few errors that I need to change in the jail config file (Oddly enough, the settings in question were checked in the webui, but not 'yes' and 'on' in the jail settings with the webui.  

After that it was easy to run a pkg update and pkg install mariadb-server-yadayada. The service is running and accessible from an external client.

I hope you have success as well.


----------



## Joe Fenton (Jan 18, 2018)

dub_c80 did you get mysql server working in the freenas jail? I am encountering every problem you have mentioned here, including not being able to update to 11.1 freebsd in the freenas jail. It seems very hard to diagnose the original error, which unfortunately I find with most problems with working with this OS, perhaps due to my lack of experience in Unix/Linux. It's like wading through treacle trying to find logs and documentation of errors, etc. Any help you can provide will be useful.
In the meantime, I'm going to see if PostgreSQL works instead...


----------



## dub_c80 (Jan 18, 2018)

I was finally able to install mysql57, but only after using iocage to create a jail that way.  I was never able to get it to work using the jails created by freenas.  

I had to do a little searching to learn how to create a jail with iocage using the command line, but once I did that, I was able to install mysql without much trouble in that jail.
I believe the new UI should create iocage jails, but when I did it, I used iocage and command line.


Hope this helps a little.


----------

