Category Archives: MYSQL

[Solved] MYSQL Remote Connect Error: ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

1. Enter the container

Docker exec – it [MySQL container name]/bin/Bash

2. Log in to MySQL

mysql -uroot -p

Password: [enter your password] or enter directly

3. Execute the following command:

use MySQL;

4. Authorization
grant all privileges on ** to ‘root’@’%’ identified by ‘yourPassword’;

5. Refresh

Flush privileges;

[Solved] MYSQL Export Sheet Error: –secure-file-priv option so it cannot execute this statement

When MySQL exports a file, the following is displayed:

mysql> select * from users into outfile '/root/users.txt';
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

The reason is not clear. It is said on the Internet that operations like into are only allowed to users with file permission. In short, it is about permissions. Here we need to use a table that stores the system parameters of MySQL:

mysql> show variables like 'secure_file_priv';
+------------------+-----------------------+
| Variable_name    | Value                 |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.01 sec)

Here, my secure_file_priv field has a value and is fixed in /var/lib/mysql-files/, which means that Mysql export data can only be exported to this directory, and export is not authorized in other places:

mysql> select * from users into outfile '/var/lib/mysql-files/users.txt';
Query OK, 6 rows affected (0.00 sec)

The value of the secure_file_priv field here can be set (I don’t know how to change it, Baidu myself)

  • If it is empty, the variable is invalid and can be exported without restriction. This is not a safe setting
  • If set to the name of a directory, the server will restrict import and export operations to only process files in that directory. The directory must exist; the server will not create it.
  • If set to NULL, the server will disable import and export operations.

Modify system variables

mysql> set global secure_file_priv = ''; 
ERROR 1238 (HY000): Variable 'secure_file_priv' is a read only variable //
Directly modify the display read only, so you can only start from the configuration file

Open another window and directly modify the configuration file my.cnf. I have omitted a lot of comments here. When making changes, please note that you cannot directly add secure_file_priv=” to the last line. This is incorrect, because the last line is in the [mysql] column. Variables need to be added under [mysqld]

[root@VM-0-7-centos mysql-files]# vim /etc/my.cnf
……
[mysqld]
……

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
……
secure_file_priv = ''   //correct position added here, [ mysqld ] in which
[mysqld_safe] 
…… 
[mysql]
……

Restart MySQL service after adding

[root@VM-0-7-centos mysql-files]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

After restarting, log in to MySQL again and find that it has been changed:

mysql> show variables like 'secure_file_priv';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| secure_file_priv |       |
+------------------+-------+
1 row in set (0.00 sec)

[Solved] SELECT list is not in GROUP BY clause and contains nonaggregated

[questions]

[reason]

MySQL 5.7.5 and above functions depend on the detection function. If the ONLY_FULL_GROUP_BY SQL mode is enabled (by default), MySQL will reject select lists, HAVING conditions, or ORDER BY list queries that reference non-aggregate columns that are neither named in the GROUP BY clause, nor are they functionally dependent on them. (Before 5.7.5, MySQL did not detect the functional dependency, ONLY_FULL_GROUP_BY is not enabled by default. For instructions on the behavior before 5.7.5, please refer to the “MySQL 5.6 Reference Manual”.) The following solution is not the final solution, The error is only blocked, but the problem still exists.

The result of looking for a long time is the mysql5.7 database reason! !

[solution]

Open navcat and query with SQL:

First:

select @@global.sql_mode;

Query whether  ONLY_FULL_GROUP_BY exists. If it exists, reset the value (in fact, delete ONLY_FULL_GROUP_BY).

set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

Then there’s no problem.

[Solved] MYSQL Command gruop by Error: this is incompatible with sql_mode=only_full_group_by

Error Messages:
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘student.name’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Check the version of MYSQL

select version();

View the Content in SQL_mode

select @@GLOBAL.sql_mode;

Reason:

The only_full_group_by option is enabled by default in mysql5.7 and above. My version is mysql5.7.27

Take a look at the syntax of group by:

select select the column in the group + aggregate function from the table name group by grouped column

From the perspective of grammatical format, the grouping is first established, and then the columns to be retrieved are determined. The columns to be retrieved can only be selected from the columns participating in the grouping.

My current Mysql version 5.7.27,

Let’s look at the meaning of ONLY_FULL_GROUP_BY: For the GROUP BY aggregation operation, if the column in the SELECT does not appear in the GROUP BY, then this SQL is illegal, because the column is not in the GROUP BY clause, that is to say, it is detected List

It must appear after the group by, otherwise an error will be reported, or this field appears in the aggregate function.

 

There are two solutions. The first is to temporarily solve the problem, which will reappear when the database is restarted, and the second is to modify the MySQL configuration file

Windows solution:

Method 1:
Delete ONLY_FULL_GROUP_BY in the queried sql_mode, it will be invalid after restart

set @@GLOBAL.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

Method 2:
find your MySQL installation path first

select @@basedir;

Then go to the folder and find your my Ini configuration file, modify the content in [mysqld], add the following content, then exit the database and restart MySQL in the service

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

Linux solution:

