一,MySQL8.0.*zip版本安装步骤。
1. 下载
https://dev.mysql.com/archives/get/p/23/file/mysql-8.0.24-winx64.zip
注现在最新的版本是8.0.24
2. 解压
将mysql-8.0.24-winx64.zip解压到 E:\Tools\mysql\mysql-latest
目录下
3. 打开cmd命令控制台,输入以下命令。
切记使用windows中的cmd命令行。
e:
cd \
cd E:\Tools\mysql\mysql-latest\bin
rem 初始化数据库目录,账号为root,无密码. 执行后mysql目录下将会多出一个data文件夹。
E:\Tools\mysql\mysql-latest\bin>mysqld --initialize-insecure
4. 安装数据库系统服务,输入以下命令。
@echo off
echo install mysql:
pushd %~dp0\bin
echo "%~dp0\bin"
mysqld --install mysql_3306
popd
echo sleep 2秒钟
ping 127.0.0.1 -n 1 -w 2000 > nul
echo Starting mysql_3306:
echo 启动数据库服务
net start mysql_3306
pause
5. 登录数据库服务器
#rem 直接登录无密码
E:\Tools\mysql\mysql-latest\bin>mysql -u root
rem 查看当前版本号
mysql>select version();
rem 查看登录账号
mysql>show user();
rem 查看所有数据库
mysql>show databases;
rem 建立数据库
mysql>create database db;
6. 退出卸载
rem 退出客户端
mysql>exit
rem 停止服务
E:\Tools\mysql\mysql-latest\bin>net stop mysql
rem 卸载服务
E:\Tools\mysql\mysql-latest\bin>mysqld --remove
7. 修改root密码为123456
连接到mysql
E:\Tools\mysql\mysql-latest\bin\mysql -uroot
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
方法二、还有一种方法
下载以后将安装包解压到任意文件夹,我这里解压到E:\Tools\mysql\mysql-latest
。
安装
在E:\Tools\mysql\mysql-latest
里面建立一个空文件夹data,如果已经有这个文件夹就不用进行这一步
建立一个my.ini文件,用记事本打开,复制以下代码进去
[mysqld]
# 设置3306端口
port=3306
# 设置mysql的安装目录
basedir=E://Tools//mysql//mysql-latest
# 设置mysql数据库的数据的存放目录
datadir=E://Tools//mysql//mysql-latest//data # 注意要双//
# 允许最大连接数
max_connections=200
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为utf8mb4 新版本的MySQL 字符集以更改为utf8mb4
character-set-server=utf8mb4
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
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.
# 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=traditional
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
default-character-set = utf8mb4
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
配置环境变量
右键计算机->属性->高级系统设置->高级->环境变量
,在系统变量中添加一个名叫 MYSQL_HOME 的变量,修改Path变量,在末尾添加 %MYSQL_HOME%\bin,以管理员身份运行cmd命令,并将路径换到mysql的bin目录下,初始化数据库,运行命令:
bin\mysqld --initialize-insecure --console
E:\Tools\mysql\mysql-latest>bin\mysqld --initialize-insecure --console
2021-07-10T05:43:08.816199Z 0 [System] [MY-013169] [Server] E:\Tools\mysql\mysql-latest\bin\mysqld.exe (mysqld 8.0.25) initializing of server in progress as process 15860
2021-07-10T05:43:08.889111Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-07-10T05:43:16.428759Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-07-10T05:43:38.797280Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
E:\Tools\mysql\mysql-latest>
安装服务
运行命令:mysqld –install, 至此mysql就安装完毕了
bin\mysqld --install "MySql_3306" --defaults-file="E:/Tools/mysql/mysql-latest/my.ini"
测试是否安装成功
启动mysql服务命令
net start MySql_3306
停止mysql服务命令
net stop MySql_3306
更改密码
假设要把密码改成123456, 运行cmd,在bin目录下运行命令:
bin\mysql -u root -p
输入原密码
输入语句:
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
备注:8.0之前版本,忘记密码修改方法
- 找到bin目录:mysqld —skip-grant-tables
- 重新在开一个cmd窗口
- 找到bin目录:mysql就进入登陆状态了
- 5.7.22修改密码语句:update user set authentication_string=password(‘123456’) where user=’root’ and host=’localhost’;
- 5.6.修改密码语句:update user set password=password(‘123456’) where user=’root’ and host=’localhost’; (我没有实验过,网上都是这么写的)
原文链接
https://www.cnblogs.com/activiti/p/10538169.html https://www.cnblogs.com/1285026182YUAN/p/10422133.html