常见MySQL问题及解决方案


本文摘自PHP中文网,作者小云云,侵删。

作为程序员,MySQL必定时我们会运用到的东西,而且很重要,可是有时候在工作中MySQL数据库难免会发生些问题,那么我们怎么去处理呢?下面我们就谈谈平常工作中会遇到的MySQL常见的一些问题及解决方案。

一、 忘记 MySQL 的 root 密码

1. 登录到数据库所在的服务器,手工 kill 掉 mysql 进程。

(1) 登录到数据库所在的服务器,手工 kill 掉 MySQL 进程:

root@bogon:/data/mysql# kill `cat ./mysql.pid`

其中,mysql.pid 指的是 MySQL 数据目录下的 pid 文件,它记录了 MySQL 服务的进程号。

(2) 使用 --skip-grant-tables 选项重启 MySQL 服务:

zj@bogon:/data/mysql$ sudo /usr/local/mysql/bin/mysqld --skip-grant-tables --user=root &

--skip-grant-tables 选项意思是启动 MySQL 服务时跳过权限表认证。启动后,连接到 MySQL 的 root 将不需要口令。

(3) 用空密码的 root 用户连接到 mysql ,并且更改 root 口令:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

zj@bogon:/usr/local/mysql/bin$ mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3Server version: 5.7.18-log Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> set password = password('123456');

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statementMySQL [(none)]> use mysql

Database changed

MySQL [mysql]> update user set authentication_string=password('123456') where user="root" and host="localhost";

Query OK, 1 row affected, 1 warning (0.02 sec)

Rows matched: 1  Changed: 1  Warnings: 1MySQL [mysql]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MySQL [mysql]> exit;

Bye

****************************************************************

zj@bogon:/usr/local/mysql/bin$ mysql -uroot -p123456

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 7Server version: 5.7.18-log Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]>

由于使用了 --skip-grant-tables 选项启动,使用 “set password” 命令更改密码失败,直接更新 user 表的 authentication_string(测试版本为5.7.18,有的版本密码字段是 ‘password’) 字段后,更改密码成功。刷新权限表,使权限认证重新生效。重新用 root 登录时,就可以使用刚刚修改后的口令了。

阅读剩余部分

相关阅读 >>

mysql触发器(trigger)简明总结和使用实例

mysql怎么更改日志文件的路径?

mysql实现自动监控同步的脚本

学习mysql不是内部命令的错误解决方案

navicat for mysql 16怎么注册?navicat16全系列最新破解教程(附注册机)

mysql触发器基本用法详解【创建、查看、删除等】

mysql的一些高级用法

mysql数据归档小工具mysql_archiver详解

mysql 数据恢复的多种方法汇总

mysql创建内存表的方法

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...