mysql常见问题处理办法

作者: 傻猫    分类: 弄数据    发布时间: 06-21 13:55    浏览次数: 9306     2 条留言

今天感觉,几年前装载硬盘上的mysql4.0仿佛有些落伍了,网上查找到的很多mysql命令和配置参数,在偶的4.0老爷车上都不起作用,于是决定喜新厌旧,升级成mysql 5.0来用。可这个升级过程颇为艰难,遇到了无数的问题,一一解决之,最后终于祖国江山一片大好。

首先,用mysql5.0的安装包setup.exe顺利安装,安装完后即弹出精美的配置界面(旧版本里面没有这个界面,说明还是进步了很多mysql),配置这个还是小意思,一路配完,在这里竟然启动不了服务,就出现这个:

cannot create windows service for MySQL。Error:0

 

苦恼啊,是什么问题呢?查找了一下,可能是由于旧版本的mysql的windows服务没有停掉的缘故。
我的解决办法如下:

1、首先停止旧版本的mysql服务。(停止后仍无法启动)
2、从命名mysql5.0的windows服务名为 mysql5.0 。 (还是没有办法启动)
3、删除原来的旧版本的mysql服务名。可以通过如下命令删除:

    C:>sc delete mysql
   [SC] DeleteService SUCCESS

     说明:sc命令在我的windows2000是没有,看你到网上说可以用delsrv来代替,需要到这个网址下载delsrv http://download.microsoft.com/download/win2000platform/webpacks/1.00.0.1/nt5/en-us/delsrv.exe

也可以通过mysql 4.0 bin目录下面的winmysqladmin.exe的相关功能来删除原来的mysql服务。操作界面如下:

 

remove服务之前

 

remove服务之后


4、做了如上操作后重新安装mysql5.0,还是一样的显示:cannot create windows service for MySQL。Error:0。
5、又看有人的问题是这样:在 注册表 Local_machine--system--surrentcontrolSet--Services找到旧的MySQL服务,把ImagePath改成新的就行了。看了一下我的机器上这个路径是没有问题的。
6、还有人的问题是发生在my。ini这个配置文件上。首先确认c:/winnt/my.ini这个配置情况(旧版本的需要放在winnt下面),和安装目录下面的my.ini配置文件(5.0好像直接放在安装目录下面),启动到底用到的那个文件。文件里面的配置是否正确。这一点很重要,一般无法启动就是配置文件不对。
7、查看响应的3306端口是否被占用,是否有防火墙软件阻止启用3306端口。

查了以上几个方面,其实大多数人的mysql启动问题就应该解决了,可我的问题不在这里。还要继续,我在windows服务管理界面直接启动mysql这个服务项,得到信息如下:

在 本地计算机 无法启动mysql服务 错误1067:进程意外中止

对错误1067的解决办法,查找如下:

1、修改%windir%\my.ini,增加
[mysqld]
#设置basedir指向mysql的安装路径
basedir=D:\Program\Tools\mysql
datadir=D:\Program\Tools\mysql\data

windows提示的错误1067并没有太多可参考价值。对解决mysql的启动问题帮助不大。

搞了许久,一个启动问题还没有搞定。最重要的转机出现在发现E:\MySQL\data\目录下的hostname.err文件。这里面详细写明无法启动的原因:

[ERROR] Default storage engine (InnoDB) is not available

这个就是为什么我的mysql无法启动的直接原因,解决办法:

1、打开my.ini或my.cnf文件,找到default-storage-engine=InnoDB这一行,把它改成default-storage-engine=MyISAM。

2、另外一个解决办法:

在windows2003安装MySQL后,如果发现service起不来
1。检查windows的日志
2。错误信息是“Default storage engine (InnoDB) is not available”

解决方法:
1。删除在MySQL安装目录下的Data目录中的
ib_logfile0
ib_logfile1
2。找到在配置MySQL服务器时指定的InfoDB目录删除掉
ibdata1
3。重新启动MySQL的Service
  

3、这个问题第二天又摸索了一下,其实是可以用InnoDB引擎的。

需要在mysql生成的配置文件增加一行配置,即增加一个临时目录,这个在启动mysql服务的时候是需要的。

[mysqld]
tmpdir=e:/111

我的my。ini配置文件如下,注意红色字体,是默认不会生成的:

# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
#
#
# Installation Instructions
# ----------------------------------------------------------------------
#
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (@localstatedir@ for this installation) or to
# ~/.my.cnf to set user-specific options.
#
# On Windows you should keep this file in the installation directory
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option
# "--defaults-file".
#
# To run run the server from the command line, execute this in a
# command line shell, e.g.
# mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# To install the server as a Windows service manually, execute this in a
# command line shell, e.g.
# mysqld --install MySQLXY --defaults-file="C:\Program Files\MySQL\MySQL Server X.Y\my.ini"
#
# And then execute this in a command line shell to start the server, e.g.
# net start MySQLXY
#
#
# Guildlines for editing this file
# ----------------------------------------------------------------------
#
# In this file, you can use all long options that the program supports.
# If you want to know the options a program supports, start the program
# with the "--help" option.
#
# More detailed information about the individual options can also be
# found in the manual.
#
#
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]

