ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (40) 请先启动mysql服务,可执行如下命令 /etc/init.d/mysql start 此时再去使用mysql zhw@debian:~$ mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.35 MySQL Community Server (GPL) Copyright (c) 2000, 2021, Oracle and/or its affiliates. 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> 安装成功。 6.启动,停止,重启 $sudo service mysql start $ sudo service mysql stop $ sudo service mysql restart 7.卸载(参考) $ sudo apt-get --purge remove mysql-server $ sudo apt-get --purge remove mysql-client $ sudo apt-get --purge remove mysql-common 最后再通过下面的命令清理残余 $ sudo apt-get autoremove $ sudo apt-get autoclean $ sudo rm /etc/mysql/ -R $ sudo rm /var/lib/mysql/ -R ============================= 正文内容========================= 一、下载安装程序 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-server_5.7.36-1debian10_amd64.deb-bundle.tar 二、程序解压 tar -xvf mysql-server_5.7.36-1debian10_amd64.deb-bundle.tar 三、依次依赖程序 apt install psmisc libaio1 libnuma1 libatomic1 libmecab2 四、安装MySQL程序(需要按照顺序依次安装) dpkg -i mysql-common_5.7.35-1debian10_amd64.deb dpkg -i mysql-community-client_5.7.35-1debian10_amd64.deb dpkg -i mysql-client_5.7.35-1debian10_amd64.deb dpkg -i mysql-community-server_5.7.35-1debian10_amd64.deb # 期间会提示输入密码, 并确认密码 dpkg -i mysql-server_5.7.35-1debian10_amd64.deb 五、修改相关配置 # 1.允许远程访问, 修改bind-address的值为0.0.0.0 # 2.配置数据库默认字符集,新增参数character-set-server=utf8 vim /etc/mysql/mysql.conf.d/mysqld.cnf bind-address = 0.0.0.0 character-set-server=utf8 # 配置客户端默认字符集,新增参数default-character-set=utf8 vim /etc/mysql/conf.d/mysql.cnf default-character-set=utf8 # 执行赋权语句并刷新生效,在进入mysql环境后执行! GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION; FLUSH PRIVILEGES; # 查看字符集 show variables like '%character%'; 六、配置定时备份任务(定时备份参考示例) #!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin #数据库用户名 db_user=root #数据库密码 db_password=******** #数据库名称 db_name=db_name #备份存放路径 backup_dir=/var/data_backup #备份命名所使用的日期格式 date=$(date +%Y%m%d_%H%M%S) #导出备份 mysqldump -u$db_user -p$db_password $db_name>$backup_dir/$db_name$date.sql #对备份进行压缩: mysqldump -u$db_user -p$db_password $db_name gzip >$backup_dir/$db_name$date.sql.gz