MYSQL 连接 技术教程文章

开启MySQL远程访问权限 允许远程连接

1、登陆mysql数据库 mysql -u root -p 查看user表mysql> use mysql;Database changedmysql> select host,user,password from user;+--------------+------+-------------------------------------------+| host | user | password |+--------------+------+-------------------------------------------+| localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |...

解决Navicat远程连接mysql很慢的方法

ubuntu 下 /etc/mysql/mysql.conf.d [mysqld]skip-name-resolve 增加该字段即可 如果增加该字段,这无法使用本地ip进行登入, 登陆到MySql服务器,执行下面的语句为所有ip赋予权限。 grant all privileges on *.* to root@% identified by xxx;其中.的意思是 所有库.所有表, ‘root’@’%’ identified by ‘xxx’的前一个root是用户名,%是指所有访问ip,xxx是指密码。 然后再执行下面的语句,用来刷新权限。 flush privileges;...

MySQL--批量KILL连接【代码】

============================================== 使用SELECT INTO OUTFILE方式获取到要删除的连接ID并保存为文件,在通过SOURCE执行## 查看kill_id文件是否存在 system cat /tmp/kill_id.sql## 如果文件存在,则先删除 system sudo rm -rf /tmp/kill_id.sql## 将所有sleep的回话拼成KILL 脚本导入到文件 SELECT CONCAT(kill ,ID,;) FROM `information_schema`.`PROCESSLIST` t WHERE t.`COMMAND` IN (Sleep) AND t.`TIME`>2 AND ...

mysql连接出现问题记录【代码】【图】

解决:Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone valu//报错信息Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone ...

远程连接mongodb和Mysql数据库时出现“由于目标计算机积极拒绝,无法连接”的解决方法【代码】

一、配置修改 Mongodb:若要开放远程连接,在MongoDB的配置文件中将bindIp从127.0.0.1修改为0.0.0.0即可,MongoDB的配置文件的目录为/etc/mongod.conf。 Mysql:Mysql比较复杂,首先,cd /etc/mysql/mysql.conf.d,打开 mysqld.cnf文件,将[mysqld]下的bind-address = 127.0.0.1加#注释掉,然后/etc/init.d/mysql restart 重启mysql服务。 然后,添加授权用户,在mysql中: mysql>grant all privileges on *.* to '用户名'@'%' ide...

jdbc连接mysql问题【图】

我导致这个错误是因为直接从maven库中复制粘贴了 mysql-connector-java 。上网重下一个即可 jdbc连接mysql数据库常见问题,参考:https://blog.csdn.net/hurtcat/article/details/82150976

【MySQL数据库】使用Navicat Premium 12连接出现1130-host ... is not allowed to connect to this MySql server

使用Navicat Premium 12工具连接MySQL数据库经常会出现1130-host ... is not allowed to connect to this MySql server,的错误,每次都会去百度,谷歌查,但是每一篇的文章解决方法都不一样,不过最后都解决了,但是解决了过段时间又会忘,SO,查的比较繁琐!今晚又遇到了,所以记录一下。 解决方法: 直接改表: mysql -u root -pvmwaremysql>use mysql; # 进入mysql库mysql>update user set host = '%' where user ...

详解mysql数据库的左连接、右连接、内连接的区别

