---
title: "MySql 一些错误记录"
author: "征客丶"
date: "2018-03-11T13:18:18Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2018-05-13T20:47:59Z"
id: 2412768
url: "https://binary-space.iteye.com/blog/2412768"
---

一、MySql 启动配置文件 my.cnf
windos 下 my.ini，linux与mac下: my.cnf；这个文件可能在安装时会自动创建，也可能需要你手动创建。
----- linux 系统按以下顺序查找这个 my.cnf 文件 
/etc/my.cnf	                        Global options 
/etc/mysql/my.cnf	                Global options (as of MySQL 5.1.15) 
SYSCONFDIR/my.cnf	        Global options 
$MYSQL_HOME/my.cnf   Server-specific options 
defaults-extra-file	                The file specified with--defaults-extra-file=path  
~/my.cnf	                                User-specific options 
---- mac系统会在 /etc下查找，所以需要把这个 my.cnf文件拷贝到 /etc下。 

二、连接报错：ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 
原因：没有找 /tmp/mysql.sock 文件；
添加指向 mysql.sock 的连接文件
>ln -s /mysql.sock  /tmp/mysql.sock 
mysql.sock 在安装目录下或你在 my.cnf 中配置的目录 
socket = mysql5.6Dir/tmp/mysql.sock 【数据连接文件】 
【注意 mysql.sock 文件是在 mysql 启动后才会生成，关闭mysql 时这个文件会删除掉】

三、远程连接报错： ERROR 1130 (HY000): Host '192.168.1.123' is not allowed to connect to this MySQL server 
原因：这个是由于 mysql 服务不允许些用户从这个 ip 登录； 
解决方法：两个，一赋与权限，二 修改系统表； 
1、赋与权限，在mysql服务器上登录mysql后进行如下操作： 
mysql> GRANT ALL PRIVILEGES ON  TO @'' IDENTIFIED BY 'UserPassword' WITH GRANT OPTION; 
例： 允许用户从任何ip的主机连接到mysql服务器 
mysql> GRANT ALL PRIVILEGES ON *.* TO  'admin'@'%' IDENTIFIED BY 'admin' WITH GRANT OPTION; 
注：dataBaseName 是指让用户可以使用服务中的哪个实例，如果为所有实例请用 *.*; 
2、修改系统表； 
在mysql服务器上登录mysql后进行如下操作： 
mysql> use mysql; 
mysql> update user set host='ip' where user='root' and host='localhost'; 
mysql> flush privileges; 
你可以向表 user 中插入一条你自己指定权限的数据，host: ip  Can't start server: Bind on TCP/IP port: Address already in use
端口被占用

七、首次登录
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
首次登录需要重置密码