安装mysql

安装Mysql

下载mysql

官网地址:https://www.mysql.com/
安装mysql
安装mysql
安装mysql
安装mysql

下载 完成后,解压缩下载包即可使用,但需配置环境变量(到bin目录)

安装mysql

配置完成后,如果下载的mysql目录没有my-default.ini文件,则可自己建立一个my.ini文件,将如下内容复制进去,并根据自己情况修改basedir和datadir

注意:my.ini文件的编码必须是英文编码(如windows中的ANSI),不能是UTF-8或GBK等。

# 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=D:\JavaStudy\software\mysql-8.0.24-winx64

datadir=D:\\JavaStudy\\software\\mysql-8.0.24-winx64\\data

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

以管理员身份进入cmd,并切换到安装的mysql的bin目录下

安装mysql

执行mysql -install命令,安装mysql服务

如果安装错了,可执行sc delete mysql删除mysql重新 安装

安装完成之后不要立马启动mysql服务

在mysql5.7以上版本中默认没有一个data目录,即没有初始化服务。需要先初始化mysql才可以启动服务,否则会报 “服务没有报告任何错误”,启动失败呗。
正确的步骤是:先在mysql的bin目录下执行mysqld --initialize (不设置root密码,建议使用)命令,第一次执行这个命令会等待的时间稍微长了一些,并且控制台没有任何返回结果。可以看到mysql的根目录下会多出一个data文件夹,里面一堆文件。

如果你的datadir路径中有\s会报错

安装MySQL的时候,当我们用命令mysqld --initialize --console进行初始化时,会出现mysqld: Can’t create directory ‘D:\Devsoft\mysql-8.0.20-winx64\bin\ oftWare\MySQL\data’ (OS errno 2 - No such file or directory)

解决方法
可以更改文件夹的名称,但是不建议,因为"“和其它字符在一起也有可能有特定含义,所有,我们直接用\,从而直接转义”"含义。

执行net start mysql启动mysql(net stop mysql关闭mysql)

上一篇:php artisan migrate时出现 SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was to


下一篇:修改字符集为utf8mb4;阿里的记录信息