port=3306

[mysql]

default-character-set=latin1


# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306


#Path to installation directory. All paths are usually resolved relative to this.
basedir="E:/MySQL/"

#Path to the database root
datadir="E:/MySQL/Data/"
#mysql的安装程序真的弱智,自己不生成这个参数导致启动无法成功。这也太白痴的错误啊。
tmpdir=e:/111

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=latin1

# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB

# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=100

# Query cache is used to cache SELECT results and later return them
# without actual executing the same query once again. Having the query
# cache enabled may result in significant speed improvements, if your
# have a lot of identical queries and rarely changing tables. See the
# "Qcache_lowmem_prunes" status variable to check if the current value
# is high enough for your load.
# Note: In case your tables change very often or if your queries are
# textually different every time, the query cache may result in a
# slowdown instead of a performance improvement.
query_cache_size=0

# The number of open tables for all threads. Increasing this value
# increases the number of file descriptors that mysqld requires.
# Therefore you have to make sure to set the amount of open files
# allowed to at least 4096 in the variable "open-files-limit" in
# section [mysqld_safe]
table_cache=256

# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
tmp_table_size=9M


# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client's threads are put in the cache if there aren't
# more than thread_cache_size threads from before. This greatly reduces
# the amount of thread creations needed if you have a lot of new
# connections. (Normally this doesn't give a notable performance
# improvement if you have a good thread implementation.)
thread_cache_size=8

#*** MyISAM Specific options

# The maximum size of the temporary file MySQL is allowed to use while
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
# If the file-size would be bigger than this, the index will be created
# through the key cache (which is slower).
myisam_max_sort_file_size=100G

# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method. This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_max_extra_sort_file_size=100G

# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method. This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_sort_buffer_size=18M

# Size of the Key Buffer, used to cache index blocks for MyISAM tables.
# Do not set it larger than 30% of your available memory, as some memory
# is also required by the OS to cache rows. Even if you're not using
# MyISAM tables, you should still set it to 8-64M as it will also be
# used for internal temporary disk tables.
key_buffer_size=11M

# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=64K
read_rnd_buffer_size=256K

# This buffer is allocated when MySQL needs to rebuild the index in
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE
# into an empty table. It is allocated per thread so be careful with
# large settings.
sort_buffer_size=256K


#*** INNODB Specific options ***


# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb

# Additional memory pool that is used by InnoDB to store metadata
# information. If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS. As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
innodb_additional_mem_pool_size=2M

# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1

# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=1M

# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system. Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=18M

# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=10M

# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=8

我的启动log日志文件:

070622 11:32:44 InnoDB: Error: unable to create temporary file; errno: 22
070622 11:32:44 [ERROR] Default storage engine (InnoDB) is not available
070622 11:32:44 [ERROR] Aborting

070622 11:32:44 [Note] E:\MySQL\bin\mysqld-nt: Shutdown complete

说明:增加tmpdir之前,服务启动失败的输出。

InnoDB: The first specified data file .\ibdata1 did not exist:
InnoDB: a new database to be created!
070622 11:36:27 InnoDB: Setting file .\ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
070622 11:36:27 InnoDB: Log file .\ib_logfile0 did not exist: new to be created
InnoDB: Setting log file .\ib_logfile0 size to 10 MB
InnoDB: Database physically writes the file full: wait...
070622 11:36:28 InnoDB: Log file .\ib_logfile1 did not exist: new to be created
InnoDB: Setting log file .\ib_logfile1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
070622 11:36:29 InnoDB: Started; log sequence number 0 0
070622 11:36:29 [Note] E:\MySQL\bin\mysqld-nt: ready for connections.
Version: '5.0.41-community-nt' socket: '' port: 3306 MySQL Community Edition (GPL)

说明:只是增加了一个简单tmpdir参数,启动就ok了。看了一下tmp目录,会生成几个文件,这几个文件就是导致无法启动的罪魁祸首。

通过以上几个问题修改后,启动mysql一切OK了。

总结:

1、说到底,mysql的无法启动问题,绝大多数是因为my.ini配置文件造成的。当然端口已经被占用,或者防火墙问题,也是极易出现的情况。
2、一定去看mysql的*.err错误文件,这里面的错误信息,是最直接的错误,指出真正的问题所在。

 

感想:

1、mysql的这个错误原因其实是安装程序自己造成的,我认为是mysql败笔,是他的失败。

2、不要用setup。exe的安装包,不是很好用。用绿色的非安装版本比较好一点。

已有 2 条评论 »

  1. Ev1n

    一些真正有趣的細節,你有written.Aided了我很多,正是我正在尋找:D。

  2. Ev1n

    方法都用了,但还是不行,不知道哪里出问题了

添加新评论