windows 下安装mysql(非msi安装版)以及创建数据库和用户

一:安装mysql

前提条件:

在mysql官网下载,比如mysql-5.6.26-winx64.zip,解压mysql-5.6.26-winx64,尽量不要去其他网站下载。

 

1、win10下,win+x键选择“命令提示符(管理员)”。

(注意:一定要用管理员运行CMD进入DOS!

 

2、在环境变量PATH中添加:

;D:\Program\MySql\mysql-5.6.26-winx64\bin

 

3、进入到mysql-5.6.26-winx64的bin目录下

C:\WINDOWS\system32>d:

D:\>cd D:\Program\MySql\mysql-5.6.26-winx64

D:\Program\MySql\mysql-5.6.26-winx64>cd bin

 

4、输入服务安装命令

D:\Program\MySql\mysql-5.6.26-winx64\bin>mysqld install MySQL --defaults-file="D:\Program\MySql\mysql-5.6.26-winx64\my-default.ini"

Service successfully installed.

 

(下载的压缩包里如果没有my-default.ini,那么可以手工创建

my-default.ini原始内容为:

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

 

[mysqld]

 

# 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.

# basedir = .....

# datadir = .....

# port = .....

# 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 = 2M

# read_rnd_buffer_size = 2M 

 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

 

5、启动MYSQL服务

D:\Program\MySql\mysql-5.6.26-winx64\bin>net start mysql

MySQL 服务正在启动 .

MySQL 服务已经启动成功。

 

6、修改MYSQL密码

D:\Program\MySql\mysql-5.6.26-winx64\bin>mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.26 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.00 sec)

 

mysql> use mysql;

Database changed

mysql> UPDATE user SET password=PASSWORD("root") WHERE user='root';

Query OK, 3 rows affected (0.00 sec)

Rows matched: 3  Changed: 3  Warnings: 0

 

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

 

mysql> QUIT

Bye

 

7、测试密码是否修改成功

D:\Program\MySql\mysql-5.6.26-winx64\bin>mysql -uroot -proot

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.6.26 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

二:创建用户和数据库并赋予权限

2.使用root管理员登录mysql。

mysql -uroot -p123456;

3.创建新用户

CREATE USER 'user'@'%' IDENTIFIED BY 'password';

注:'%' - 所有情况都能访问
       ‘localhost’ - 本机才能访问
       ’111.222.111.111‘ - 指定 ip 才能访问

修改密码

update mysql.user set password=password('新密码') where user='user1';

4.新用户登录访问,可以看到默认生成的两个数据库,看不到其他任何数据库;

5.给用户添加权限

grant all privileges on 想授权的数据库.* to 'user'@'%';

all可以替换为  select,delete,update,create,drop

此时访问即可看到新添加的数据库;

6.删除用户

Delete FROM mysql.user Where User='user1';

注意:刷新权限;在对用户进行操作后,可能不及时生效,需进行权限刷新

flush privilege;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值