欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > MySQL配置my.ini文件

MySQL配置my.ini文件

2025/4/18 21:53:03 来源:https://blog.csdn.net/m0_74824170/article/details/144835411  浏览:    关键词:MySQL配置my.ini文件

my.ini文件中存储了数据库的文件地址,数据库数据存储地址以及登录密码等基础信息。在遇到忘记密码或者其他基础问题时,修改my.ini文件很方便。但是部分数据库版本默认不生成my.ini文件,需要自己进行配置。

1.停止数据库服务。在搜索框中输入cmd,选择以管理员身份打开。输入

sc delete mysql(注意,这里的mysql是你的数据库服务名称,不知道怎么看的win+R后输入services.msc回车,就能在名称那一列找到你的mysql名称)

回车

显示成功后在管理(win+R回车后输入services.msc,回车)里看一下,如果数据库在管理中仍然存在,右键选择停止。数据库在管理中消失。

2.新建my.ini配置文件

配置文件存放路径如下图

我的mysql目录下不允许生成新文件,所以我在别的地方新建my.ini,编辑好后直接复制到存放的目录下。

下列代码复制到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.
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_bin
init_connect=‘SET NAMES utf8mb4’
# 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 = 3306
# 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 = 16M
read_rnd_buffer_size = 16M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

其中basedir datadir是自己的数据库和数据库数据存放路径。路径记得删双引号

3. 删除data文件夹。有重要数据提前备份!

还是管理员身份打开cmd

mysqld --initialize-insecure --user=mysql

输入命令回车后系统会自动生成data文件夹

4.配置my.ini

mysqld --install “给自己的mysql命名” --defaults-file=“my.ini的路径”

建议不要把mysql的名字取得花里胡哨的,也别出现中文,最多就换两个大小写,加点数字区分版本号就行了。

5.重启mysql,自定密码

5.1管理员打开cmd,输入

net start mysql(这里的mysql是你刚才定义的数据库名称)

回车后会显示你的数据库启动成功

5.2输入

mysql -u root -p

显示输入密码不用管,直接回车就可以进入mysql

5.3输入

ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘自定义密码’;

注意:1.这是mysql8.0以上的语句,如果是8.0一下,要自己搜一下。

2.建议把密码记好,不然不记得密码了,重置又是一个坎

5.4输入

quit;

退出mysql

6.测试

打开一个普通的cmd,输入

mysql -uroot -p

回车后输入密码,显示进入mysql即为成功。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词