mysql社区版安装包版windows安装包下载地址
在系统环境变量path无点.的情况下
- powershell可以- .\或- ./开头表示当前文件夹
- cmd可以直接命令或- .\开头, 不能- ./开头
 所以- .\在cmd和powershell中通用
步骤
- 在解压目录 .\mysqld --initialize-insecureroot无密码初始化
- .\mysqld install安装服务
- net start mysql启动MySQL服务
- .\mysql -uroot登录
- CREATE USER IF NOT EXISTS 'remote'@'%' IDENTIFIED BY 'remote'; GRANT ALL ON *.* TO 'remote'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;创建远程用户
- net stop mysql停止服务
- .\mysqld remove移除服务
- 拷贝整个解压安装目录到另一个文件夹, 或者换个电脑, 实现数据迁移 , 同版本同配置可只拷贝data文件夹
- .\mysqld install安装服务
- .\net start mysql启动MySQL服务
win11安装mysql8.3.0压缩包版 240206
- 解压安装初始化启动服务
- 查看服务状态
- 停止服务,移除服务,卸载
- 停止服务
- 查看服务状态
- 卸载服务
 
 
- 登录
- 创建远程用户
- 创建remote用户的语句模板
- 创建远程root的语句模板
 
 
 
 
mysql社区版安装包版windows安装包下载地址
解压安装初始化启动服务
-  解压到自定义安装目录 
-  以管理员身份运行powershell或cmd进入安装目录 
 powershell在环境变量无点.时不会执行本目录命令
 要加.\命令或./命令
 cmd在环境变量无点.时也可直接执行本目录的程序
 cmd切换其它盘用cd /d
-  执行 mysqld --initialize-insecure --console无密码安装
 环境变量无点.,也没有添加安装目录到系统环境变量path时的powershell要特别指明命令在当前目录,用.\或./
 正反斜杆都可以
.\mysqld --initialize-insecure --console
或
./mysqld --initialize-insecure --console
或
.\mysqld.exe --initialize-insecure --console
或
./mysqld.exe --initialize-insecure --console
cmd运行默认会在当前目录查找,不需要环境变量path带点.
mysqld.exe --initialize-insecure --console
注意: 初始化时,安装文件夹不能有data文件夹, 初始化后会生成data文件夹
- 以管理身份运行mysqld --install安装MySql服务
--install 的两横可以省略, 可以写成 -install 或 install
mysqld install
mysqld -install
mysqld --install
执行 mysqld --install 必须要管理员权限 ! ,
可以给服务取名 ,默认的服务名为 mysql
mysqld install 等效 mysqld install mysql
比如可以自定义服务名称为 MysqlServiceName2 👇
mysqld install MysqlServiceName2
查看mysql和mysqld命令帮助的命令
.\mysql --verbose --help
.\mysqld --verbose --help
- 启动mysql服务
启动MySQL服务的几种方法
 Windows可以用 net start 服务名 或 sc start 服务名 或 sc.exe start 服务名 来启动服务
net start mysql
net start install时自定义的名称
或
sc.exe start mysql
sc.exe start "mysql"
sc.exe start install时自定义的名称
sc.exe start "有空格 的名称要加引号"
sc 在cmd中可以写成sc或sc.exe
 sc 在powershell中会判定为Set-Content 命令,所以,
 sc 在powershell中要写成sc.exe
sc.exe start mysql
Start-Service mysql
Start-Service -Name "mysql"
mysql是MySQL默认的服务名, 可以在执行 mysqld --install 服务名 时指定,
 省略服务名mysqld --install , 相当于 mysqld --install mysql
 net start mysql 或 sc start mysql 启动MySQL服务
对应的,停止MySQL服务的几种方法
net stop mysql
sc.exe stop mysql
Stop-Service mysql
Stop-Service -Name mysql
查看服务状态
sc query 服务名 查看服务
sc.exe query mysql
get-service mysql
get-service -Name mysql
停止服务,移除服务,卸载
停止服务
net stop mysql
sc.exe stop mysql
Stop-Service -Name mysql
查看服务状态
sc.exe query mysql
get-service -name mysql
卸载服务
卸载,删除,移除MySQL服务可以用 mysqld --remove MySQL服务名 或 sc delete 服务名
- mysqld --remove MySQL服务名
- sc.exe delete 服务名
mysqld是MySQL提供的命令 , sc是Windows提供的命令
mysqld --remove MySQL服务名 移除MySQL服务, 如果不指定服务名, 则服务名=mysql
mysqld --remove相当于mysqld --remove mysql
mysqld --remove
mysqld --remove mysql
sc.exe delete mysql
### powershell版本必须大于等于6
Remove-Service -Name mysql
登录
./mysql -uroot
创建远程用户
创建remote用户的语句模板
比如创建一个名为remote的用户,可以写在一行,以分号分隔
CREATE USER IF NOT EXISTS 'remote'@'%' IDENTIFIED BY 'remote'; GRANT ALL ON *.* TO 'remote'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;
创建远程root的语句模板
自带的 root@'localhost' 只能本地登陆,
 创建 root@'%' , 并将 root@'localhost' 的权限授予 root@'%'
CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY '密码'; GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
创建 root@‘%’ , 并让 root@'%'扮演root@‘localhost’ 的角色 , 并设置为默认角色
CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY '密码';
GRANT root@'localhost' TO 'root'@'%'; SET DEFAULT ROLE root@'localhost' TO 'root'@'%';
FLUSH PRIVILEGES;
权限和角色两者都加持
CREATE USER IF NOT EXISTS 'root'@'%' IDENTIFIED BY '密码';
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION;
GRANT root@'localhost' TO 'root'@'%';
SET DEFAULT ROLE root@'localhost' TO 'root'@'%';
FLUSH PRIVILEGES;
或者直接将 root@localhost 改为 root@%
update mysql.user set host='%' where user='root'; flush privileges;
UPDATE mysql.user SET host='%' WHERE user='root'; FLUSH PRIVILEGES;