Category Archives: MYSQL

[Solved] check the manual that corresponds to your MySQL server version

My problem is….. heck the manual that corresponds to your MySQL server version for the right syntax to use near ‘where id =?’。

String sql = "UPDATE shop_user SET password=?,nickname=?,where id=?";

It turns out that you have added an extra comma to report errors all the time

Should be

String sql = "UPDATE shop_user SET password=?,nickname=?where id=?";

36807;”3616444;”21448;”21457;” 29616; 35768;”3838382;” 39064;

2529909;”MYsql38190;” 23601;”199811;” 38190;”21862b;

ADD ALL ALTER
ANALYZE AND AS
ASC ASENSITIVE BEFORE
BETWEEN BIGINT BINARY
BLOB BOTH BY
CALL CASCADE CASE
CHANGE CHAR CHARACTER
CHECK COLLATE COLUMN
CONDITION CONNECTION CONSTRAINT
CONTINUE CONVERT CREATE
CROSS CURRENT DATE CURRENT TIME
CURRENT TIMESTAMP CURRENT USER CURSOR
DATABASE DATABASES DAY HOUR
DAY MICROSECOND DAY MINUTE DAY SECOND
DEC DECIMAL DECLARE
DEFAULT DELAYED DELETE
DESC DESCRIBE DETERMINISTIC
DISTINCT DISTINCTROW DIV
DOUBLE DROP DUAL
EACH ELSE ELSEIF
ENCLOSED ESCAPED EXISTS
EXIT EXPLAIN FALSE
FETCH FLOAT FLOAT4
FLOAT8 FOR FORCE
FOREIGN FROM FULL TEXT
GOD GRANT GROUP
HAVING HIGH PRIORITY HOUR MICROSECOND
HOUR MINUTE HOUR SECOND IF
IGNORE IN INDEX
INFILE INNER INOUT
INSENSITIVE INSERT INT
INT1 INT2 INT3
INT4 INT8 INTEGER
INTERVAL INTO IS
ITERATE JOIN KEY
KEYS KILL LABEL
LEADING LEAVE LEFT
LIKE LIMIT LINEAR
LINES LOAD LOCALTIME
LOCALTIMESTAMP LOCK LONG
LONGBLOB LONGTEXT LOOP
LOW PRIORITY MATCH MEDIUMBLOB
MEDIUMINT MEDIUMTEXT MIDDLEINT
MINUTE MICROSECOND MINUTE OF SECOND MOD
MODIFIES NATURAL NOT
NO WRITE TO BINLOG NULL NUMERIC
ON OPTIMIZE OPTION
OPTIONALLY OR ORDER
OUT OUTER OUTFILE
PRECISION PRIMARY PROCEDURE
PURGE RAID0 RANGE
READ READS REAL
REFERENCES REGEXP RELEASE
RENAME REPEAT REPLACE
REQUIRE RESTRICT RETURN
REVOKE RIGHT RLIKE
SCHEMA SCHEMAS SECOND MICROSECOND
SELECT SENSITIVE SEPARATOR
SET SHOW SMALLINT
SPATIAL SPECIFIC SQL
SQLEXCEPTION SQLSTATE SQLWARNING
SQL BIG RESULT SQL CALC FOUND ROWS SQL SMALL RESULT
SSL STARTING STRAIGHT JOIN
TABLE TERMINATED THEN
TINYBLOB TINYINT TEXT
TO TRAILING TRIGGER
TRUE UNDO UNION
UNIQUE UNLOCK UNSIGNED
UPDATE USAGE USE
USING UTC DATE UTC Time
UTC TIMESTAMP VALUES VARBINARY
VARCHAR VARCHARACTER VARYING
WHEN WHERE WHILE
WITH WRITE X509
XOR YEAR to MONTH ZEROFILL

[Solved] Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Problem description:

