【Linux】【mysql】mysql8.0开启远程访问及常见问题

1.连接数据库

复制代码
 1 [root@localhost ~]# mysql -uroot -p
 2 Enter password: 
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.
 4 Your MySQL connection id is 17
 5 Server version: 8.0.17 MySQL Community Server - GPL
 6 
 7 Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
 8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14 
15 mysql> 
复制代码

2.在mysql8版本中更改用户密码需要加入with mysql_native_password

1 mysql>  alter user 'root'@'localhost' identified with mysql_native_password by '***
';
2 Query OK, 0 rows affected (0.04 sec)

3.修改root用户的host为‘%’

复制代码
 1 mysql> show databases;
 2 +--------------------+
 3 | Database           |
 4 +--------------------+
 5 | information_schema |
 6 | mysql              |
 7 | performance_schema |
 8 | sys                |
 9 +--------------------+
10 4 rows in set (0.01 sec)
11 
12 mysql> use mysql;
13 Reading table information for completion of table and column names
14 You can turn off this feature to get a quicker startup with -A
15 
16 Database changed
17 
18 mysql> select user,host from user;
19 +------------------+-----------+
20 | user             | host      |
21 +------------------+-----------+
22 | mysql.infoschema | localhost |
23 | mysql.session    | localhost |
24 | mysql.sys        | localhost |
25 | root             | localhost |
26 +------------------+-----------+
27 4 rows in set (0.00 sec)
28 
29 mysql> update user set host = '%' where user = 'root';
30 Query OK, 1 row affected (0.00 sec)
31 Rows matched: 1  Changed: 1  Warnings: 0
32 
33 mysql> flush privileges;
34 Query OK, 0 rows affected (0.00 sec)
复制代码

再查看root用户的host

复制代码
 1 mysql> select user,host from user;
 2 +------------------+-----------+
 3 | user             | host      |
 4 +------------------+-----------+
 5 | root             | %         |
 6 | mysql.infoschema | localhost |
 7 | mysql.session    | localhost |
 8 | mysql.sys        | localhost |
 9 +------------------+-----------+
10 4 rows in set (0.01 sec)
复制代码

至此,root用户的远程访问已开启。

4.测试下navicat连接

 

 连接成功!

常见问题解决

1.解决sql_mode=only_full_group_by问题

[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'mingbyte.u.USER_ID' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

连接数据库,通过  select version(), @@sql_mode; 查看mode

复制代码
 1 [root@localhost ~]# mysql -uroot -p
 2 Enter password: 
 3 Welcome to the MySQL monitor.  Commands end with ; or \g.
 4 Your MySQL connection id is 89
 5 Server version: 8.0.17 MySQL Community Server - GPL
 6 
 7 Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
 8 
 9 Oracle is a registered trademark of Oracle Corporation and/or its
10 affiliates. Other names may be trademarks of their respective
11 owners.
12 
13 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
14 
15 mysql> select version(), @@sql_mode;
16 +-----------+-----------------------------------------------------------------------------------------------------------------------+
17 | version() | @@sql_mode                                                                                                            |
18 +-----------+-----------------------------------------------------------------------------------------------------------------------+
19 | 8.0.17    | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
20 +-----------+-----------------------------------------------------------------------------------------------------------------------+
21 1 row in set (0.00 sec)
22 
23 mysql> 
复制代码

发现上文中查看的mode中有ONLY_FULL_GROUP_BY。将其删除

sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

修改mysql的配置文件,重启依旧生效

  • vi /etc/my.cnf

上述sql_mode插入[mysqld]下方,保存,重启数据库,问题解决。

或者

1 mysql> set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
2 Query OK, 0 rows affected (0.01 sec)
3 
4 mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
5 Query OK, 0 rows affected (0.00 sec)

问题解决。

 

posted @     阅读(3329)  评论(1编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示