mysql5.7 on windows
1.下载zip包:
https://dev.mysql.com/downloads/file/?id=476696
https://dev.mysql.com/downloads/file/?id=476696
2.解压到E盘
3.执行命令 初始化
E:/mysql-5.7.22-winx64/bin/mysqld --initialize-insecure --basedir=E:/mysql-5.7.22-winx64 --datadir=E:/mysql-5.7.22-winx64/data
4.创建配置文件
E:/mysql-5.7.22-winx64/my.ini :
[mysqld]
port=3310
# set basedir to your installation path
basedir=E:\\mysql-5.7.22-winx64
# set datadir to the location of your data directory
datadir=E:\\mysql-5.7.22-winx64\\data
key_buffer_size=16M
max_allowed_packet=8M
5.执行命令启动mysql
start E:/mysql-5.7.22-winx64/bin/mysqld --defaults-file=E:/mysql-5.7.22-winx64/my.ini
6.另起一个命令行,连上mysql服务
6.另起一个命令行,连上mysql服务
E:/mysql-5.7.22-winx64/bin/mysql -h127.0.0.1 -P 3310 -u root --skip-password
7.执行sql设置root密码
7.执行sql设置root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql1314';
8.退出
8.退出
exit
9.重新使用新密码连接
9.重新使用新密码连接
E:/mysql-5.7.22-winx64/bin/mysql -h127.0.0.1 -P 3310 -u root -p
10.建库;
10.建库;
create database db1;
11.建用户user1
11.建用户user1
GRANT USAGE ON *.* TO 'user1'@'%' IDENTIFIED BY '123456';
12.为user1授权
12.为user1授权
GRANT ALL ON *.* TO 'user1'@'%';
flush privileges;
exit
13.使用user1连接数据库
E:/mysql-5.7.22-winx64/bin/mysql -h127.0.0.1 -P 3310 -u user1 -p
14.建表
use db1
create table t1(id int auto_increment,name varchar(20),primary key (id));
参考资料
https://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html