mysql user 表里有几个root

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql user 表里有几个root相关的知识,希望对你有一定的参考价值。

首先mysql User表中的root数据根据安装环境不同数量不一样。

如图详细介绍User表:

1、 如图所示为win8.1机器安的user表。默认有2个root(图中紫色框选部分),分别是:root@127.0.0.1,root@localhost;linux下安装一般是有3个root,比win8.1多了1个root@主机名;

2、User表是
mysql默认内置的数据表,可编辑:表中的【Host】字段表示远程连接地址、【User】字段表示远程连接用户名,【Password】字段表示远程连接密码,其它字段含义见附件【User表字段含义】(图中红色框选部分,权限配置);

3、User表可以增加数据,如图中蓝色框选部分;


参考技术A 一般情况下有三个 对应的域分别是localhost 127.0.0.1 %,研发环境都没事,线上环境需要修改一下 参考技术B root用户数量不确定。
一般linux系统安装完数据库后,会出现:root@localhost,root@127.0.0.1,root@主机名
每个账号都是独立的。本回答被提问者和网友采纳
参考技术C

可以设置好多个

因为第一个是允许访问的ip

第二个是访问者用户名

第三个是访问者密码

后面的是权限

访问者用户名也可以用其他的

个人理解,仅供参考!

mysql忘记root密码

mysql忘记了超级用户管理密码,可以利用重新启动mysql进程的时候带 --skip-grant-tables参数来启动数据库,并空密码登录。这个就是相当于是数据库第一次启动的时候。随后可以查看mysql.user表里面的超级用户,以及修改超级用户的密码

1# 关闭MYSQL instance,或者杀死进程

2# 重新启动mysql,带--skip-grant-tables语句

[[email protected] my.cnf.d]$ mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘  --skip-grant-tables &
[1] 32530
[[email protected] my.cnf.d]$ 180828 19:02:13 mysqld_safe Logging to ‘/data/mysqldata/3306/data/../mysql-error.log‘.
180828 19:02:13 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data

[[email protected] my.cnf.d]$ 

3# 空密码登录MySQL

[[email protected] my.cnf.d]$ msyql -S /data/mysqldata/3306/mysql.sock 
bash: msyql: command not found...
[[email protected] my.cnf.d]$ mysql -S /data/mysqldata/3306/mysql.sock 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.6.31-log Source distribution

Copyright (c) 2000, 2016, 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.

([email protected])[(none)]> 

4# 修改mysql.user表

([email protected])[(none)]> 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
([email protected])[mysql]> 
([email protected])[mysql]> select user,host,password from user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *A0F874BC7F54EE086FCE60A37CE7887D8B31086B |
+------+-----------+-------------------------------------------+
1 row in set (0.00 sec)

([email protected])[mysql]> update user set password=password(‘password123‘) where user=‘root‘;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

([email protected])[mysql]> 

5# 正常关闭数据库

[[email protected] my.cnf.d]$ mysqladmin -S /data/mysqldata/3306/mysql.sock -uroot -p‘password123‘ shutdown
Warning: Using a password on the command line interface can be insecure.
180828 19:04:54 mysqld_safe mysqld from pid file /data/mysqldata/3306/mysql.pid ended
[1]+  Done                    mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘ --skip-grant-tables
[[email protected] my.cnf.d]$ 

6# 正常开启数据库

[[email protected] my.cnf.d]$ mysqld_safe --defaults-file=‘/data/mysqldata/3306/my.cnf‘  &
[1] 33094
[[email protected] my.cnf.d]$ 180828 19:05:04 mysqld_safe Logging to ‘/data/mysqldata/3306/data/../mysql-error.log‘.
180828 19:05:04 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data

[[email protected] my.cnf.d]$

7# 正常登录数据库

[[email protected] my.cnf.d]$ mysql -uroot -S ‘/data/mysqldata/3306/mysql.sock‘ -p‘password123‘
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 1
Server version: 5.6.31-log Source distribution

Copyright (c) 2000, 2016, 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.

([email protected])[(none)]> 

至此mysql的root密码修改完成

以上是关于mysql user 表里有几个root的主要内容,如果未能解决你的问题,请参考以下文章

MySQL 更新一个表里的字段等于另一个表某字段的值

MySQL - 数据操作语言

MySQL导出所有账号的GRANTS语句

初识mySQL(关系型数据库)

MySQL插入数据因外键约束失败?

mysql 管理脚本