mysql:无法在Ubuntu上正常启动

我有以下问题。 当MySQL作为服务启动时,所有工作正常:例如

oleg: ~$ sudo service mysql start mysql start/running, process 9111 oleg: ~$ 

但是,当我通过命令行开始没有任何工作。 configuration本身在下面的path中看起来不正确:

 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 

仍然无法find如何在ubuntu 14.04下运行mysql和自定义configuration:(

另外,我似乎无法调用/usr/bin/mysql_install_db命令,以便在新数据库中设置数据库

例如

 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$ 

你可能已经安装了Ubuntu软件库提供的mysql软件包。 我build议你安装mysql-apt-config或直接从MySQL下载站点下载DEB文件。 你会发现最新的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 

这是我的示例configuration文件:

 cat /etc/my.cnf [mysqld] basedir=/usr datadir=/srv/data pid-file=/srv/data/mysqld.pid port=3308 socket=/srv/data/mysql.sock 

并且要certificate它使用了这个数据元:

 mysql> select @@datadir; +------------+ | @@datadir | +------------+ | /srv/data/ | +------------+ 1 row in set (0.00 sec) 

编辑:您的mysql_install_db错误可能与错误#7006​​7有关 。

快速解决方法如果您不想安装任何软件包,您可以创build此文件并再次运行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 

只要确保对/usr/bin/mysql_install_db/usr/sbin/mysqld使用–user = mysql而不是–user = root

问题在于configuration。 replace这个

 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 

MySql有预编译的位置来查找configuration文件和数据。 所以你最好的select是如果你想自定义所有的东西,从源码编译mysql。 否则它可能是凌乱的。

根据你的自定义my.cnf文件,你的新datadir是datadir=/tmp/tmpWtpvgM/var ,我想这是空的,这就是为什么你得到这个错误。

要么你应该尝试将你的MySQL数据从它的默认位置( /var/lib/mysql )移动到你的自定义位置,然后尝试启动mysql。

或者尝试像这样创build它:

 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