mysql数据库安装

1、下载zip安装包,在本地进行解压


 (下载的安装包5.7版本)

(解压后的安装包)

2、数据库进行初始化


 1)cmd进入解压目录的bin目录下, 执行命令:mysqld --initialize-insecure(使用管理员权限进入cmd)

2)初始化后,解压目录会有多出data目录

3)启动服务端:mysqld,此时服务端已启动

4)windows服务,进入mysql的安装的bin目录下,执行命令:mysqld --install

5)启动服务命令:net start MySQL

(第一启动报错了,一直没有解决,后来重启电脑后正常了,下一张截图)

6)停止服务命令:net start MySQL

3、登录数据库


  1、数据库默认的root用户没有密码:mysql -uroot -p

 4、创建数据库


1、创建命令:create database db1;

2、查看数据库:show databases;

5、创建用户


  1、创建用户:create user 'test'@'%' identified by '123456';

2、设置用户权限:grant all privileges  on db1.* to 'test'@'%';

1)设置用户test全权限,数据库db1下面的表:grant all privileges  on db1.* to 'test'@'%';

2)设置部分权限:grant select,insert,update  on db1.t1 to 'test'@'%';

3、刷新权限:flush privileges;//刷新系统权限表

4、刷新权限:revoke all privileges on db1.t1 from 'test'@'%';

其他命令事例:

如果想指定部分权限给一用户,可以这样来写:

mysql>grant select,update on testDB.* to test@localhost identified by '1234';

授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限):

mysql>grant all privileges on testDB.* to test@localhost identified by '1234';

授权test用户拥有所有数据库的某些权限:   

mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

//test用户对所有数据库都有select,delete,update,create,drop 权限。

//@"%" 表示对所有非本地主机授权,不包括localhost。(localhost地址设为127.0.0.1,如果设为真实的本地地址,不知道是否可以,没有验证。)

//对localhost授权:加上一句grant all privileges on testDB.* to test@localhost identified by '1234';即可。

原文地址:https://www.cnblogs.com/ygzy/p/10834671.html