记录linux 安装 MYSQL 的点点滴滴

本文记录了解决MySQL连接失败的问题过程,包括安装MariaDB遇到的替代安装提示,解决socket连接失败,处理MySQL启动后权限拒绝,查找并修改默认密码,以及最终成功连接到MySQL数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1:今天当我mysql 的时候,报错: 

[root@oc2246430752 etc]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

后来,当我安装好:

yum install -y mariadb-server

提示:Package mariadb-server is obsoleted by mysql-community-server, trying to install mysql-community-server-5.7.25-1.el7.x86_64 instead

下面开始安装:mysql-community-server-5.7.25-1.el7.x86_64.rpm

2: 安装后还是同样报错:

[root@oc2246430752 etc]# mysql

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

3:看了我是mqsql 没有启动:

启动后报另外一个错:

[root@oc2246430752 init.d]# service mysqld start

Redirecting to /bin/systemctl start mysqld.service

[root@oc2246430752 init.d]# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

4:原来是密码问题,

grep 'temporary password' /var/log/mysqld.log 把密码显示出来;

mysql -uroot -p 输入默认的密码,然后修改

mysql> set password=password( "Sheng2020");  (注意是双引号)

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> select @@validate_password_length;

+----------------------------+

| @@validate_password_length |

+----------------------------+

| 8 |

+----------------------------+

1 row in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%';

+--------------------------------------+-------+

| Variable_name | Value |

+--------------------------------------+-------+

| validate_password_check_user_name | OFF |

| validate_password_dictionary_file | |

| validate_password_length | 8 |

| validate_password_mixed_case_count | 1 |

| validate_password_number_count | 1 |

| validate_password_policy | LOW |

| validate_password_special_char_count | 1 |

+--------------------------------------+-------+

7 rows in set (0.01 sec)

mysql>

下面连接数据库:[root@oc2246430752 log]# mysql

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@oc2246430752 ~]# mysql -h127.0.0.1 -uroot -pSheng2020 -P3306

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 5

Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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>

成功了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shenghuiping2001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值