mysql_install_db出错,Unable to lock /usr/local/mysql/var/ibdata1, error: 11

时间:2021-11-11 21:57:26
今天,在一台旧机器上编译一个新的Mysql,install时出了错:
/usr/local/mysql_5615/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql_5615/ --datadir=/mnt/disk1/mysql_5615/ 

Installing MySQL system tables...-- ::  [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
-- :: 7fb9ca4d06f0 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option innodb_use_sys_malloc and with the InnoDB's internal memory allocator.
-- :: 7fb9ca4d06f0 InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!
-- :: [Note] InnoDB: The InnoDB memory heap is disabled
-- :: [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
-- :: [Note] InnoDB: Compressed tables use zlib 1.2.
-- :: [Note] InnoDB: Using CPU crc32 instructions
-- :: [Note] InnoDB: Initializing buffer pool, size = 16.0M
-- :: [Note] InnoDB: Completed initialization of buffer pool
-- :: [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error:
-- :: [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
-- :: [Note] InnoDB: Retrying to lock the first data file
-- :: [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error:
-- :: [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files. 循环打印此错N次…… -- :: [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error:
-- :: [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
-- :: [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error:
-- :: [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
2014-01-20 17:01:02 30853 [ERROR] InnoDB: Unable to lock /usr/local/mysql/var/ibdata1, error: 11
2014-01-20 17:01:02 30853 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
-- :: [Note] InnoDB: Unable to open the first data file
-- :: 7fb9ca4d06f0 InnoDB: Operating system error number in a file operation.
InnoDB: Error number means 'Resource temporarily unavailable'.
InnoDB: Some operating system error numbers are described at
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html
-- :: [ERROR] InnoDB: Can't open '/usr/local/mysql/var/ibdata1'
-- :: [ERROR] InnoDB: Could not open or create the system tablespace. If you tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote those files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain your precious data!
-- :: [ERROR] Plugin 'InnoDB' init function returned error.
-- :: [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
-- :: [ERROR] Unknown/unsupported storage engine: InnoDB
-- :: [ERROR] Aborting

它试图去lock /usr/local/mysql/var/ibdata1,这并不是我想要的行为。我指定的basedir=/usr/local/mysql_5615,datadir=/mnt/disk1/mysql_5615,想来想去也不明白。可是怎么找到/usr/local/mysql/var/ibdata1来的呢?我查了查,服务器上的确有一个mysqld已经在跑了,而且用的就是这个数据文件。我的正确解决办法总不能是把人家的干掉啊。读了读mysql_install_db脚本,有些难懂,一下子也理解不出它为什么指定了这个目录。后来想到它应该是找到了某些我不想要的my.cnf文件。

于是查查:
/usr/local/mysql_5615/bin/mysqld --verbose --help | grep -A  'Default options'
-- :: [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root! Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /mnt/disk1/mysql_5615/my.cnf ~/.my.cnf
-- :: [ERROR] Aborting -- :: [Note] Binlog end
再ls一下这四个my.cnf,果然发现/etc/my.cnf是存在的。看看内容,正是正在运行的那个mysqld用的。把它暂时改名,再来mysql_install_db ,成功了。
 
回头要细读一下mysql_install_db 脚本了。

另:我还是喜欢什么东西都清清楚楚的。my.cnf还是喜欢放在自己的默认位置,这种用系统默认目录的,总是不喜欢。不过服务器也不是我的,不理了……