mysql start the process

MySQL If you delete all the users how to do?

premise:

1, there is determined a database Close

2, is determined from a database and no master

Operating procedures:

1. Shut down the database

2, not to verify the landing approach (no password required)

3, enter a user authorization database in mysql database

4, or to insert data in the user table mysql

 

As follows:

[root@localhost ~]# mysql  -uroot  -p123

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

# This specifies the user can not login and password

[root@localhost ~]# service   mariadb   stop

# Stop the database

[root@localhost ~]# mysqld_safe --skip-grant-tables  --skip-networking  &

# Conduct free secret landing

MariaDB [(none)]> use  mysql

Database changed

MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'password' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> select   user, host  from   user;

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

| user | host      |

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

| root | localhost |

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

1 row in set (0.00 sec)

The second method

What the user table columns If you use this method you need to know

MariaDB [mysql]> desc  user;

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

| Field                  | Type                              | Null | Key | Default | Extra |

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

| Host | char (60) | NO | PRI | | |

| User                   | char(16)                          | NO   | PRI |         |       |

| Password               | char(41)                          | NO   |     |         |       |

| SELECT_priv | enum ( 'N', 'Y') | NO | | N | |

| Insert_priv            | enum('N','Y')                     | NO   |     | N       |       |

| Update_priv            | enum('N','Y')                     | NO   |     | N       |       |

| Delete_priv | enum ( 'N', 'Y') | NO | | N | |

| Create_priv | enum ( 'N', 'Y') | NO | | N | |

| Drop_priv              | enum('N','Y')                     | NO   |     | N       |       |

| Reload_priv | enum ( 'N', 'Y') | NO | | N | |

| Shutdown_priv | enum ( 'N', 'Y') | NO | | N | |

| Process_priv | enum ( 'N', 'Y') | NO | | N | |

| File_priv | enum ( 'N', 'Y') | NO | | N | |

| Grant_priv | enum ( 'N', 'Y') | NO | | N | |

| References_priv | enum ( 'N', 'Y') | NO | | N | |

| Index_priv | enum ( 'N', 'Y') | NO | | N | |

| Alter_priv | enum ( 'N', 'Y') | NO | | N | |

| Show_db_priv           | enum('N','Y')                     | NO   |     | N       |       |

| Super_priv | enum ( 'N', 'Y') | NO | | N | |

| Create_tmp_table_priv  | enum('N','Y')                     | NO   |     | N       |       |

| Lock_tables_priv       | enum('N','Y')                     | NO   |     | N       |       |

| Execute_priv           | enum('N','Y')                     | NO   |     | N       |       |

| Repl_slave_priv        | enum('N','Y')                     | NO   |     | N       |       |

| Repl_client_priv       | enum('N','Y')                     | NO   |     | N       |       |

| Create_view_priv       | enum('N','Y')                     | NO   |     | N       |       |

| Show_view_priv         | enum('N','Y')                     | NO   |     | N       |       |

| Create_routine_priv    | enum('N','Y')                     | NO   |     | N       |       |

| Alter_routine_priv     | enum('N','Y')                     | NO   |     | N       |       |

| Create_user_priv       | enum('N','Y')                     | NO   |     | N       |       |

| Event_priv             | enum('N','Y')                     | NO   |     | N       |       |

| Trigger_priv           | enum('N','Y')                     | NO   |     | N       |       |

| Create_tablespace_priv | enum('N','Y')                     | NO   |     | N       |       |

| ssl_type               | enum('','ANY','X509','SPECIFIED') | NO   |     |         |       |

| ssl_cipher             | blob                              | NO   |     | NULL    |       |

| x509_issuer            | blob                              | NO   |     | NULL    |       |

| x509_subject           | blob                              | NO   |     | NULL    |       |

| max_questions          | int(11) unsigned                  | NO   |     | 0       |       |

| max_updates            | int(11) unsigned                  | NO   |     | 0       |       |

| max_connections        | int(11) unsigned                  | NO   |     | 0       |       |

| max_user_connections   | int(11)                           | NO   |     | 0       |       |

| plugin                 | char(64)                          | NO   |     |         |       |

| authentication_string  | text                              | NO   |     | NULL    |       |

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

42 rows in set (0.01 sec)

#这里是user表中的字段,如果需要插入超级用户需要有所有的权力,即这里的列为Y

操作语句

MariaDB [(none)]> insert   into  mysql.user  values('127.0.0.1','root',PASSWORD('123'),'Y','Y', 'Y', 'Y', 'Y', 'Y','Y', 'Y', 'Y', 'Y', 'Y','Y', 'Y', 'Y', 'Y', 'Y','Y', 'Y', 'Y', 'Y', 'Y','Y', 'Y', 'Y', 'Y', 'Y','Y', 'Y', 'Y','','','',0,0,0,0,'mysql_native_password','','N');

#重启数据库

MariaDB [mysql]> select user,host from   user;

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

| user | host      |

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

| root | 127.0.0.1 |

| root | localhost |

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

2 rows in set (0.00 sec)

 

mysql的连接

mysql命令是mysql自带的连接数据库工具,其本质是mysql客户端

常见参数有:

-u          指定用户

-p          指定密码

-h          指定IP地址用于远程连接

-S          指定soket文件

-e          指定使使用的sql语句

--protocol=name   指定连接方式

第三方工具

sqlyon、navtcat

mysqld_safe与mysqld区别

mysqld是mysql的守护进程。每次在使用mysql前必须先用它。mysqld是计算机进程,MySQL数据库服务器相关程序。

mysqld_safe

1. 检查系统和选项。

2. 检查MyISAM表。

3. 保持MySQL服务器窗口。

4. 启动并监视mysqld,如果因错误终止则重启。

5. 将mysqld的错误消息发送到数据目录中的host_name.err 文件。

6. 将mysqld_safe的屏幕输出发送到数据目录中的host_name.safe文件。

mysqld_safe的常用参数详解

参数

说明

--skip-grant-tables

跳过安全验证

--skip-networking

关闭tcp连接

--datadir=path

指定安装目录

--basedir=path

指定数据目录

--defaults-file=path

指定数据库配置目录

--pid-file=path

指定pid文件目录

--socket=path

指定socket文件

--user=username

指定启动用户

--port=3306

指定端口

--log-error

指定错误日志目录

 

MySQL数据库启动流程

 

 

 

Guess you like

Origin www.cnblogs.com/DB-MYSQL/p/11616475.html