I have a problem with running mysql server. I've just installed FreeBSD 10.3 and I want to run here MySQL server, but process doesn't starts.

Here are all commands i gave after install FreeBSD, step-by-step:

portsnap fetch extract
pkg update
pkg install mysql57-server

/* Here mysql says about .mysql_secret file with password to root, but it's not generating at all. I can use but there is no result... */

find / -iname .mysql_secret

When I try to first run MySQL using this command:

mysqld_safe --initialize --user=mysql

I get this one:

mysqld_safe Logging to '/var/db/mysql/host.err'
mysqld_safe Starting mysqld deamon with databases from /var/db/mysql
mysqld_safe mysqld from pid file /var/db/mysql/host.pid ended

Here you are /var/db/mysql/host.err

2016-08-22T11:56:27.6NZ mysqld_safe Starting mysqld daemon with databases from /var/db/mysql
2016-08-22T11:56:27.533572Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2016-08-22T11:56:27.533635Z 0 [ERROR] Aborting

2016-08-22T11:56:27.6NZ mysqld_safe mysqld from pid file /var/db/mysql/host.pid ended

I found something simmilar:



There is still no solution. Any ideas? I really need MySQL. I have tried with MySQL 5.6 too. Same problem...

At the end /usr/local/etc/mysql/my.cnf

# $FreeBSD: branches/2016Q3/databases/mysql57-server/files/my.cnf.sample.in 414707 2016-05-06 14:39:59Z riggs $

port                            = 3306
socket                          = /tmp/mysql.sock

prompt                          = \u@\h [\d]>\_

user                            = mysql
port                            = 3306
socket                          = /tmp/mysql.sock
bind-address                    =
basedir                         = /usr/local
datadir                         = /var/db/mysql
tmpdir                          = /var/db/mysql_tmpdir
slave-load-tmpdir               = /var/db/mysql_tmpdir
secure-file-priv                = /var/db/mysql_secure
log-bin                         = mysql-bin
log-output                      = TABLE
master-info-repository          = TABLE
relay-log-info-repository       = TABLE
relay-log-recovery              = 1
slow-query-log                  = 1
server-id                       = 1
sync_binlog                     = 1
sync_relay_log                  = 1
binlog_cache_size               = 16M
expire_logs_days                = 30
default_password_lifetime       = 0
enforce-gtid-consistency        = 1
gtid-mode                       = ON
safe-user-create                = 1
lower_case_table_names          = 1
explicit-defaults-for-timestamp = 1
myisam-recover-options          = BACKUP,FORCE
open_files_limit                = 32768
table_open_cache                = 16384
table_definition_cache          = 8192
net_retry_count                 = 16384
key_buffer_size                 = 256M
max_allowed_packet              = 64M
query_cache_type                = 0
query_cache_size                = 0
long_query_time                 = 0.5
innodb_buffer_pool_size         = 1G
innodb_data_home_dir            = /var/db/mysql
innodb_log_group_home_dir       = /var/db/mysql
innodb_data_file_path           = ibdata1:128M:autoextend
innodb_temp_data_file_path      = ibtmp1:128M:autoextend
innodb_flush_method             = O_DIRECT
innodb_log_file_size            = 256M
innodb_log_buffer_size          = 16M
innodb_write_io_threads         = 8
innodb_read_io_threads          = 8
innodb_autoinc_lock_mode        = 2

max_allowed_packet              = 256M
  • Just as an aside, you do not need to do portsnap fetch extract if you are using pkg :)
    – forquare
    Aug 30, 2016 at 8:18

3 Answers 3


You need to initialise the database. This is already handled in the FreeBSD startup script, but it's probably not too difficult to do it the hard way. Look at the mysql_install_db utility.

However, if you add the following to your /etc/rc.conf file:


Then the mysql_install_db utility will be run automatically first time through.

The service is started automatically at boot time, or manually using the service command:

service mysql start
  • mysql_install_db is deprecated so I used mysqld_safe --initialize --user=mysql
    – mregulski
    Aug 22, 2016 at 16:38

Before being able to run your mysql command you will need to start the mysql service by doing the following as root:

echo mysql_enable="YES" >> /etc/rc.conf
service mysql start

This will then generate the file /root/.mysql_secret which contains the initial password for 'root'@'localhost'. You will then be able to run your mysql command.


Finally I found solution myself:

cd /var/db/mysql #IMPORTANT STEP
/usr/local/libexec/mysqld --initialize --user=mysql #SECOND IMPORTANT STEP
echo mysql_enable="YES" >> /etc/rc.conf
service mysql-server start
mysql -u root -p (here password randomly generated from the terminal)

and so on...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .