电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 2015 人浏览分享

mysql的忘记密码、无法启动和socket文件丢失等错误问题的解决办法

[复制链接]
2015 0
本帖最后由 zhaorong 于 2018-6-25 15:28 编辑

问题一、忘记密码

  1. [root@141 sh]# mysql -uroot -p
  2. Enter password:
  3. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
复制代码


解决方案:

在配置文件中选择免密登录:

  1. [code][code][root@141 sh]# vim /etc/my.cnf
复制代码

20180622112101195.png

  1. [root@141 sh]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MariaDB monitor.  Commands end with ; or \g.
  4. Your MariaDB connection id is 2
  5. Server version: 5.5.35-MariaDB MariaDB Server
  6. Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8. MariaDB [(none)]> exit
复制代码

问题二、无法启动

解决方案:

  1. # yum install mariadb-server -y //如果已安装可以省略  
  2. # systemctl start mariadb.service //启动服务  
  3. # systemctl enable mariadb.service //开机启动服务  
  4. # mysql -u root -p //登录mysql  
复制代码


问题三、socket文件丢失

连接localhost通常通过一个Unix域套接字文件进行,一般是/tmp/mysql.sock。如果套接字文件被删除了,
本地客户就不能连接。这可能发生在你的系统运行一个cron任务删除了/tmp下的临时文件。

如果你因为丢失套接字文件而不能连接,你可以简单地通过重启服务器重新创建得到它。
因为服务器在启动时重新创建它。

20180622112101197.png


接下来就是保存退出,然后确保这个目录存在,并且将这个目录的权限修改一下

  1. chmod 777 /var/lib/mysql  
  2. # service mysql  restart  
  3. # service mysqld restart
复制代码

  1. root@iZufkfljcZ:/var/run/mysqld# mysql -uroot -p -S /var/run/mysqld/mysqld.sock   
  2. Enter password:   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4. Your MySQL connection id is 4  
  5. Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)  
  6. Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.  
  7. Oracle is a registered trademark of Oracle Corporation and/or its  
  8. affiliates. Other names may be trademarks of their respective  
  9. owners.  
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  11. mysql>
复制代码


运行成功后,把之前改的配置改回来就行,之前的目录是/tmp/mysql.sock,建立一个软连接连上去就可以。

  1. ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
复制代码


9.png


  1. [root@141 sh]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MariaDB monitor.  Commands end with ; or \g.
  4. Your MariaDB connection id is 2
  5. Server version: 5.5.35-MariaDB MariaDB Server
  6. Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
复制代码


成功!



您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.