windows 安装mysql 和不能通过ip访问到数据库

 

一、确认windows 是否已经安装mysql

1.按【Win+R】打开运行

2.输入【services.msc】打开服务

3、在服务列表中查找MySQL,如果有mysql服务则表示Windows已经安装MySQL,如果没有MySQL服务则表示Windows没有安装MySQL

二、下载MySQL 安装包

1、mysql 官网下载地址   https://dev.mysql.com/downloads/mysql/

 2.选择 No thanks, just start my download.

三.添加配置文件

1.将下载的zip包,解压到想要安装的目录下

 2.进入解压后的目录,在bin同等级目录下新建my.ini

3.编辑my.ini,将以下配置粘贴到my.ini

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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.
# 设置mysql的安装目录
# basedir = D:/mysql-8.0.33-winx64/mysql-8.0.33-winx64
basedir = C:/software/mysql-8.1.0-winx64
# 设置mysql数据库的数据的存放目录
# datadir = D:/mysql-8.0.33-winx64/mysql-8.0.33-winx64/data
datadir = C:/software/mysql-8.1.0-winx64/data
# 设置3306端口
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 = 2M
# read_rnd_buffer_size = 2M
  
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  
# 允许最大连接数
max_connections = 200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors = 10
# 服务端使用的字符集默认为UTF8
character-set-server = utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine = INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin = mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set = utf8mb4
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
default-character-set = utf8mb4
 
 
[mysqld]
skip-grant-tables

 4.编辑my.ini,修改basedir   和 datadir

 四 、安装MySQL

注意说明:如果已安装,卸载掉之前老版本,命令:1、mysqld -nt-remove 移除  

1、管理员运行cmd,进入bin目录

2、生成初始化密码

1
mysqld --initialize --console

 3、执行第二条命令,安装mysql服务

1
mysqld --install mysql

4、启动mysql服务  命令启动:net start mysql

 五、修改root 密码

1.在MySQL安装目录下的bin目录下,启动cmd,进入命令提示符后执行以下命令

 2.修改root密码为:123456

1
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

 3. 创建新的管理员账号

1
create user 'admin'@'localhost' identified by 'admin';

4. 授权管理员账号

1
2
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost';
FLUSH PRIVILEGES;

5. 使用管理员账号登录

 

二、常见问题(不能通过ip连接到数据库)

解决办法:1修改访问权限即可。
打开cmd,进入mysql

 

 

 

 

posted @ 2023-12-07 17:11  ...翰  阅读(305)  评论(0编辑  收藏  举报