我遇到了以下问题。当 mysql 作为服务启动时,一切正常:例如
oleg: ~$ sudo service mysql start
mysql start/running, process 9111
oleg: ~$
但是当我通过命令行启动时,什么都没起作用。配置本身在以下路径上看起来并不正确:
oleg: ~$ cat /tmp/tmpWtpvgM/etc/my.cnf
[mysqld]
pid-file=/tmp/tmpWtpvgM/tmp/mysqld.pid
datadir=/tmp/tmpWtpvgM/var
port=3308
tmpdir=/tmp/tmpWtpvgM/tmp
socket=/tmp/tmpWtpvgM/tmp/mysql.sock
oleg: ~$ /usr/sbin/mysqld --defaults-file=/tmp/tmpWtpvgM/etc/my.cnf
--user=root
2015-11-26 12:18:24 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use
--explicit_defaults_for_timestamp server option (see documentation for more details).
2015-11-26 12:18:24 0 [Note] /usr/sbin/mysqld (mysqld 5.6.27-0ubuntu0.14.04.1) starting as process 8448 ...
2015-11-26 12:18:24 8448 [Warning] One can only use the --user switch if running
as root
2015-11-26 12:18:24 8448 [Warning] Buffered warning: Changed limits:
max_open_files: 1024 (requested 5000)
2015-11-26 12:18:24 8448 [Warning] Buffered warning: Changed limits:
table_open_cache: 431 (requested 2000)
2015-11-26 12:18:24 8448 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
2015-11-26
12:18:24 8448 [ERROR] Can't open the mysql.plugin table. Please run
mysql_upgrade to create it.
2015-11-26 12:18:24 8448 [Note] InnoDB:
Using atomics to ref count buffer pool pages
2015-11-26 12:18:24 8448
[Note] InnoDB: The InnoDB memory heap is disabled
2015-11-26 12:18:24
8448 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-11-26 12:18:24 8448 [Note] InnoDB: Memory barrier is not used
2015-11-26 12:18:24 8448 [Note] InnoDB: Compressed tables use zlib
1.2.8
2015-11-26 12:18:24 8448 [Note] InnoDB: Using Linux native AIO
2015-11-26 12:18:24 8448 [Note] InnoDB: Using CPU crc32 instructions
2015-11-26 12:18:24 8448 [Note] InnoDB: Initializing buffer pool, size
= 128.0M
2015-11-26 12:18:24 8448 [Note] InnoDB: Completed initialization of buffer pool
2015-11-26 12:18:24 8448 [Note] InnoDB:
Highest supported file format is Barracuda.
2015-11-26 12:18:24 8448
[Note] InnoDB: Log scan progressed past the checkpoint lsn 49463
2015-11-26 12:18:24 8448 [Note] InnoDB: Database was not shutdown
normally!
2015-11-26 12:18:24 8448 [Note] InnoDB: Starting crash
recovery.
2015-11-26 12:18:24 8448 [Note] InnoDB: Reading tablespace
information from the .ibd files...
2015-11-26 12:18:24 8448 [Note]
InnoDB: Restoring possible half-written data pages
2015-11-26
12:18:24 8448 [Note] InnoDB: from the doublewrite buffer... InnoDB:
Doing recovery: scanned up to log sequence number 1600607
2015-11-26
12:18:24 8448 [Note] InnoDB: Starting an apply batch of log records to
the database... InnoDB: Progress in percent: 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
2015-11-26 12:18:24 8448 [Note] InnoDB:
128 rollback segment(s) are active.
2015-11-26 12:18:24 8448 [Note]
InnoDB: Waiting for purge to start
2015-11-26 12:18:24 8448 [Note]
InnoDB: 5.6.27 started; log sequence number 1600607
2015-11-26
12:18:24 8448 [Note] Server hostname (bind-address): '*'; port: 3308
2015-11-26 12:18:24 8448 [Note] IPv6 is available.
2015-11-26 12:18:24
8448 [Note] - '::' resolves to '::';
2015-11-26 12:18:24 8448 [Note]
Server socket created on IP: '::'.
2015-11-26 12:18:24 8448 [ERROR]
Fatal error: Can't open and lock privilege tables: Table 'mysql.user'
doesn't exist
仍然找不到如何在 ubuntu 14.04 和自定义配置下运行 mysql :(
另外,我似乎无法调用/usr/bin/mysql_install_db
命令来在新的 datadir 中设置数据库
例如
oleg: /usr/share/mysql$ /usr/bin/mysql_install_db --verbose
--defaults-file=/home/oleg/testing/etc/my.cnf --basedir=/usr/share/mysql --user=root
FATAL ERROR: Could not find my-default.cnf
If you compiled from source, you need to run 'make install' to copy
the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top level
of the extracted archive, or pass the --basedir option pointing to
that location.
oleg: /usr/share/mysql$
答案1
你可能安装了 Ubuntu repos 提供的 mysql 包。我建议你安装mysql-apt-config或者直接从下载 DEB 文件MySQL 下载站点。您将在那里找到最新的 5.6.28 版本,而不是 5.6.27 版本。
一旦您安装了 mysql-community-* 包,您将能够初始化 datadir 并能够在不同的 datadir 上启动 mysqld 的新实例。
sudo /usr/bin/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql
然后像这样启动 mysqld:
sudo /usr/sbin/mysqld --defaults-file=/etc/my.cnf --user=mysql
这是我的示例配置文件:
cat /etc/my.cnf
[mysqld]
basedir=/usr
datadir=/srv/data
pid-file=/srv/data/mysqld.pid
port=3308
socket=/srv/data/mysql.sock
并证明它正在使用所述数据目录:
mysql> select @@datadir;
+------------+
| @@datadir |
+------------+
| /srv/data/ |
+------------+
1 row in set (0.00 sec)
编辑:您的 mysql_install_db 错误可能与错误有关#70067。
如果您不想安装任何软件包,您可以快速创建此文件并mysql_install_db
再次运行。
cat /usr/share/mysql/my-default.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
只需确保使用--用户=mysql并不是--用户=root对于/usr/bin/mysql_install_db
或/usr/sbin/mysqld
答案2
问题在于配置。更换此
pid-file=/tmp/tmpWtpvgM/tmp/mysqld.pid
datadir=/tmp/tmpWtpvgM/var
port=3308
tmpdir=/tmp/tmpWtpvgM/tmp
socket=/tmp/tmpWtpvgM/tmp/mysql.soc
和
pid-file=/tmp/tmpWtpvgM/tmp/mysqld.pid
datadir=/tmp/tmpWtpvgM/var
port=3308
tmpdir=/tmp/tmpWtpvgM/tmp
socket=/tmp/tmpWtpvgM/tmp/mysql.sock
答案3
MySql 有其预编译位置来查找配置文件和数据。因此,如果您想自定义所有内容,最好的办法是从源代码自行编译 mysql。否则可能会很混乱。
根据您的自定义 my.cnf 文件,您的新 datadir 是datadir=/tmp/tmpWtpvgM/var
,我猜它是空的,这就是您收到此错误的原因。
您应该先尝试将 mysql 数据从其默认位置(/var/lib/mysql
)移动到您的自定义位置,然后尝试启动 mysql。
或者尝试像这样创建它:
mysql_install_db --user=mysql --basedir=/tmp/tmpWtpvgM --datadir=/tmp/tmpWtpvgM/var
检查并确保适当的目录权限。
检查您收到的警告:One can only use the --user switch if running as root
因此以用户身份运行命令root
。
以下是两篇非常相关的帖子:
https://stackoverflow.com/questions/4634163/changing-default-my-cnf-path-in-mysql https://stackoverflow.com/questions/1795176/how-to-change-mysql-data-directory