准备好软件

MySql的下载参考:(1137条消息) mysql下载与安装过程_weixin_40396510的博客-CSDN博客_mysql数据库下载安装
(1137条消息) 安装MySQL的常见问题_二木成林的博客-CSDN博客_sc不是内部或外部命令,也不是可运行的程序
解压要C盘(自定义,本人解压到C盘)

本人解压位置C:\MySQL\mysql-8.0.30-winx64
配置环境变量

然后在Path变量里添加路径:

安装MySQL服务以及初始化
打开cmd(管理员权限)输入:
参考指令
mysqld --initialize --console //初始化mysqld
mysqld -install //安装SQL后台服务程序(mysqld),mysqld用来实现让客户端通过连接服务器来访问数据库
net start mysql //启动MySQL
mysql -u root -p
alter user 'root'@'localhost' identified by 'smartmore@2022'; //修改密码为
commit;
quit;
#卸载
mysqld -remove MySQL //-u表示输入用户名,-p表示输入密码,按下回车后则会要求输入密码
//密码在初始化时有显示,下面截图展示
create database ai_adc default character set utf8 collate utf8_general_ci;
create user 'smartmore'@'localhost' identified by 'smartmore@2022'
create user 'smartmore'@'%' identified by 'smartmore@2022';
GRANT ALL ON *.* TO 'smartmore'@'localhost';
GRANT ALL ON *.* TO 'smartmore'@'%';

注意: 在执行 mysql -u root -p 时,忘记前面的初始密码,则需要卸载Mysql后重新安装,
卸载MySql的指令为:mysqld -remove MySQL ,但是有可能卸载失败,报错,

这是因为Mysql启动了或者没有卸载干净,解决办法

然后重新安装。
修改密码 alter user 'root'@'localhost' identified by 'smartmore@2022'; //修改密码

密码修改后需要提交生效,comit;

安装heidiSql客户端

打开heidiSql客户端,新建一个会话,然后配置如下

即可打开一个数据库

创建用户演示
下面是命令行打开数据库

----屏蔽上面的操作---


点击打开

注意:上面有个错误:
Access denied; you need (at least one of) the RELOAD privilege(s) for this operation
reload 是 administrative 级的权限,即 server administration;这类权限包括:
CREATE USER, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHOW DATABASES, SHUTDOWN, SUPER
解决办法:
GRANT ALL ON *.* TO 'smartmore'@'localhost';

然后打开heidiSql客户端:

无报错。