• MySQL-FAQ


    1、ERROR 1130: Host 'xxx' is not allowed to connect to this MySQL server
    远程连接mysql服务器报上述错误。
    解决方法:
    1.改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
    mysql -u root -pvmwaremysql>use mysql;mysql>update user set host = '%' where user = 'root';mysql>select host, user from user;
    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 'root'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.10.40.54' IDENTIFIED BY '123456' WITH GRANT OPTION;
    授权后记得刷新:flush privileges;
    来源: <http://chen3888015.blog.51cto.com/2693016/986841>

    2、ERROR 2019 (HY000): Can't initialize character set gbk (path: /usr/local/mysql/share/charsets/)
    搜索一下,使用“mysql --default-character-set=utf8 -u mysql -p ”可以连接上mysql。
    但是navicate for mysql仍然是不能够连接上去。
    另外,每次使用 mysql --default-character-set=utf8 -u mysql -p ”登录,也比较麻烦。
    经过搜索,发现通过修改my.cnf,指定mysql和mysqld的编码,可以解决问题。如下是mysql和mysqld两个section添加的内容,亲测有效,问题迎刃而解:
    [mysql]
    default-character-set=utf8
    [mysqld]
    character-set-server=utf8


    3、ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
    遇到这个问题时,我是可以通过lampp提供的phpMyadmin连接到mysql数据库的。所以很奇怪为什么不能在mysql服务器上登录。
    下面是解决思路,可供参考:
    先检查了自己的my.cnf。我发现我的mysql.sock是”socket          = /opt/lampp/var/mysql/mysql.sock“,所以,很奇怪,为什么报错是”/var/lib/mysql/mysql.sock“。
    所以试着使用my.cnf设置的mysql.sock连接mysql,命令如下:
    1. mysql -u root -p -S /opt/lampp/var/mysql/mysql.sock
    输入密码,OK,可以成功连上。
    现在再来寻找为何通过命令”mysql -u root -p“不能连接上mysql的原因:
    再检查是否有/var/lib/mysql/mysql.sock“这个文件。发现没有这个文件。
    那是否是因为mysql命令没有指定-S选项时,使用了默认的设置?我猜想默认设置可能是尝试从/var/lib/mysql/mysql.sock“连接mysql服务器。
    通过观察my.cnf文件,修改了[mysql]这一节的内容,添加了”socket          = /opt/lampp/var/mysql/mysql.sock“,然后重启mysql,再度使用”mysql -u root -p“重连。
    无效,仍然报同样的错误。于是返回去把刚刚添加这行删除。
    那么通过软链接创建一个可以么?试试。命令:
    1. ln -s /opt/lampp/var/mysql/mysql.sock /var/lib/mysql/mysql.sock
    OK,问题解决。可以通过”mysql -u root -p"链接到mysql服务器了。
     
    4、访问lampp的时phpMyadmin弹出非法设置
    可能是mysql设置的密码和phpMyadmin设置的密码不一致。
    4.1 首先修改mysql的密码
    1. ./mysqladmin -u root password "newpassword"
    4.2 修改phpMyadmin密码
    修改root的密码与mysql中设置的一致。
    cd /opt/lampp/phpmyadmin
    vi config.inc.php
    1. /* Authentication type and info */
    2. $cfg['Servers'][$i]['auth_type'] = 'config';
    3. $cfg['Servers'][$i]['user'] = 'root';
    4. $cfg['Servers'][$i]['password'] = 'root';
    再次访问:http://192.168.198.128/phpmyadmin/,发现已能够正常访问了。

    5、ERROR 1044 (42000): Access denied for user 'mysql'@'localhost' to database 'mysql'
    上述错误说明用户mysql没有权限访问mysql服务器的mysql库。


    6、ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
    原因:多半是用户密码不正确造成的。
    方法1:使用已有账号登录mysql重置其他账号的密码。
    1. mysql> update mysql.user set Password=PASSWORD('root') where mysql.user.User='root';
    如果你有一个具有修改密码权限的用户时,比如root,则上述命令会执行成功。否则,会返回下述错误信息:
    ERROR 1142 (42000): UPDATE command denied to user 'mysql'@'localhost' for table 'user'

    方法2:通过mysqld_safe重置密码。
    方法1不好用的话,可以试试mysqld_safe重置密码。
    下面以重置root用户的密码为例,说明重置步骤。首先停掉mysql服务,然后依次执行:
    [root@MasterRedis tmp]mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
    mysql -u root mysql
    mysql> UPDATE user SET Password=PASSWORD('root') where USER='root';
    mysql> FLUSH PRIVILEGES;
    mysql> quit
    [root@MasterRedis tmp]# service mysql restart
    [root@MasterRedis tmp]# mysql -u root -p
    执行mysql -u root -p时,在弹出“Enter password:”提示后,输入刚刚设置的密码。OK,登录进入mysql了。

    下面是输出,注意在界面上打印出
    080309 06:18:19 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
    后,输入命令mysql -u root mysql
    1. [root@MasterRedis tmp]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
    2. [1] 16202
    3. [root@MasterRedis tmp]# 080309 06:18:19 mysqld_safe Logging to '/usr/local/mysql/err.log'.
    4. 080309 06:18:19 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
    5. mysql -u root mysql
    6. Welcome to the MySQL monitor. Commands end with ; or g.
    7. Your MySQL connection id is 1
    8. Server version: 5.5.12-log Source distribution
    9. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    10. Oracle is a registered trademark of Oracle Corporation and/or its
    11. affiliates. Other names may be trademarks of their respective
    12. owners.
    13. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    14. mysql> UPDATE user SET Password=PASSWORD('root') where USER='root';
    15. Query OK, 5 rows affected (0.03 sec)
    16. Rows matched: 5 Changed: 5 Warnings: 0
    17. mysql> FLUSH PRIVILEGES;
    18. Query OK, 0 rows affected (0.00 sec)
    19. mysql> quit
    20. Bye

    21. [root@MasterRedis tmp]# service mysql restart
    22. Shutting down MySQL.080309 06:19:27 mysqld_safe mysqld from pid file /usr/local/mysql/data/MasterRedis.pid ended
    23. [确定]
    24. Starting MySQL.[确定]
    25. [1]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking
    26. [root@MasterRedis tmp]# mysql -u root -p Enter password:





  • 相关阅读:
    在CSS里加下面任何一行代码都可以解决图片之间的间隙
    MasterPage Toolbar
    图解虚拟机VMware服务自动启动
    WSUS完全部署
    DIV全屏覆盖网页
    大型架构.net平台篇(WEB层均衡负载nginx)
    组策略设置及导出导入方法[附上设置好的组策略]
    如何設定定時關機?
    gridview获取当前行索引的方法
    no suject
  • 原文地址:https://www.cnblogs.com/topplay/p/3914047.html
Copyright © 2020-2023  润新知