When the program is running and the page is refreshed, the following error occurs

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
at sun.reflect.GeneratedConstructorAccessor36.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2871)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3414)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4874)
at com.mchange.v2.c3p0.impl.NewProxyConnection.setAutoCommit(NewProxyConnection.java:912)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:83)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
… 78 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2431)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2882)

… 87 more

The above problem is caused by the configuration of the mysql database. mysql defaults its connection wait_timeout to 8 hours. The value can be viewed in its client program as follows.

mysql> show global variables like “wait_timeout”;
+—————+———+
| Variable_name | Value |
+—————+———+
| wait_timeout | 1814400 |
+—————+———+
1 row in set (0.00 sec)

If the database connection (java.sql.Connection) remains in the wait_timeout state for the duration of the wait_timeout seconds, mysql closes the connection. At this point, your Java application’s connection pool still legally holds a reference to that connection. When using that connection to perform database operations, you encounter the above error.

Solution:

1. modify the MySQL data configuration file, the Windows filename is my.ini, the path is under the MYSQL installation path; in Linux the filename is my.cnf the path is in /etc/my.cnf. modify wait_timeout = 1814400.

2. Restart the MySQL database: service mysqld restart

Solution Supplement:

1, the above solution modified the wait_timeout , but my Linux MySql version is 5.6, I tried to modify the mysql/my.cnf max_connetions = 1814400, and then tested it is also possible.

[Solved] MySQL Connect Error: Can’t connect to MySQL server on ‘ ‘(61)

There is an account TT that can’t connect to MySQL server on ‘< remote-ip>’ ( 61)

1. Check whether the user has remote login permission

mysql> SELECT User, Host FROM mysql.user;
+-----------+-----------+
| User      | Host      |
+-----------+-----------+
| tt        | %         |
| mysql.sys | localhost |
| root      | localhost |
| Laily     | %        |
| ttt       | %        |
+-----------+-----------+
5 rows in set (0.00 sec)

Obviously, TT is allowed to log in from other servers

2. Check whether MySQL server has monitored port 3306

[root@centos-linux ~]# netstat -tulpen
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       User       Inode      PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      0          16801      1507/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      0          17222      1970/master
tcp6       0      0 :::3306                 :::*                    LISTEN      27         46396      22054/mysqld
tcp6       0      0 :::22                   :::*                    LISTEN      0          16803      1507/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      0          17223      1970/master
udp        0      0 0.0.0.0:68              0.0.0.0:*                           0          49600      22999/dhclient
udp        0      0 0.0.0.0:43504           0.0.0.0:*                           0          48850      22999/dhclient
udp6       0      0 :::47875                :::*                                0          48851      22999/dhclient

I have no problem here. If I don’t monitor port 3306 or only monitor localhost (0.0.0.0 means monitor all), add the following line in My. CNF

bind-address = 0.0.0.0

3. If the server is centos7, add MySQL service to the firewall

[root@centos-linux ~]# sudo firewall-cmd --zone=public --permanent --add-service=mysql
success
[root@centos-linux ~]# sudo systemctl restart firewalld

After I restart the firewall, I can access it normally

The use of libpqxx interface in Linux solves the error of PSQL: connections on UNIX domain socket “/TMP/.S.pgsql.5432”

When using PostgreSQL database in the project, it is required to be compatible on both windows and Linux platforms. So the interface used in windows broke out an exception in Linux

psql:connections on Unix domain socket "/tmp/.s.PGSQL.5432"

After analyzing and checking the documentation the problem was solved as follows.

1. Reason: This is due to the fact that when connecting to pg under linux, the default unix domain socket method is used to connect to pg, and the port of pg is running on a non-default port (default port is 5432). Under windows the same interface uses the TCP protocol of socket to connect to pg.

2. When using pgxx::connection(“”), the string to be passed in is incomplete, resulting in a connection using the unix domain socket method under linux.

The following is the official postgresql documentation explaining.

host

