背景:因为电脑需要安装多个版本的MySQL,碰到了一系列问题,记录一下
问题:原本有个MySQL5.7,需要安装8.0版本的,但是服务起不来,打印日志没有报错
发现初始化数据库时,没有生成data目录,使用-console打印控制台,报错5.7版本的data目录已经存在
1. 这时候知道虽然我进入的是8.0版本的目录使用的命令,但是系统先检查环境变量MYSQL_HOME设置的5.7版本的命令,删掉环境变量后再次初始化数据库发现成功了,但是服务还是起不来。
2. 检查配置文件内容并且-console命令打印发现不是配置文件内容的问题。
(1)这里附上MySQL8.0.36版本的my.ini文件
[mysqld]
# 设置3307端口
port=3307
# 设置mysql的安装目录 ----------是你的文件路径-------------
basedir= "D:\Environment\MySql\mysql-8.0.36-winx64"
# 设置mysql数据库的数据的存放目录 ---------是你的文件路径data文件夹自行创建
datadir= "D:\Environment\MySql\mysql-8.0.36-winx64\Data"
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
#mysql_native_password
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3307
default-character-set=utf8mb4
(2)MySQL5.7版本的my.ini文件
# 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 = "D:/Environment/MySql/mysql-5.7.37-winx64"
datadir = "D:/Environment/MySql/mysql-5.7.37-winx64/data"
port = 3306
character_set_server = utf8
# server_id = .....
# 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
- 最后应该就是配置文件路径问题了,就到注册表的计算机
\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\mysql8
内的imagePath后面追加指定配置文件路径
--defaults-file="D:\Environment\MySql\mysql-8.0.36-winx64\my.ini"
再次net start mysql8,启动成功!
总结
安装MySQL时,发现服务启动不了,有3个点需要注意
- 环境变量MYSQL_HOME需要删掉,否则安装其他版本时,会优先搜索环境变量的版本命令,比如MYSQL_HOME,好奇的是我没有把他放进path里也生效了;
- 配置文件内容需要注意一下,可以使用-console打印出来;
- 初始化数据库后服务还是启动不了,应该是配置文件路径的问题,进注册表ImagePath检查;