下载
https://dev.mysql.com/downloads/mysql/
解压
路径D:\dev\mysql-8.0.30-winx64;
添加环境变量
D:\dev\mysql-8.0.30-winx64\bin添加到环境变量
安装
使用管理员方式打开cmd (命令窗口输入输入cmd后 输入Ctrl+Shift+Enter)
开始安装
(1)、mysqld install
C:\Windows\system32>mysqld install
Service successfully installed.
(2)、启动服务 net start mysql
出现错误先忽略
C:\Windows\system32>net start mysql
MySQL 服务正在启动 .
MySQL 服务无法启动。
服务没有报告任何错误。
(3)初始化 mysqld --initialize --console
如下命令得到的初始密码是U,l&FF/!l0dz
C:\Windows\system32>mysqld --initialize --console
2022-08-31T01:25:52.873437Z 0 [System] [MY-013169] [Server] D:\dev\mysql-8.0.30-winx64\bin\mysqld.exe (mysqld 8.0.30) initializing of server in progress as process 29564
2022-08-31T01:25:52.887789Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-08-31T01:25:53.125133Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-08-31T01:25:53.719896Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: U,l&FF/!l0dz
(4)、修改默认密码
如果服务未启动成功,则再次执行net start mysql
然后进入mysql 修改密码:
C:\Windows\system32>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.30
。。。
mysql> ALTER USER USER() IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
远程链接
配置
进入mysql后
update user set host = ‘%’ where user = ‘root’;
重启服务
mysql> use mysql
Database changed
mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql8特殊处理
mysql8版本会提示“Navicat连接Mysql 8.0报错并显示:Client does not support authentication protocol requested by server”
问题原因:Mysql8.0的默认认证方式改用sha2了,要么升级客户端,要么修改要登陆的用户认证方式
下面只讲解修改认证方式方案;
解决方法:
alter user ‘root’@‘%’ IDENTIFIED WITH mysql_native_password by ‘123456’;
flush privileges;
mysql> select host,user ,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | caching_sha2_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> alter user 'root'@'%' IDENTIFIED WITH mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user ,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| % | root | mysql_native_password |
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
+-----------+------------------+-----------------------+
4 rows in set (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)