一:登录报错

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;
解决方法:
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
注:遇到异常情况,通过上面列举的办法应该是可以解决;

最新文章

  1. hdu 1501 Zipper
  2. The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?,objectWrapperFactory?,reflectorFactory?,plugins?,environments?,databaseIdProv
  3. lr参数化——500户并发迭代1次 循环取5条数据
  4. 一步步学Mybatis-实现简单的分页效果逻辑 (5)
  5. 12个git实战建议和技巧
  6. ListIterator-迭代器
  7. 纯代码添加约束条件(Auto Layout)
  8. [开发环境] Ubuntu12.04 Telnet服务设置
  9. Magento网站迁移指南
  10. Android自定义控件(三)——有弹性的ListView
  11. JNDI support differences between Tibco EMS and ActiveMQ
  12. 消息队列(Message Queue)简介及其使用
  13. Building Projects with Native Code
  14. hive 函数 current_date()
  15. Base64编码和解码实现
  16. bzoj1511 [POI2006]OKR-Periods of Words kmp+乱搞
  17. --BEA官方网站(http: //www.bea.com)甲骨文已完成对该公司的收购BEA Weblogic Server 7.0x应用服务器简明安 装、配置手册 1
  18. String.Format数字格式化输出 {0:N2} {0:D2} {0:C2} (转)
  19. SHELL脚本简单的赋值与递增
  20. 例子Architecting Android…The clean way?----代码分析

热门文章

  1. Java开发工具MyEclipse的设置自动联想功能
  2. HDU 4565 So Easy!(矩阵)
  3. Java 包装类 自动装箱和拆箱
  4. velocity加减运算注意格式 ,加减号的左右都要有空格
  5. 函数xdes_get_offset
  6. sql语句记录
  7. bzoj2005: [Noi2010]能量采集
  8. LA 3708 Graveyard 墓地雕塑 NEERC 2006
  9. 【树状数组(二叉索引树)】轻院热身—candy、NYOJ-116士兵杀敌(二)
  10. Android中FragmentPagerAdapter对Fragment的缓存(一)