Name of host to connect to.If a host name begins with a slash, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. If multiple host names are specified, each will be tried in turn in the order given. The default behavior whenhostis not specified is to connect to a Unix-domain socketin/tmp(or whatever socket directory was specified whenPostgreSQLwas built). On machines without Unix-domain sockets, the default is to connect tolocalhost.

A comma-separated list of host names is also accepted, in which case each host name in the list is tried in order.

hostaddr

Numeric IP address of host to connect to. This should be in the standard IPv4 address format, e.g.,172.28.40.9. If your machine supports IPv6, you can also use those addresses. TCP/IP communication is always used when a nonempty string is specified for this parameter.

Usinghostaddrinstead ofhostallows the application to avoid a host name look-up, which might be important in applications with time constraints. However, a host name is required for GSSAPI or SSPI authentication methods, as well as forverify-fullSSL certificate verification. The following rules are used:

Ifhostis specified withouthostaddr, a host name lookup occurs.

Ifhostaddris specified withouthost, the value forhostaddrgives the server network address. The connection attempt will fail if the authentication method requires a host name.

If bothhostandhostaddrare specified, the value forhostaddrgives the server network address. The value forhostis ignored unless the authentication method requires it, in which case it will be used as the host name.

Note that authentication is likely to fail ifhostis not the name of the server at network addresshostaddr. Also, note thathostrather thanhostaddris used to identify the connection in a password file .

A comma-separated list ofhostaddrvalues is also accepted, in which case each host in the list is tried in order. SeeSection33.1.1.3for details.

Without either a host name or host address,libpqwill connect using a local Unix-domain socket; or on machines without Unix-domain sockets, it will attempt to connect tolocalhost.

Therefore, there are 2 main things wrong with our interface.

1. std::string strConnection has a problem with string splicing when using strConnection = “dbname=”+pg_dbname+” user=”+pg_username+” password=” under windows. So when splicing the string again use

std::string strConnection = "dbname=";
strConnection += pg_dbname.c_str();
strConnection += " user=";
strConnection += pg_username.c_str();
strConnection += " password=";
strConnection += pg_password.c_str();
strConnection += " hostaddr=";
strConnection += pg_ip.c_str();
strConnection += " port=";
strConnection += pg_port.c_str();

2. It is better to add the configuration of host = localhost in the strconnection string to ensure that there is no problem

[Solved] JDBC connection to SQL Service reported an error: “the driver cannot establish a secure connection with SQL server by using SSL encryption“

1. Environment

IDE : IDEA

JDK : JAVA1.8

SQL Server Version: SQL Server 2008

2. Specific error information

2019-09-16 17:43:11 [Druid-ConnectionPool-Create-847839957] ERROR c.a.d.p.DruidDataSource - create connection SQLException, url: jdbc:sqlserver://localhost;DatabaseName=PT_STORE_HLW, errorCode 0, state 08S01
com.microsoft.sqlserver.jdbc.SQLServerException: The driver was unable to establish a secure connection to SQL Server by using Secure Socket Layer (SSL) encryption. Error: "SQL Server did not return a response. The connection was closed. ClientConnectionId:22dc49b0-221d-4a51-9a84-8d507658df6e”。
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)
	at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1668)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1323)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
	at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156)
	at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218)
	at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1560)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2468)
Caused by: java.io.IOException: SQL Server No response returned. The connection is closed. ClientConnectionId:22dc49b0-221d-4a51-9a84-8d507658df6e
	at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.ensureSSLPayload(IOBuffer.java:651)
	at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.readInternal(IOBuffer.java:708)
	at com.microsoft.sqlserver.jdbc.TDSChannel$SSLHandshakeInputStream.read(IOBuffer.java:700)
	at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.readInternal(IOBuffer.java:895)
	at com.microsoft.sqlserver.jdbc.TDSChannel$ProxyInputStream.read(IOBuffer.java:883)
	at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
	at sun.security.ssl.InputRecord.read(InputRecord.java:503)
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
	at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1618)
	... 10 common frames omitted

