mysql安装以及配置和启动

mysql 的下载及安装

mysql 的下载

mysql 下载地址

选择对应的下载文件。(我电脑是 64 位,所以这下载的是 64 位的下载文件)

mysql 的安装

msi 格式的

直接点击安装,按照它给出的安装提示进行安装

zip 格式的

zip 格式是自己解压,解压缩之后其实 MySQL 就可以使用了。

mysql 的启动

2-1、找到mysql的安装目录 **D:\tool\mysql-5.6.42-winx64\bin**

2-2、双击mysqld.exe启动mysql服务

2-3、启动cmd命令提示窗,cd到bin目录下,输入mysql -u root -p,并回车,

这个时候提示输入密码,一般初始密码为空,直接回车就进入mysql服务

用户和数据库的创建以及相关操作

数据库的创建

create database mydatabase;

创建用户

insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));

在mysql8.0版本里,用以下方式:

create user 'username'@'localhost' identified by 'pwd'

注意:此处的”localhost”,是指该用户只能在本地登录,不能在另外一台机器上远程登录。如果想远程登录的话,将”localhost”改为”%”,表示在任何一台电脑上都可以登录。也可以指定某台机器可以远程登录

为用户授权

授权格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码";

授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限)
grant all privileges on testDB.* to test@localhost identified by '1234';

如果想指定部分权限给一用户:
grant select,update on testDB.* to test@localhost identified by '1234';

授权test用户拥有所有数据库的某些权限:  
grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

在mysql8.0版本里,用以下方式:
grant all privileges on 'testDB'.* to 'test'@'localhost'

注:如果授权不成功,则先执行 flush privileges(刷新系统权限),然后再授权,在 8.0 版本里需要更换加密方式,否则无法登陆数据库

alter user 'username'@'localhost' identified with mysql_native_password by 'newpwd'

然后刷新下权限
flush privileges

用户登录

exit; //退出当前用户

mysql -u test -p;
然后输入密码登录

注:上一步的授权里不要用test@’%’,而是用test@localhost,否则会被拒绝登录,这里有说明

第三方工具软件的接入

创建mysql连接,输入刚刚创建的用户名和密码就可以成功连接到我们创建的数据库,

然后就可嘿嘿嘿的创建各种表了,从而进行各种操作了。
感谢您为我的屌丝逆袭之路添砖加瓦!!!