社区版下载地址
MySQL :: Download MySQL Community Server
解压并且在程序根目录新建my.ini文件,文件内容如下:路径根据情况自己改下。
注意:路径中的使用/不要使用\。
[client]
default-character-set=UTF8MB4
[mysqld]
#设置3306端口
port=3306
#设置mysql的安装目录
basedir=C:/mysql-8.0.31-winx64
#设置mysql数据库的数据的存放目录
datadir=C:/mysql-8.0.31-winx64/data
#允许最大连接数
max_connections=200
#服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=UTF8MB4
collation-server=UTF8MB4_general_ci
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
tmpdir=C:/mysql-8.0.31-winx64/tmp
需要注意
第一、mysql5.7的字符集utf8在这里不能使用了,用的话会提示建议将UTF8MB3改为UTF8MB4。
第二 、比较mysql5.7增加配置tmpdir=c:/my/mysql-8.0.29-winx64/tmp,不加这个配置会出现一堆不相关的错误。
其他没什么变化。
使用管理员权限打开cmd,进入mysql目录,初始化数据库执行
官网文档地址MySQL :: MySQL 8.0 Reference Manual :: 2.10.1 Initializing the Data Directory
bin\mysqld --initialize --console 或者 bin\mysqld --initialize-insecure --console
会看到红框框里面的随机密码,别弄丢了。
在执行bin\mysqld install
在执行 net start mysql
登录后必须修改密码,用这个修改密码:
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY '新密码';
C:\my\mysql-8.0.29-winx64\bin>mysql -uroot -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.29
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY '123';
完活。