本帖最后由 zhaorong 于 2018-6-25 15:28 编辑
问题一、忘记密码
- [root@141 sh]# mysql -uroot -p
- Enter password:
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
复制代码
解决方案:
在配置文件中选择免密登录:
- [code][code][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.
复制代码
成功!