windows 安装mysql
一、确认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
# 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、管理员运行cmd,进入bin目录
2、生成初始化密码
mysqld --initialize --console
3、执行第二条命令,安装mysql服务
mysqld --install mysql
4、启动mysql服务
五、修改root 密码
1.在MySQL安装目录下的bin目录下,启动cmd,进入命令提示符后执行以下命令
2.修改root密码为:123456
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
3. 创建新的管理员账号
create user 'admin'@'localhost' identified by 'admin';
4. 授权管理员账号
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost'; FLUSH PRIVILEGES;
5. 使用管理员账号登录