Solution process:

On the Internet, some Baidu said it was because of the problem of JDK1.6, but I used JDK1.8

It is also said that JRE lacks two jar packages, which is not the reason after trying

Solution:

In JDK 8 and earlier, edit the/lib/security/Java. Security file and create 3DES_ EDE_ CBC is removed from the jdk.tls.legacyalgorithms security attribute

Remove 3DES from Java. Security under JDK_EDE_CBC can connect SQL Server with JDBC

In Java 8, the encryption suite is disabled by default: “SSL”_ RSA_ WITH_ 3DES_ EDE_ CBC_ Sha ”
and then to connect successfully, open SSL_ RSA_ WITH_ 3DES_ EDE_ CBC_ The answer is:
open folder (Java)_ Security policy file in home/JRE/lib/Security: Java. Security
Modify JDK. TLS. Disabledalgorithms option jdk.tls.disabledalgorithms = MD5, SSLv3, DSA, RSA keysize & lt; 2048
jdk.tls.disabledAlgorithms=SSLv3, RC4, MD5withRSA, DH keySize < 1024,
EC keySize < 224, DES40_CBC, RC4_ 40,3DES_ EDE_ CBC

To enable SSL_RSA_WITH_3DES_EDE_CBC_Sha, will 3DES_EDE_CBC notes out:

Default values of jdk.tls.disabledalgorithms in Java 8:
jdk.tls.disabledalgorithms = MD5, SSLv3, DSA, RSA keysize < 2048
jdk.tls.disabledAlgorithms=SSLv3, RC4, MD5withRSA, DH keySize < 1024,
EC keySize < 224, DES40_CBC, RC4_40
#,3DES_EDE_CBC

[Solved] Postgres Error: template1 is being accessed by other users

When the developer creates a Postgres database on a development machine, an error is reported. Create database statement:

CREATE DATABASE temp_kenyon
  WITH OWNER = postgres
       ENCODING = 'UTF8'
       TABLESPACE = pg_default
       LC_COLLATE = 'C'
       LC_CTYPE = 'C'
       CONNECTION LIMIT = -1;

Error information:

ERROR:  source database "template1" is being accessed by other users
DETAIL:  There are 1 other session(s) using the database.

********** ERROR **********

ERROR: source database "template1" is being accessed by other users
SQL STATUS: 55006
More:There are 1 other session(s) using the database.

Analysis: the error prompt is obvious. There is another session connected to template1, and this is the template library. PG does not allow other connections when creating a new library

 

 

solutions:

1. Use another template library template0 of PG

[postgres@kenyon  ~]$ createdb -T template0 tets_kenyon -p 5432
Password: 
[postgres@kenyon  ~]$ psql -p 5432
Password: 
psql (9.1.2)
Type "help" for help.

postgres=# \l
                              List of databases
    Name     |  Owner   | Encoding | Collate | Ctype |   Access privileges   
-------------+----------+----------+---------+-------+-----------------------
 postgres    | postgres | UTF8     | C       | C     | 
 template0   | postgres | UTF8     | C       | C     | =c/postgres          +
             |          |          |         |       | postgres=CTc/postgres
 template1   | postgres | UTF8     | C       | C     | =c/postgres          +
             |          |          |         |       | postgres=CTc/postgres
 testof      | postgres | UTF8     | C       | C     | 
 tets_kenyon | postgres | UTF8     | C       | C     | 
(6 rows)

postgres=# drop database test_kenyon;
ERROR:  database "test_kenyon" does not exist
postgres=# drop database tets_kenyon;
DROP DATABASE

2. Kill the process connected to template1 and execute the database building statement again

postgres=# select procpid from pg_stat_activity where DATNAME = 'template1';
 procpid 
---------
   8879
postgres=# \q
[postgres@kenyon  ~]$ kill 8879