Method 1:
Delete ONLY_FULL_GROUP_BY in the queried sql_mode, it will be invalid after restart

set @@GLOBAL.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

Method 2:
The configuration file of mysql on linux is not called my.ini, the configuration file is in /etc/my.cnf

vim /etc/my.cnf

Modify the content in [mysqld], add the following content, and then restart mysql

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

Restart command:

service mysql restart

Pycharm Connect MySQL to Find Sheet Error: RuntimeError: ‘cryptography’ package is required for sha256_password or caching_sha2_password auth methods

When linking MySQL database through pycharm, the query report will give an error prompt:

RuntimeError: ‘cryptography’ package is required for sha256_password or caching_sha2_password auth methods

Method 1: restart MySQL

① As an administrator, enter the command line “net start MySQL 80” in CMD (the service name of MySQL 80 is different here according to the installed version) to start mysql

② Enter “MySQL” to enter mysql.

③ pycharm runs again without reporting an error.

Method 2: install the cryptography package

Error: runtimeerror: ‘cryptography’ package is required for sha256_ password or caching_ sha2_ password auth methods

The error message means: sha256_Password and caching_sha2_ Password two encryption methods require cryptography.

Therefore, you only need to install the cryptography package: PIP install cryptography

① First, if you see mysql running in task manager.

② After opening cmd, enter the command "pip install cryptography", after successful installation, run pycharm again, no error is reported.

[Solved] pycharm Connect mysql Error: You must configure either the server or JDBC driver (via the ‘serverTimezone’ configuration property) to use a more specifc time zone value if you want to utilize time zone support.

1. Modify my INI.file

Mothod:

[mysqld] add

default-time-zone=’+8:00′
set global time_ zone=’+8:00’

#serverTimezone=Asia/Shanghai
#set global time_zone=Asia/Shanghai

Mothod 2: command configuration

2. URL setting of pycharm JDBC: mysql://localhost:3306/mysql?serverTimezone=Asia/Shanghai

3. Connection succeeded

4. Data query succeeded

[Solved] MYSQL Error: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]

1. When calling an interface, an interface reports an error

o.s.b.f.xml. XmlBeanDefinitionReader: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]

o.s.jdbc. support. SQLErrorCodesFactory : SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]

Screenshot information:

2. Solution ideas

(1) Look at the problem description, it is a database problem.

(2) Check the interface log, through the log, you can initially locate the problem in the “==> Preparing: REPLACE into” sql statement, while the log returned the sql statement’s input “==> Parameters”

(3) According to the parameters, the sql statement was executed in Navicat, and the result came out because of the problem of foreign keys in the database.

3.Summary

The problem how to solve is not the focus, the focus is to encounter such problems, first check the logs, locate where the problem, and then targeted to solve.

There are several common problems in the degree, such as field naming errors, type mismatch, data problems.

At the end of the day, according to the logs, execute the problem statement in the visual sql execution tool. The problem can be solved.

MySQL Execute update error: Error Code 1175 [How to Solve]

When using Mysql to execute update, if the primary key is not used in the where condition, the following error will be reported and the update cannot be executed.

Exception content: error code: 1175 You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.

Solution:
This is because MySql is running in safe-updates mode. Modify the database security mode to allow update or delete commands to be executed under non-primary key conditions.

Excuting an order:

SET SQL_SAFE_UPDATES = 0;

[Solved] Backup mysql8.0 with the mysqldump of mysql5.7 Error

Use mysql5 The mysqldump command of version 7 backs up mysql8 An error will be reported when using the 0 version of the database:

mysqldump: Couldn't execute 'SET SQL_QUOTE_SHOW_CREATE=1/*!40102 ,SQL_MODE=concat(@@sql_mode, _utf8 ',NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS') */': Variable 'sql_mode' can't be set to the value of 'NO_KEY_OPTIONS' (1231)

The solution is as follows:

The first way is to upgrade MySQL 5 Version 7 database to MySQL 8.0 0, and then use the same command to back up

The second way is not to use MySQL 5 Version 7 database comes with the mysqldump command, but find a mysql8 Upload the mysqldump command file of version 0 database to the specified path of the host, and then use mysqldump under this path for backup operation

The second method is recommended

View the current mysqldump version command

# mysqldump --version
mysqldump  Ver 10.13 Distrib 5.7.35, for Linux (x86_64)

# mysqldump --version
mysqldump  Ver 8.0.25 for Linux on x86_64 (MySQL Community Server - GPL)

[Solved] SQL Server2008 Install Progress to SqlBrowserConfigAction_install_ConfigNonRC_Cpu32 Error

When Windows Server 2012 R2 installs SQL Server 2008 R2, the installation proceeds to sqlbrowserconfigaction_ install_ ConfigNonRC_ Cpu32 always reports an error

An unauthorized operation was attempted
click Retry to retry the failed operation. Click Cancel to cancel the operation and continue the installation.

Solution:

First go to the control panel

Click uninstall program

After successful uninstall

Win + R runs regedit to open the registry and delete it

HKEY_LOCAL_ MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server 2005 Redist

Then install SQL Server 2008 R2