Windows:
1.下载:https://dev.mysql.com/downloads/mysql/
推荐使用镜像:http://mirrors.sohu.com/mysql/MySQL-8.0/
2.下载完成之后, 解压到目录下,例如:D:mysql-8.0.22-winx64
3. 设置环境变量
变量名称:MYSQL_HOME
变量值:D:mysql-8.0.22-winx64
4. 生成data目录
注意: 以管理员身份运行cmd
进入到bin目录下D:mysql-8.0.22-winx64in
执行命令:
mysqld --initialize-insecure --user=mysql
则会在bin目录的同级生成data目录
5. 安装MySQL
mysqld -install
6. 启动服务
net start MySQL
7. 登录MySQL
mysql -u root -p //默认没有设置密码, 直接回车即可
8)查询用户密码
select host,user,authentication_string from mysql.user
9)密码修改
use mysql; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
flush privileges;
10)再次登录
11)mysql配置
默认mysql8.0是data目录中是不存在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. [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:mysql-8.0.22-winx64 datadir = D:mysql-8.0.22-winx64data 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
设置完成之后, 可以设置mysql默认的配置文件
mysqld --defaults-file="D:mysql-8.0.22-winx64datamy.ini"
然后重启服务即可, 如果你在开始安装的时候已经创建了配置文件,可以在安装的时候直接指定即可
mysqld --install "MySql80" --defaults-file="C:installmysqlmysql-8.0.16-winx64my.ini"
其他相关命令:
1. 停止MySQL服务
net stop mysql