CREATE DATABASE blacktea
  WITH OWNER = postgres
       ENCODING = 'UTF8'
       TABLESPACE = pg_default
       LC_COLLATE = 'C'
       LC_CTYPE = 'C'
       CONNECTION LIMIT = -1;

It works.

 

With template library template0 and template1 and database view PG_ Description of database

1. When the database initialization is installed, template0 and template1 are the same, a clean library and the same content

2. After initialization, users can customize template1, such as adding a new user-defined function. When creating a new library, the user-defined function will be attached without creating it in the new library

3. Generally, it is not allowed to operate on template0 to ensure that it is a clean database, which is helpful for database recovery. When building a new database, you can specify template0 as the template to create a clean new database

4. When creating a new library, you cannot connect to a new session. If a new session is connected to the template library, the creation will fail, as shown in the above example

5. View PG_ Description of main fields of database

postgres=# \d pg_database;
    Table "pg_catalog.pg_database"
    Column     |   Type    | Modifiers 
---------------+-----------+-----------
 datname       | name      | not null
 datdba        | oid       | not null
 encoding      | integer   | not null
 datcollate    | name      | not null
 datctype      | name      | not null
 datistemplate | boolean   | not null
 datallowconn  | boolean   | not null
 datconnlimit  | integer   | not null
 datlastsysoid | oid       | not null
 datfrozenxid  | xid       | not null
 dattablespace | oid       | not null
 datacl        | aclitem[] | 
Indexes:
    "pg_database_datname_index" UNIQUE, btree (datname), tablespace "pg_global"
    "pg_database_oid_index" UNIQUE, btree (oid), tablespace "pg_global"
Tablespace: "pg_global"

Datistemplate: can it be used as a template?If it is true, any user with created B can create it. Generally, the value of user database is false

Datallowconn indicates whether the connection is allowed. Template0 generally does not allow the connection. Other databases can be connected

Datconnlimit means connection limit, – 1 means no limit

[How to Solve] nodejs mysql ER_NOT_SUPPORTED_AUTH_MODE

1. Problem description

A MySQL service is started locally using docker compose. The default image tag is latest. The yaml file is as follows:

## Resource files required for local development
version: '3'
services:
  ### mysql (https://hub.docker.com/_/mysql/)
  db_mysql:
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: 1qaz
      TZ: Asia/Shanghai
    image: mysql
    ports:
      - 3306:3306
    restart: always

Nodejs uses typeorm and the following configuration to link to local MySQL:

DB_TYPE=mysql
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=1qaz
DB_DATABASE=test
DB_SYNC=true

Bootloader reported an error:

{ Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    at Handshake.Sequence._packetToError (/usr/src/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
... ...

Problem definition: permission verification error occurred when MySQL client links to MySQL server

2. Problem investigation

MySQL 8.0 – Client does not support authentication protocol requested by server; Consider upgrading MySQL client: the scheme actually executes SQL script, but does not work

ER_ NOT_ SUPPORTED_ AUTH_ Mode after upgrade: this solution also implements SQL to modify the root user’s permission. It is easy to use after many attempts on GitHub. This solution is adopted, and the result is work. This problem is solved

ER_ NOT_ SUPPORTED_ AUTH_ Mode – MySQL server: this solution is not very safe and the problem has been solved in the previous step, but not adopted

Root cause: the client driver of MySQL only supports mysql_ native_ password/mysql_ old_ Password authentication mode, and the default authentication mode after 5.7 is: plugin. MySQL provides two plug-ins:

sha256_ password: Implements basic SHA-256 authentication

caching_ sha2_ password: Implements SHA-256 authentication (like sha256_ password), but uses caching on the server side for better performance and has additional features for wider applicability

Mysql8.0 uses caching by default_ sha2_ Password instead of MySQL_ native_ Password , our solution is to modify the root authentication mode from caching_ sha2_ Password is the traditional mysql_ native_ password.

By querying user information:

mysql> select Host,User,plugin,authentication_string from user where User='root'\G
*************************** 1. row ***************************
                 Host: localhost
                 User: root
               plugin: auth_socket
authentication_string: 
1 row in set (0.00 sec)

In essence, client driver should support auth_ socket.

3. Solutions

Scheme 1: link to MySQL server and execute the following command:

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; 
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Scheme 2: set the docker startup command and use native password

  db_mysql:
    container_name: mysql
    environment:
      MYSQL_ROOT_PASSWORD: 1qaz
      TZ: Asia/Shanghai
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    ports:
      - 3306:3306
    restart: always

Restart nodejs service without errors, problem solved!

[Solved] MySQL ERROR 2003 (HY000): Can’t connect to MySQL server on ‘localhost’ (10061)

 

MySQL display error 2003 (HY000): can’t connect to MySQL server on ‘localhost’ (10061) solution

solution: the first step is to enter the bin directory of MySQL

cd C:\Program Files\MySQL\MySQL Server 5.5\bin

Input:

mysqld --skip-grant-tables

Open a new CMD, and then enter the bin directory:

cd C:\Program Files\MySQL\MySQL Server 5.5\bin

Input:

mysql -uroot

The problem has to be solved

[Solved] MYSQL ERROR 1290 (HY000): The MySQL server is running with the –secure-file-priv option so it cannot e…

Today, when I was learning MySQL, I wanted to import the data from the text file into the database, but I found that I kept getting errors, and I changed the path to import the text and still got the same error, the error showed ERROR 1290 (HY000): The MySQL server is running with the –secure- file-priv option so it cannot execute this statement.

select ….. .into outfile is a logical backup method that can be restored very fast, faster than inserting. It only backs up the data in the table and does not include the structure of the table.

The reason for the error is that after MySQL 5.7.6, the import file can only be in the folder specified by secure_file_priv (also because of insufficient permissions)

Method 1.

We can use the show variables like ‘%secure%’; command to display the file directory

This will place the imported files in the /var/lib/mysql-files/ folder, and then import them from there.

When you export the files, you will also export the files to this folder.

root@localhost:mysql3306.sock [(none)]>show global variables like ‘%secure%’;
+————————–+—————————-+
| Variable_name | Value |
+————————–+—————————-+
| require_secure_transport | OFF |
| secure_auth | ON |
| secure_file_priv | /data/mysql/mysql3306/tmp/ |

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

root@localhost:mysql3306.sock [(none)]>select * from qt into outfile ‘/data/mysql/mysql3306/tmp/qt.sql’;
ERROR 1046 (3D000): No database selected
root@localhost:mysql3306.sock [(none)]>select * from qq.qt into outfile ‘/data/mysql/mysql3306/tmp/qt.sql’;
Query OK, 8 rows affected (0.01 sec)

[root@node1 ~]# cd /data/mysql/mysql3306/tmp/
[root@node1 tmp]# ll
total 4
-rw-rw-rw- 1 mysql mysql 56 Aug 13 06:06 qt.sql
[root@node1 tmp]# pwd
/data/mysql/mysql3306/tmp

Recovery.

root@localhost:mysql3306.sock [(none)]>use qq;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
root@localhost:mysql3306.sock [qq]>select * from qt;
Empty set (0.01 sec)

root@localhost:mysql3306.sock [qq]>LOAD DATA INFILE ‘/data/mysql/mysql3306/tmp/qt.sql’ into table qq qt;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘qt’ at line 1
root@localhost:mysql3306.sock [qq]>LOAD DATA INFILE ‘/data/mysql/mysql3306/tmp/qt.sql’ into table qq.qt;
Query OK, 8 rows affected (0.00 sec)
Records: 8 Deleted: 0 Skipped: 0 Warnings: 0

root@localhost:mysql3306.sock [qq]>

If it shows ERROR 1261 (01000): Row 1 doesn’t contain data for all columns
This error is because the data rows do not match and cannot be empty by default, use the following command to solve set sql_modul = 0;