分类: MySQL
Win11快速部署MySQL Community Server 8.0.33

1、先在MySQL官方下载安装包:

--MySQL官方下载地址:
https://dev.mysql.com/downloads/mysql/
--直接下载地址:
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.33-winx64.zip

2、解压并设置环境变量: 将mysql-8.0.33-winx64.zip解压到C盘根目录下,解压完成后会有C:\mysql-8.0.33-winx64目录。 添加环境变量: 电脑->右键 属性->高级系统设置->环境变量->系统变量->PATH,在PATH里添加入mysql安装路径下的bin的路径—例如我的是:

C:\mysql8033\bin\

3、创建my.cnf配置文件:

--在C:\mysql8033目录下创建my.cnf文件,内容如下:
[mysql]
default-character-set=utf8mb4

[mysqld]
port=3306
basedir=C:/mysql8033
datadir=C:/mysql8033/data
max_connections=200
max_connect_errors=100     
character-set-server=utf8mb4
default-storage-engine=INNODB
authentication_policy =mysql_native_password
bind-address = 0.0.0.0
log-bin = C:/mysql8033/binlog/binlog
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
binlog_format = ROW
server_id = 1
tmp_table_size = 64M
table_open_cache = 2000
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
join_buffer_size = 2M
sort_buffer_size = 2M
read_buffer_size = 1M
thread_cache_size = 10
#skip-name-resolve = ON
expire_logs_days = 7
log-error = C:/mysql8033/error.log 

character-set-client-handshake = FALSE
#collation-server = utf8mb4_unicode_ci #不区分大小写
collation-server = utf8mb4_bin
lower_case_table_names = 1

character-set-server=utf8mb4
init_connect='SET NAMES utf8mb4'

slow_query_log = 1
long_query_time = 3
slow_query_log_file = C:/mysql8033/slow.log

[client]
port=3306
default-character-set=utf8mb4

[mysqldump]
column-statistics=0

4、创建data目录、安装服务及初始化:

--在C:\mysql8033下创建data和binlog目录
--以管理员账号运行CMD,执行初始化引导:
PS C:\Users\ice> mysqld --initialize --console
2022-10-12T04:26:16.382015Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2022-10-12T04:26:16.382036Z 0 [System] [MY-013169] [Server] C:\mysql-8.0.31-winx64\bin\mysqld.exe (mysqld 8.0.31) initializing of server in progress as process 9528
2022-10-12T04:26:16.404446Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-10-12T04:26:16.641875Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-10-12T04:26:17.411693Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ,KOtD%adf2zD

--此处会显示mysql的初始密码如上所示。

--安装服务(需要以管理员权限运行CMD):
C:\Windows\System32> mysqld --install mysqld
Service successfully installed.

--启动服务:
C:\Windows\System32>net start mysqld
mysqld 服务正在启动 .
mysqld 服务已经启动成功。

5、修改默认密码:

mysql -uroot -p
--输入密码即可登录
--修改密码:
ALTER USER root@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUPASSWORD';
flush privileges;

6、进行初始化设置:

--在cmd命令行中运行
mysql_secure_installation
--回车后根据提示设置,最后重启mysql服务
C:\Windows\System32>net stop mysqld
mysqld 服务正在停止..
mysqld 服务已成功停止。

C:\Windows\System32>net start mysqld
mysqld 服务正在启动 .
mysqld 服务无法启动。
至此MySQL8.0.33已部署完成,可以根据实际需求配置修改my.cnf文件。

mysql8.png


相关博文:

发表新评论