mysql 2027错误解决_Mysql常见报错解决方法

一:登录报错

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

mysql日志文件总结此问题的整体步骤如下:

第一步:修改pid路径

查看日志文件中错误信息:

cat /var/log/mysqld.log

2013-10-26 16:39:34 3712 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)

2013-10-26 16:39:34 3712 [ERROR] Can't start server: can't create PID file: No such file or directory

原因:

mysql 用户没有操作/var/run目录的权限,所以pid文件无法创建,导致登陆时无法建立 进程信息文件,登陆进程就无法开启,自然无法登陆。

解决:

修改 /etc/my.conf

原来为:

#pid-file=/var/run/mysqld/mysqld.pid

修改为

pid-file=/var/lib/mysql/mysqlid.pid

检查发现,mysql用户根本无法cd到/var/run/。修改为mysql可以有权限的目录后再执行mysql就进入数据库了。

第二步:修改数据库默认密码

/etc/init.d/mysql stop   (service mysqld stop)

/usr/bin/mysqld_safe --skip-grant-tables

另外开个SSH连接

[root@localhost ~]# mysql

mysql>use mysql

mysql>update user set password=password("123456") where user="root";

mysql>flush privileges;

mysql>exit

然后

[mysql@localhost etc]$ ps -A | grep mysql

4532 pts/0    00:00:00 mysqld_safe

5542 pts/0    00:00:00 mysqld

[mysql@localhost etc]$ kill -9 4532 5542

正常启动 MySQL:/etc/init.d/mysql start   (service mysqld start)

第三步:

登陆ok。 mysql -uroot -p

二:远程登录mysql数据库报错

ERROR 1130 (HY000): Host '192.168.76.50' is not allowed to connect to this MySQL server

1.改表法。

可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

mysql -u root -pTalent123

mysql>use mysql;

mysql>update user set host = '%' where user = 'root';

mysql>select host, user from user;

mysql> flush privileges;

2.授权法。

例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

如果你想允许用户myuser从ip为192.168.1.3的主机连接到mysql服务器,并使用mypassword作为密码

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY

'mypassword' WITH GRANT OPTION;

三:创建普通用户后无法在本地登录

[root@jcfx-4 ~]#mysql -h192.168.76.73 -usalt -psalt

ERROR 1045 (28000): Access denied for user 'salt'@'jcfx-4' (using password: YES)

通过查看user表发现localhost对应的是空密码,所以这是导致不能再本地登录的根本原因:

mysql> select host,user,password from mysql.user;

cef21a0a329298f37deda5369d3c30d3.png

解决方法:

mysql> grant select,insert,update,delete on salt.* to salt@"localhost" identified by "salt";

Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

四:mysql登录报错:

[root@patronus2 bin]# mysql

-bash: mysql: command not found

解决方法:

ln -s /usr/local/mysql/bin/mysql /usr/bin

五:设置字符集

Server version: 5.6.21 MySQL

character_set_server=utf8

注:遇到异常情况,通过上面列举的办法应该是可以解决;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值