vieyahn2017 / iBlog

44 stars 0 forks source link

1.15 mysql定位问题收集 #348

Closed vieyahn2017 closed 3 months ago

vieyahn2017 commented 4 years ago

mysql定位问题收集

vieyahn2017 commented 4 years ago

MySQL 'localhost' (10061)解决方法

原创鱼丸与粗面 最后发布于2018-11-08 16:47:33 阅读数 680 收藏 展开 1、首先检查MySQL 服务有没有启动,如果没有启动,则要启动这个服务。

1)、查看MySQL服务是否启动的两种方法:

a)使用dos窗口查看,命令:mysql -u root -p ,然后输入密码,看是否可以登录。

b)在“运行”打开中输入:services.msc命令,查看服务开启情况。

2)、开启MySQL服务方式:

使用dos窗口,命令:net start mysql,开启服务;net stop mysql,关闭服务。

即使服务是正常启动也没有解决问题。

2、其次检查本地的hosts文件ip地址域名指向是否正常匹配

hosts文件路径:C:\Windows\System32\drivers\etc

#    127.0.0.1       localhost
#    ::1             localhost

这种就是正常的。但是问题依旧没有解决。

3、找到在mysql安装目录下的my.ini文件,检查端口是否正确。

my.ini文件路径:D:\Server\MySQL(你的安装路径,MySQL配置文件my.ini)

修改bind-address=127.0.0.1 为 bind-address=0.0.0.0 如在MySQL 5的my.ini中未发现此项,可在[mysqld]这一节中添加上这一行:bind-address = 0.0.0.

mysql赋权操作:

GRANT ALL PRIVILEGES ON . TO 'root'@'%'' IDENTIFIED BY '123456' WITH GRANT OPTION;
flush privileges;

GRANT:赋权命令 ALL PRIVILEGES:当前用户的所有权限 ON:介词 .:当前用户对所有数据库和表的相应操作权限 TO:介词 'root'@'%'':权限赋给root用户,所有ip都能连接 IDENTIFIED BY '123456':连接时输入密码,密码为123456 WITH GRANT OPTION:允许级联赋权

mysql查看当前用户权限

SHOW GRANTS [FOR user]
This statement displays the GRANT statement or statements that must be issued to duplicate the privileges that are granted to a MySQL user account. SHOW GRANTS requires the SELECT privilege for the mysql database, except to see the privileges for the current user.

To name the account, use the same format as for the GRANT statement; for example, 'jeffrey'@'localhost'. If you specify only the user name part of the account name, a host name part of '%' is used. For additional information about specifying account names, see Section 13.7.1.3, “GRANT Syntax”.

mysql> 
SHOW GRANTS FOR 'root'@'localhost';

+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
vieyahn2017 commented 4 years ago

mysql 用户及权限管理 允许远程连接

mysql,功能强大的关系型数据库,它的用户管理在开发过程中当然也尤其重要,接下来就看看mysql的用户管理

1.登录数据库

mysql -uroot -p 回车

输入密码... 回车

2.登录成功后,切换数据库

mysql>use mysql;

3.查看当前用户

mysql>select user,host from user;

这里只列举了两个字段,这张表的字段很多,一般比较关注的就这几个:

host:访问主机

user:访问用户名

plugin:认证方式(密码加密方式)

authentication_string:密码加密后的一长串字符

4.新增用户

mysql>CREATE USER 'username'@'host' IDENTIFIED BY 'password';

host:主机ip,%【任意ip】 localhost【本机】 192.168.31.22【指定ip】

IDENTIFIED BY:将密码用默认的加密方式进行加密后放入表中,不直接存放可以明码

默认的加密方式需要查一下user表中的plugin,如果客户端不支持,可以指定加密方式进行加密

mysql>CREATE USER 'username'@'host' IDENTIFIED MySqlSHA1 BY 'password';

新增后的用户默认是没有任何权限的,也就是useage,只能登陆罢了

5.查看MYSQL数据库中用户的权限 mysql>show grants for 'username'@'host';

6.用户授权 mysql>grant privileges on dbname.tabname to "username"@"host" privileges :权限,select【查询】,update【更新】,delete【删除】等等,all【所有】 这样的授权的用户就算拥有可所有权限,但是没办法管理其他用户,如果你想让这个用户可以授权其他用户,在后面再加上 with grant option. grant privileges on dbname.tabname to "username"@"host" with grant option

7.修改用户 mysql>update user set host="localhost" where user="username" user,host,plugin都可以用update语句,修改plugin之后,需要再次修改密码,否则无效,也可以在修改密码的时候指定加密方式,就不需要修改plugin 修改用户密码加密方式一般是是客户端不支持服务器这边的加密方式,才会修改的,如果支持,一般可以不修改加密方式,mysql8.0就需要修改加密方式,不然图形化工具完全没办法连接。

8.删除用户,根据用户名删除,也可以根据host mysql>delete user where user="username"

注意:允许远程就是把用户的访问地址从localhost 到 % 或者指定ip,允许了远程之后,要设置权限,否则用户就只能登录,其他的什么也不能干,当然,你想逗他玩玩,也可以,你开心就好。

9.用户操作,最后一步,更新权限

mysql>flush privileges

10.如果还是显示无法连接,查看配置文件

则需要修改配置文件。找到my.cnf,一般在/etc/mysql/下面,具体情况根据实际而定。注释掉其中的bind-address属性。如下

vieyahn2017 commented 4 years ago

In aggregated query without GROUP BY报错

记录一下关于mysql的一个报错问题解决方案:In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column ‘yunva_changke.u.user_id’; this is incompatible with sql_mode=only_full_group_by 问题描述:是因为mysql的sql_mode默认开启了only_full_group_by 模式,导致Mysql的Sql的group by规则跟Oracle类似了,所以去掉这个默认就可以了 具体方法: 1.查看sql_mode模式,如果sql_mode显示为:only_full_group_by,执行步骤二即可

mysql>show variables like ‘%sql_mode’;

mysql> show session variables like ‘%sql_mode%’;
mysql> show global variables like ‘%sql_mode%’;

2.

mysql> set global sql_mode=”;
mysql> set session sql_mode=”;

mysql查询出现In aggregated query without GROUP BY

mysql查询出现In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated c 原创沉睡一万年 最后发布于2019-03-01 11:30:34 阅读数 3073 收藏 展开 mysql查询出现In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'zhibo.a.id';

出现问题:

Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: In aggregated query without GROUP BY,expression #2 of SELECT list contains nonaggregated column 'pay.t.type'; this is incompatible with sql_mode=only_full_group_by

出现原因:

在MySQL5.7.5后,默认开启了ONLY_FULL_GROUP_BY,所以导致了之前的一些SQL无法正常执行,其实,是我们的SQL不规范造成的,因为group by 之后,返回的一些数据是不确定的,所以才会出现这个错误。

vieyahn2017 commented 4 years ago

pymysql取代MySQL-python

​import pymysql

pymysql.install_as_MySQLdb()