mysql的忘记密码、无法启动和socket文件丢失等错误问题的解决办法
程序员文章站
2022-03-02 17:27:25
问题一、忘记密码
[root@141 sh]# mysql -uroot -p
enter password:
error 1045 (28000): access denied for...
问题一、忘记密码
[root@141 sh]# mysql -uroot -p enter password: error 1045 (28000): access denied for user 'root'@'localhost' (using password: no)
解决方案:
在配置文件中选择免密登录:
[root@141 sh]# vim /etc/my.cnf
[root@141 sh]# mysql -uroot -p enter password: welcome to the mariadb monitor. commands end with ; or \g. your mariadb connection id is 2 server version: 5.5.35-mariadb mariadb server copyright (c) 2000, 2013, oracle, monty program ab and others. type 'help;' or '\h' for help. type '\c' to clear the current input statement. mariadb [(none)]> exit
问题二、无法启动
解决方案:
# yum install mariadb-server -y //如果已安装可以省略 # systemctl start mariadb.service //启动服务 # systemctl enable mariadb.service //开机启动服务 # mysql -u root -p //登录mysql
问题三、socket文件丢失
连接localhost通常通过一个unix域套接字文件进行,一般是/tmp/mysql.sock。如果套接字文件被删除了,本地客户就不能连接。这可能发生在你的运行一个cron任务删除了/tmp下的临时文件。
如果你因为丢失套接字文件而不能连接,你可以简单地通过重启服务器重新创建得到它。因为服务器在启动时重新创建它。
接下来就是保存退出,然后确保这个目录存在,并且将这个目录的权限修改一下
chmod 777 /var/lib/mysql # service mysql restart # service mysqld restart
root@izufkfljcz:/var/run/mysqld# mysql -uroot -p -s /var/run/mysqld/mysqld.sock enter password: welcome to the mysql monitor. commands end with ; or \g. your mysql connection id is 4 server version: 5.7.20-0ubuntu0.16.04.1 (ubuntu) copyright (c) 2000, 2017, 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>
运行成功后,把之前改的配置改回来就行,之前的目录是/tmp/mysql.sock,建立一个软连接连上去就可以。
ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
[root@141 sh]# mysql -uroot -p enter password: welcome to the mariadb monitor. commands end with ; or \g. your mariadb connection id is 2 server version: 5.5.35-mariadb mariadb server copyright (c) 2000, 2013, oracle, monty program ab and others. type 'help;' or '\h' for help. type '\c' to clear the current input statement.
成功!