Kali Linux下MySQL设置和重置用户名密码


1、如果Linux中未安装MySQL,则需要下载安装,在安装的过程中会要求输入用户名密码,则无需重置,直接设置



2、MySQL设置UTF-8编码格式

配置文件:

root@kali:~# vim /etc/mysql/my.cnf


添加默认utf-8编码:
[client]
default-character-set = utf8

[mysqld]
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_ci



3、更新MySQL的用户名密码


首先查看MySQL是否运行,确保MySQL是stop状态,可以使用/etc/init.d/mysql stop停止运行

root@kali:~# /etc/init.d/mysql status
[info] MySQL is stopped..


然后启动MySQL的server/daemon process

root@kali:~# mysqld_safe --skip-grant-tables &
[1] 4216
root@kali:~# 151015 11:33:52 mysqld_safe Logging to syslog.
151015 11:33:52 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

使用root用户连接MySQL

root@kali:~# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.44-0+deb7u1 (Debian)

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> 

更改root用户的密码为admin

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=PASSWORD('admin') where User='root';
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4  Changed: 4  Warnings: 0

执行更新命令

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
flush privileges 命令本质上的作用是将当前user和privilige表中的用户信息/权限设置从mysql库(MySQL数据库的内置库)中提取到内存里。MySQL用户数据和权限有修改后,希望在"不重启MySQL服务"的情况下直接生效,那么就需要执行这个命令。通常是在修改ROOT帐号的设置后,怕重启后无法再登录进来,那么直接flush之后就可以看权限设置是否生效。而不必冒太大风险。


退出

mysql> quit


4、验证用户密码是否更新成功


重启MySQL

root@kali:~# /etc/init.d/mysql restart
[ ok ] Stopping MySQL database server: mysqld.
[....] Starting MySQL database server: mysqld151015 11:41:36 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[ .k 
[info] Checking for tables which need an upgrade, are corrupt or were 
not closed cleanly..
[1]+  完成                  mysqld_safe --skip-grant-tables

使用root用户连接MySQL

root@kali:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 43
Server version: 5.5.44-0+deb7u1 (Debian)

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> 



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值