我在运行 mysql 服务器时遇到问题。我刚刚安装了 FreeBSD 10.3,我想在这里运行 MySQL 服务器,但进程没有启动。
以下是我在安装 FreeBSD 后给出的所有命令,一步一步:
portsnap fetch extract
pkg update
pkg install mysql57-server
/* 这里mysql说关于.mysql_secret文件和root密码,但它根本没有生成。我可以使用但没有结果... */
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
答案1
您需要初始化数据库。这已经在 FreeBSD 启动脚本中处理了,但是用困难的方式来完成它可能并不太困难。看看mysql_install_db
实用性。
但是,如果您将以下内容添加到/etc/rc.conf
文件中:
mysql_enable="YES"
然后该mysql_install_db
实用程序将在第一次自动运行。
该服务在启动时自动启动,或者使用service
命令:
service mysql start
答案2
在能够运行 mysql 命令之前,您需要以 root 身份执行以下操作来启动 mysql 服务:
echo mysql_enable="YES" >> /etc/rc.conf
service mysql start
/root/.mysql_secret
然后,这将生成包含“root”@“localhost”初始密码的文件。然后您将能够运行 mysql 命令。
答案3
最后我自己找到了解决方案:
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)
等等...