mysql8 的安装先比较之前的版本复杂了一些,下面就一步一步安装。
到 mysql官网 下载最新版本的mysql 下载完成后解压,并新建my.ini文件
my.ini文件内容:
[mysqld] # 设置3306端口 port=3306 # 设置mysql的安装目录 basedir=C:\Program Files\mysql-8.0.20-winx64 # 设置mysql数据库的数据的存放目录 datadir=C:\Program Files\mysql-8.0.20-winx64\Data # 允许最大连接数 max_connections=200 # 允许连接失败的次数。 max_connect_errors=10 # 服务端使用的字符集默认为utf8mb4 character-set-server=utf8mb4 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB # 默认使用“mysql_native_password”插件认证 #mysql_native_password default_authentication_plugin=mysql_native_password [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8mb4 [client] # 设置mysql客户端连接服务端时默认使用的端口 port=3306 default-character-set=utf8mb4环境变量中配置MySQL的bin的地址:
以管理员权限运行CMD:
输入mysqld --initialize --console 注意,这里的root@localhost: wD3l-a.r=2yP时用户名和密码,先记录下来。
先用刚从的初始密码登陆,然后用alter user 'root'@'localhost' identified by '123456';命令修改密码。
C:\Program Files\mysql-8.0.20-winx64\bin>mysql -uroot -pwD3l-a.r=2yP mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.20 Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> alter user 'root'@'localhost' identified by '123456'; Query OK, 0 rows affected (0.01 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)注意:
我们安装的时mysql8 版本,update mysql.user set password='newpassword' where user='root'; 和update mysql.user set password=PASSWORD('newpassword') where User='root';这两条命令已经失效。flush privileges;刷新命令不可以省略哦