MySQL账户管理的一些常用操作

本文介绍在Windows环境下MySQL数据库账户管理的常见操作,包括登录数据库、查看账户、创建账户、删除账户、修改密码及授权等步骤。

老服务器windows server 2008上安装MySQL,高一点的有兼容问题,不去排查了,选择了低一点版本:5.7.16版本 下载免安装的压缩包,手动安装步骤如下:

1. 解压到D盘: d:\mysql

2. 创建数据目录:d:\mysql\data

3. d:\mysql目录下生成my.ini,内容如下(抄写改改):

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/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 = d:\mysql
datadir = d:\mysql\data
port = 3306
server_id = 1

# 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 

# 设置时区为东八区
default-time-zone = '+8:00'

# 允许最大连接数
max_connections = 200

# 服务端使用的字符集默认为UTF8
character_set_server = utf8

# 创建新表时将使用的默认存储引擎
default-storage-engine = INNODB

# 默认使用“mysql_native_password”插件认证
default_authentication_plugin = mysql_native_password

[mysql]
# 设置MySQL客户端默认字符集
default-character-set = utf8

[client]
# 设置MySQL客户端连接服务端时默认使用的端口
port = 3306
default-character-set = utf8
 

4. 管理员身份证启动cmd,进入d:\mysql\bin目录

5. 输入命令:mysqld --initialize-insecure --user=mysql

6. 输入命令:mysql --install

7. 输入命令:net start mysql

    应显示:

8. 登录数据库,输入命令:mysql -u root -p

9. 提示输入密码直接回车即可(初始无密码)

10.  创建root密码:alter user user() identified by '输入密码';

       (注:'输入密码'就是要创建的密码比如'123456')

至此安装完成,还不能远程访问,需要创建或修改账户的HOST为'%',下文各种命令可以找出相关命令设置。

为了正式服务器上的数据安全,还是要对MySQL数据库账户进行管理,不要轻易使用Root,建议根据使用情况分别设置一些账户供不同情况使用。

下面是Windows环境下mysql账户管理的一些常用的操作:

1. 登录数据库

     c:\>mysql -u xxx -p

     xxx是账户比如root

     回车后,要求输入密码,输入密码后进入了mysql,当然 -p 后面继续写入密码再回车,就直接进入数据库操作环境。

2. 进入数据库

     mysql>use mysql;

     注意要有";"

3. 查看账户

     mysql>select User,Host from user;

     将看到账户列表,User是账户名称,Host是远程还是本地,localhost是允许本地,%是允许任何地方,IP地址是允许的远程地址

4. 创建账户

      mysql>create user ‘gwf’@‘localhost’ identified by '123456';

      mysql>create user ‘gwf’@‘%’ identified by 'abcdef';

      mysql>create user ‘gwf’@‘101.132.22.55’ identified by '666666';

      mysql>flush privileges;

      上面创建了3个账户,gwf是账户名称,名称虽然是同一个,但是@后面是不同的Host登录位置,并且可以使用不用的密码;localhost表示是从本地登录,%则表示从任何地方登陆,101.132.22.55则表示只从101.132.22.55这里登录;123456、abcdef、66666为登录密码。

       flush privileges;是让操作生效。

5. 删除账户

      mysql>drop user ‘root'@'%';

      mysql>flush privileges;

      删除远程登陆账户。

6. 修改密码

     mysql>update mysql.user set password = password('123456') where user = 'gwf' and host = 'localhost';

     mysql>flush privileges;

     修改gwf账户的本地登录密码。

7. 账户授于某个数据库的全部权限

     mysql>grant all privileges on donghuan.* to gwf@'%' identified by '123456';

     mysql>flush privileges;

     将donghuan数据库的全部权限授予gwf的远程登录账户,如果没有这个远程登录账户,则自动创建这个远程登陆用户。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值