Mysql 问题总结


阅读次数

Mysql 已经启动但是连接错误(Mac)

报错信息:
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’

解决办法:
出现这种情况经常是因为mysql 的配置文件问题

根据不同的情况,MySQL的安装路径会有所不同
添加mysql 环境变量

export PATH="/usr/local/mysql/bin:$PATH"

在 /usr/local/etc/ 下创建或修改 my.cnf

[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
init-connect ='SET NAMES utf8'
max_allowed_packet = 64M
bind-address = 127.0.0.1
port = 3306
socket = /tmp/mysql.sock
innodb_file_per_table=1
[mysqld_safe]
timezone = '+0:00'

命令行启动

sudo /usr/local/mysql/support-files/mysql.server start


无法启动数据库‘The server quit without updating PID file’(mac)

报错信息:
ERROR! The server quit without updating PID file (/usr/local/var/mysql/localhost.local.pid).

解决办法:

这是因为文件夹权限问题

sudo chown -R _mysql:mysql /usr/local/var/mysql
or
chmod -R 777 /usr/local/var/mysql/

之后再重新启动就行了


启动进入mysql,输入语句提示 必须重置密码(mac)

报错信息:
You must reset your password using ALTER USER statement before executing this statement.

解决办法:
mysql 5.7之后安装后会生成随机密码,或者没有密码,需要我们自己重置密码

ALTER USER USER() IDENTIFIED BY 'new_password';
ALTER USER ‘root‘@‘localhost‘ PASSWORD EXPIRE NEVER;
flush privileges;

参考:
Mysql密码过期策略
Alter 语法
Mysql密码重置


">