Freebsd

使用 pkg 在 FreeBSD/amd64 10.3 中安裝 MySQL 5.7.13 埠後,mysqld_safe 未啟動

  • September 30, 2016

我在執行 mysql 伺服器時遇到問題。我剛剛安裝了 FreeBSD 10.3,我想在這裡執行 MySQL 伺服器,但是程序沒有啟動。

以下是我在安裝 FreeBSD 後逐步給出的所有命令:

portsnap fetch extract
pkg update
pkg install mysql57-server

/* 這裡 mysql 說的是帶有 root 密碼的 .mysql_secret 文件,但它根本沒有生成。我可以使用但沒有結果… */

find / -iname .mysql_secret

當我嘗試使用此命令首次執行 MySQL 時:

mysqld_safe --initialize --user=mysql

我得到這個:

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

這裡是 /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

我發現了類似的東西:

https://forums.freebsd.org/threads/56275/

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=209512

仍然沒有解決辦法。有任何想法嗎?我真的需要 MySQL。我也嘗試過使用 MySQL 5.6。同樣的問題…

最後 /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 $

[client]
port                            = 3306
socket                          = /tmp/mysql.sock

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

[mysqld]
user                            = mysql
port                            = 3306
socket                          = /tmp/mysql.sock
bind-address                    = 127.0.0.1
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
skip-symbolic-links

[mysqldump]
max_allowed_packet              = 256M
quote_names
quick

您需要初始化數據庫。這已經在 FreeBSD 啟動腳本中進行了處理,但用硬方法來做這件事可能並不太難。看看mysql_install_db實用程序。

但是,如果您將以下內容添加到/etc/rc.conf文件中:

mysql_enable="YES"

然後該mysql_install_db實用程序將在第一次自動執行。

該服務在引導時自動啟動,或者使用以下service命令手動啟動:

service mysql start

在能夠執行 mysql 命令之前,您需要以 root 身份執行以下操作來啟動 mysql 服務:

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

這將生成/root/.mysql_secret包含“root”@“localhost”初始密碼的文件。然後,您將能夠執行您的 mysql 命令。

引用自:https://unix.stackexchange.com/questions/305002