Home >Database >Mysql Tutorial >新版MySql5.6.20,安装后无法登陆的解决办法_MySQL

新版MySql5.6.20,安装后无法登陆的解决办法_MySQL

WBOY
WBOYOriginal
2016-06-01 13:02:08950browse

1.按照提示安装好mysql

2.运行cmd 进入mysql的安装目录,我的安装目录C:\Program Files\MySQL\MySQL Server 5.6\bin
  输入   cd C:\Program Files\MySQL\MySQL Server 5.6\bin

3.采用mysqld将mysql注册为服务,命令为:mysqld -install MySQL

4.启动服务:net start MySQL

5.然后登陆,因为root用户的默认密码为空,直接回车进入
  mysql -u root -p

6.①  show databases;
  ②  use mysql;
  ③  SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
  ④  quit;
#添加一个可远程登录的帐号user,且设置密码123456,能访问所有库 如远程无法访问关闭防火墙或添加入站出站规则,添加端口3306
GRANT all privileges on *.* TO 'user'@'%' identified by '123456' WITH GRANT OPTION;  
FLUSH PRIVILEGES;  

#mysql 添加用户user1并授权访问指定数据库db123,且设置密码333333
grant all privileges on db123.* to 'user1'@'%' identified by '333333' with grant option;  
FLUSH PRIVILEGES;

#mysql 添加用户user2并授权访问指定数据库db123,且设置密码666666,同时限制登录为指定IP段
grant all privileges on db123.* to 'user2'@'192.168.104.%' identified by '666666' with grant option;  
FLUSH PRIVILEGES; 
MySQL新建用户,授权,删除用户,修改密码

1.新建用户。

//登录MYSQL
@>mysql -u root -p
@>密码
//创建用户
mysql> insert into mysql.user(Host,User,Password) values("localhost","phplamp",password("1234"));
//刷新系统权限表
mysql>flush privileges;
这样就创建了一个名为:phplamp  密码为:1234  的用户。

然后登录一下。

mysql>exit;
@>mysql -u phplamp -p
@>输入密码
mysql>登录成功

2.为用户授权。

//登录MYSQL(有ROOT权限)。我里我以ROOT身份登录.
@>mysql -u root -p
@>密码
//首先为用户创建一个数据库(phplampDB)
mysql>create database phplampDB;
//授权phplamp用户拥有phplamp数据库的所有权限。
>grant all privileges on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系统权限表
mysql>flush privileges;
mysql>其它操作

/*
如果想指定部分权限给一用户,可以这样来写:
mysql>grant select,update on phplampDB.* to phplamp@localhost identified by '1234';
//刷新系统权限表。
mysql>flush privileges;
*/

3.删除用户。
@>mysql -u root -p
@>密码
mysql>DELETE FROM user WHERE User="phplamp" and Host="localhost";
mysql>flush privileges;
//删除用户的数据库
mysql>drop database phplampDB;

4.修改指定用户密码。
@>mysql -u root -p
@>密码
mysql>update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost";
mysql>flush privileges;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn