Centos7-安装mysql运行报错,can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

  1. 云栖社区>
  2. 博客>
  3. 正文

Centos7-安装mysql运行报错,can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

论尽先生 2018-10-23 22:52:40 浏览401 评论0

摘要: 本文转载,向高手致敬! 1、安装YUM Repo 由于CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件。 wget https://dev.mysql.com/get/mysql57-community-release-el7-9.

本文转载,向高手致敬!

1、安装YUM Repo

由于CentOS 的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件。

wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

然后进行repo的安装:

rpm -ivh mysql57-community-release-el7-9.noarch.rpm

执行完成后会在/etc/yum.repos.d/目录下生成两个repo文件mysql-community.repo mysql-community-source.repo

2、安装MySQL

使用yum命令即可完成安装

yum install mysql-server

启动msyql:

systemctl start mysqld #启动MySQL

配置MySQL

获取安装时的临时密码:

grep 'temporary password' /var/log/mysqld.log

登录:

mysql -u root -p

划重点:如果中途报错:can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

1.删除原来安装过的mysql残留的数据(这一步非常重要,问题就出在这)

rm -rf /var/lib/mysql

2.重启mysqld服务

systemctl restart mysqld

3.再去找临时密码

grep 'temporary password' /var/log/mysqld.log

登录成功后修改密码:

set password=password("yourpassword");

设置安全选项:

mysql_secure_installation

其他设置:

systemctl stop mysqld #关闭MySQL
systemctl restart mysqld #重启MySQL
systemctl status mysqld #查看MySQL运行状态
systemctl enable mysqld #设置开机启动
systemctl disable mysqld #关闭开机启动

请执行

【云栖快讯】一站式开发者服务,海量学习资源免费学  详情请点击

网友评论