mysql启动失败(win7)

mysql启动失败(win7),第1张

一、无法访问系统资源

MySQL 不能访问启动需要的资源是造成而 MySQL 无法启动的一个常见原因,如:文件,端口等。由于 linux 中用于启动 mysqld 进程的 mysql 用户通常是不能登陆的,可以使用类似下面的命令检查文件的访问权限。

sudo -u mysql touch /var/lib/mysql/b

找出问题后,修改对应文件或目录的权限或属主后通常可以解决问题。但有时 mysql 用户有访问文件和目录的权限,但仍然会被拒绝访问,例如下面这个例子:

mysql>system sudo -u mysql touch /home/mysql/data/a

mysql>create table t1 (

id int primary key,n varchar(10

) data directory

ERROR 1030 (HY000): Got error 168 from storage engine

测试说明 mysql 用户有这个目录的访问权限,但创建文件还是失败,这种情况让很多人困惑,这个时候通常是 mysqld 进程的访问被 linux 的 selinux 或 apparmor 给阻止了,大家可以看到创建的表不是在 mysql 的默认目录下面,因此 selinux 或 apparmor 的 policy 里面没有包含这个目录的访问权限,此时只要对应的修改 policy 就行了,当然把 selinux 或 apparmor 停了也行。

有时虽然对系统资源有访问的权限,但系统资源已经被占用:

mysqld --no-defaults --console --user mysql

2020-11-03T03:36:07.519419Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 21171

2020-11-03T03:36:07.740347Z 1 [ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11

这个故障产生的原因是另外一个 mysqld 进程已经启动并占用了对应的文件。

二、参数设置错误

参数设置错误造成 MySQL 无法启动的原因也非常常见,此时先要检查 MySQL 启动时会调用的参数,下面的命令可以查询 MySQL 启动时调用参数文件的顺序:

$ mysqld --verbose --help | grep "Default options " -A 1

Default options are read from the following files in the given order:

/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

知道了 MySQL 参数文件的调用顺序,我们就可以检查对应的参数文件,找出其中的错误,如果觉得参数文件的可读性不强,可以使用下面的命令显示 mysqld 程序将要调用的参数:

$ mysqld --print-defaults

/usr/sbin/mysqld would have been started with the following arguments:

......

注意这个命令显示完参数后就退出,不会真正运行 mysqld。这个命令和 my_print_defaults mysqld 完全是等价的,只不过后者的显示方式是一行一个参数。

然后开始对可疑的参数进行调试,我个人喜欢加的参数和顺序如下:

1. 在 mysqld 后加上第一个参数 --no-defaults ,这个参数的作用是通知 mysqld 在启动的时候不要读任何参数文件;

2. 第二个参数是 --console,这个参数会把错误信息输出到屏幕上,这个参数带来的一个弊端是所有的信息都输出到屏幕上,让屏幕显得比较乱,但对于我们调试却是很方便的;

3. 第三个参数是 --log-error-verbosity=3,这个参数会显示详细的日志;

4. 然后再在后面加上有把握的参数,可以一次只加一个参数,然后启动 mysqld,采用排除法逐步找出错误的参数。

1、 MySQL Community Server 5.6.10

2、解压到d:\MySQL.(路径自己指定)

3、在d:\MySQL下新建my.ini配置文件,内容如下:

*****************配置文件开始*********************

# MySQL Server Instance Configuration File

#----------------------------------------------------------------------

# Generated by the MySQL Server Instance ConfigurationWizard

#

#

# Installation Instructions

#----------------------------------------------------------------------

#

#

# CLIENT SECTION

#----------------------------------------------------------------------

#

# The following options will be read by MySQL clientapplications.

# Note that only client applications shipped by MySQLare guaranteed

# to read this section. If you want your own MySQLclient program to

# honor these values, you need to specify it as anoption during the

# MySQL client library initialization.

#

[client]

port=3306

[mysql]

default-character-set=gbk

# 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 usuallyresolved relative to this.

basedir="d:\MySQL\"

#Path to the database root

datadir="d:\MySQL\Data"

[WinMySQLadmin]

Server="d:\MySQL\bin\mysqld.exe"

# The default character set that will be used when anew schema or table is

# created and no character set is defined

default-character-set=gbk

# The default storage engine that will be used whencreate 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 MySQLserver will

# allow. One of these connections will be reserved fora user with

# SUPER privileges to allow the administrator to logineven if the

# connection limit has been reached.

max_connections=100

# Query cache is used to cache SELECT results andlater return them

# without actual executing the same query once again.Having the query

# cache enabled may result in significant speedimprovements, if your

# have a lot of identical queries and rarely changingtables. See the

# "Qcache_lowmem_prunes" status variable tocheck if the current value

# is high enough for your load.

# Note: In case your tables change very often or ifyour queries are

# textually different every time, the query cache mayresult 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 mysqldrequires.

# Therefore you have to make sure to set the amount ofopen 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) temporarytables. If a table

# grows larger than this value, it is automaticallyconverted to disk

# based table This limitation is for a single table.There can be many

# of them.

tmp_table_size=26M

# How many threads we should keep in a cache forreuse. When a client

# disconnects, the client's threads are put in thecache if there aren't

# more than thread_cache_size threads frombefore. This greatly reduces

# the amount of thread creations needed if you have alot of new

# connections. (Normally this doesn't give a notableperformance

# improvement if you have a good threadimplementation.)

thread_cache_size=8

#*** MyISAM Specific options

# The maximum size of the temporary file MySQL isallowed to use while

# recreating the index (during REPAIR, ALTER TABLE orLOAD DATA INFILE.

# If the file-size would be bigger than this, theindex will be created

# through the key cache (which is slower).

myisam_max_sort_file_size=100G

# If the temporary file used for fast index creationwould be bigger

# than using the key cache by the amount specifiedhere, 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 tocreate the index.

myisam_sort_buffer_size=52M

# Size of the Key Buffer, used to cache index blocksfor 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 ifyou're not using

# MyISAM tables, you should still set it to 8-64M asit will also be

# used for internal temporary disk tables.

key_buffer_size=40M

# Size of the buffer used for doing full table scansof 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 rebuildthe index in

# REPAIR, OPTIMZE, ALTER table statements as well asin LOAD DATA INFILE

# into an empty table. It is allocated per thread sobe careful with

# large settings.

sort_buffer_size=256K

#*** INNODB Specific options ***

innodb_data_home_dir="d:\MySQL\Data\INNODB\"

# Use this option if you have a MySQL server withInnoDB support enabled

# but you do not plan to use it. This will save memoryand disk space

# and speed up some things.

#skip-innodb

# Additional memory pool that is used by InnoDB tostore 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 needto change this

# value. SHOW INNODB STATUS will display the currentamount used.

innodb_additional_mem_pool_size=2M

# If set to 1, InnoDB will flush (fsync) thetransaction logs to the

# disk at each commit, which offers full ACIDbehavior. If you are

# willing to compromise this safety, and you arerunning small

# transactions, you may set this to 0 or 2 to reduce diskI/O to the

# logs. Value 0 means that the log is only written tothe log file and

# the log file flushed to disk approximately once persecond. Value 2

# means the log is written to the log file at eachcommit, but the log

# file is only flushed to disk approximately once persecond.

innodb_flush_log_at_trx_commit=1

# The size of the buffer InnoDB uses for buffering logdata. As soon as

# it is full, InnoDB will have to flush it to disk. Asit is flushed

# once per second anyway, it does not make sense tohave it very large

# (even with long transactions).

innodb_log_buffer_size=1M

# InnoDB, unlike MyISAM, uses a buffer pool to cacheboth indexes and

# row data. The bigger you set this the less disk I/Ois needed to

# access data in tables. On a dedicated databaseserver you may set this

# parameter up to 80% of the machine physical memorysize. Do not set it

# too large, though, because competition of thephysical 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 perprocess, so do not

# set it too high.

innodb_buffer_pool_size=77M

# Size of each log file in a log group. You should setthe combined size

# of log files to about 25%-100% of your buffer poolsize to avoid

# unneeded buffer pool flush activity on log fileoverwrite. However,

# note that a larger logfile size will increase thetime needed for the

# recovery process.

innodb_log_file_size=39M

# Number of threads allowed inside the InnoDB kernel.The optimal value

# depends highly on the application, hardware as wellas the OS

# scheduler properties. A too high value may lead tothread thrashing.

innodb_thread_concurrency=8

*****************配置文件结束*********************

配置文件也放在了附件里,大家可以根据需要修改。

重点是以下配置,其中datadir的目录名称必须是data,并且好像必须是MySQL目录下的data.之前自己制定了其他目录,一直出现1067的错误。

#Path to installation directory. All paths are usuallyresolved relative to this.

basedir="d:\MySQL\"

#Path to the database root

datadir="d:\MySQL\Data"

4、在windows环境变量里加入以下内容(方便执行命令行命令)

新建MYSQL_HOME="d:\MySQL\"

在Path里加入%MYSQL_HOME%\bin

5、将mysql注册为windows系统服务。具体 *** 作是在命令行中执行以下命令:

mysqld install MySQL --defaults-file="d:\MySQL\my.ini"

移除服务为 mysqld remove

6、第5步成功后,在命令行启动mysql

c:>net start mysql

7、修改root的密码为62386997

方法一:

c:>mysql –uroot

mysql>showdatabases

mysql>use mysql

mysql>UPDATE user SET password=PASSWORD("62386997") WHEREuser='root'

mysql>FLUSH PRIVILEGES

mysql>QUIT

..

1、点击“开始——搜索”,输入“cmd”命令后按车,然后右键cmd选择以管理员身份运行。

2、在打开的管理员命令行中,可正常使用“net start /stop mysql”命令,此处的mysql服务名称是mysql56。

3、mysql服务就可正常的启动或关闭了。

电脑公司Win7系统mysql数据库服务的正确启动步骤就与大家分享到这里,有需要的用户可按照上述方法解决。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/6132523.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-15
下一篇 2023-03-15

发表评论

登录后才能评论

评论列表(0条)

保存