一般所说的左连接,外连接是指左外连接,右外连接。做个简单的测试你看吧。 先说左外连接和右外连接: [TEST1@orcl#16-12月-11] SQL>select * from t1;ID NAME ---------- --------------------1 aaa2 bbb[TEST1@orcl#16-12月-11] SQL>select * from t2;ID AGE ---------- ----------1 203 30 左外连接: [TEST1@orcl#16-12月-11] SQL>select * from t1 left join t2 on t1.id=t2.id;ID NAME ...

[ 转载 ] Mysql 远程连接+开放80和3306端口 常用配置

直接上方法: 首先配置CentOS下防火墙iptables规则:# vim /etc/sysconfig/iptables向其中加入下列规则:-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT -A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT说明:防火墙开放http用的80端口和连接MySql的3306端口。# service iptables restart然后配置MySQL允许远程登陆:...

SpringBoot整合JdbcTemplate连接Mysql【代码】

import java.io.IOException;import javax.sql.DataSource;import org.apache.ignite.IgniteSystemProperties; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.jdbc.core.JdbcTemplate; im...

通过Navicat for MySQL远程连接的时候报错mysql 1130的解决方法【图】

今天在用远程连接Mysql服务器的数据库,不管怎么弄都是连接不到。错误代码是1130,ERROR 1130: Host X.X.X.X is not allowed to connect to this MySQL server 猜想是无法给远程连接的用户权限问题。结果这样子操作mysql库,即可解决。 在服务器登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “host” 项,从”localhost”改称%。 下面是用SQL语句解决问题: mysql -u root -p mysql;use mysql; mysql;select host fr...

(三)设置mysql允许外部IP连接的解决方法及遇到的坑说明【代码】【图】

用命令查询端口情况:netstat -an | grep LISTEN 发现mysql用到3306这个端口,只能被127.0.0.1访问(0.0.0.0的就是每个IP都有的服务,写明哪个IP的就是绑定那个IP的服务) 网上查了一下默认情况下mysql只允许本地进入设置,如果需要外部IP连接到mysql,需要向mysql数据库里的“user”表里添加相关授权。 具体步骤: 1.授权mysql>GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%′ IDENTIFIED BY ‘newpwd’ WITH GRANT OPTION; 2...

mysql 连接02

public static void main(String[] args){Class.forName("com.mysql.jdbc.Driver");Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?characterEncoding=utf-8","root","root");String sql="select * from film";PrepareStatement pt=conn.prepareStatement(sql);ResultSet rs=pt.executeQuery();if(rs.next()){System.out.println("数据库连接成功");}rs.close();pt.close();conn.close(); }

Navicat for MySQL无法连接本地的MySQL服务(因为本地没有启动SQL服务导致)【图】

Navicat for MySQL无法连接本地的MySQL服务,导致连接服务的时候报错如下:是因为没有启动本地sql 服务导致的,(本地设置了自动启动由于自己打游戏,腾讯后台直接关闭了该服务所以刚开机的时候能用,打了游戏就不能用了); 直接说解决方案吧,我使用的win10 打开计算机管理然后找到服务和应用程序,在里面选择服务 在右侧找到本地安装的MySQL服务点击选中,然后点击启动此服务即可!!!!

Navicat 连接mysql8.0时报错【代码】

命令 mysql -u root -p use mysql select user,host,plugin from user; alter user 'haidragon'@'%' identified with mysql_native_password by 'pass123'; select user,host,plugin from user; exit mysql.server restart (mac) 192:etc haidragon$ mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 18Server version: 8.0.15 Homebrew Copyright (c) 20...

CMD命令连接MySQL【图】

1、CMD命令进入MySQL数据库 命令:mysql -u root -p 2、显示mysql基本信息 命令:\s 3、其他指令 ? cmd命令窗口连接mysql的命令大全 ?

springboot项目中使用原生jdbc连接MySQL数据库【代码】【图】

第一步:pom.xml中添加依赖;<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId></dependency> 第二步:编写连接类package com.example.demo.controller; import java.lang.*; import java.sql.*;public class JDBCDemo {public static void main(String[] args) throws SQLException, ClassNotFoundException { // Class.forName("com.mysql.jdbc.Driver");Class.forName("com.mysql.cj.jd...

使用springboot最新版本mysql-Connector连接数据库时提示Loading class `com.mysql.jdbc.Driver'. This is deprecate【代码】

在连接数据库时,使用了最新版本的mysql-Connector,报错如下:Loading class `com.mysql.jdbc.Driver. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.解决方法:将 jdbc.driverClassName=com.mysql.jdbc.Driver 修改为jdbc.driverClassName=com.mysql.cj.jdbc.Driver

Navicat连接mysql8.0.1版本出现1251--Client does not support authentication protocol requested by server的解决【代码】

转载自:https://blog.csdn.net/XDMFC/article/details/80263215好不容易安装好mysql,但又出现了mysql客户端版本太低的问题。根据参考的这篇博客,完美的解决了该问题。 1、通过命令行进入解压的mysql根目录下。 2、登陆数据库 mysql -uroot -p 3、再输入root的密码: Enter password: ****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18 Server version: 8.0.11 MySQL Community ...

JDBC连接MYSQL【代码】

package org.spring.springboot.controller;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet; public class JDBCTest {public static void main(String[] args) throws Exception {Connection connection = null;PreparedStatement prepareStatement = null;ResultSet rs = null;try {// 加载驱动Class.forName("com.mysql.jdbc.Driver");// 获取连接Stri...