启动MySQL Server

启动MySQL Server,但跳过所有授予特权和网络:

# mkdir -p /var/run/mysqld
# chown mysql:mysql /var/run/mysqld
# /usr/sbin/mysqld --skip-grant-tables --skip-networking &
[1] 8142

登录mysql

接下来,在不使用密码的情况下以root身份登录mysql:

# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.12-0ubuntu1 (Ubuntu)
Copyright (c) 2000, 2014, 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>

使用新密码登录

# mysql -u root --password=onitroad
mysql: [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 7
Server version: 5.7.12-0ubuntu1 (Ubuntu)
Copyright (c) 2000, 2014, 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设置新密码(onitroad),并退出

mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('onitroad');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> quit
Bye

刷新权限

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected, 6 warnings (0.02 sec)
mysql>
如何在Linux服务器上重置MySQL root密码

如何在Linux上重置管理root密码。

重新启动mysql数据库

优雅地停止当前MySQL进程:

# kill %1
[1]+  Done                    /usr/sbin/mysqld --skip-grant-tables --skip-networking

接下来,我们需要启动MySQL数据库:

# service mysql start

停止mysql

首先,停止MySQL Server:

# service mysql stop
 * Stopping MySQL database server mysqld              [ OK ]
日期:2020-07-07 20:56:32 来源:oir作者:oir