Tag Archives: database

[Solved] JDBC error: Communications link failure

Change url: In addition?useUnicode=true& CharacterEncoding=UTF-8& serverTimezone=UTC”

 <!-- Database connection pooling -->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
          destroy-method="close">
        <property name="url" value="jdbc:mysql://localhost:3306/user_db?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=UTC" />
        <property name="username" value="root" />
        <property name="password" value="123456" />
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    </bean>

Mongodb Crash Error: Too many open files [How to Solve]

Problem analysis of mongodb crash error too many open files

during the actual use of the project, the customer reported that he could open the web page but could not log in. He felt that the database server should hang up for the first time, so he checked the mongodb database server log, and sure enough, it hung up. The error information is as follows:

2020-12-28T13:21:21.731+0800 E STORAGE  [conn2624] WiredTiger error (24) [1609132881:731616][23581:0x7fe157189700], WT_SESSION.create: __posix_directory_sync, 151: /data1/mongodb/data/db/collection-1063-1706476241051221735.wt: directory-sync: Too many open files Raw: [1609132881:731616][23581:0x7fe157189700], WT_SESSION.create: __posix_directory_sync, 151: /data1/mongodb/data/db/collection-1063-1706476241051221735.wt: directory-sync: Too many open files

Cause of problem:

The number of open files on the system has reached the maximum
The reason for the above problem is that Centos7 gives each user a default number of files to open at the same time of 1024, which can be checked with the ulitme -u command

Problem solving:

1. Modify the limits.conf default parameters and add the following under the file.
* soft nofile 65536
* hard nofile 65536
PS: After saving as above, you need to reboot the system to take effect permanently

2, dynamic modification (no need to restart the system and mongo)
2.1, check the mongodb service pid file
        ps aux | grep mongo
2.2、After getting the pid file, check the corresponding pid limits, the following command
        cat /proc/95051/limits
2.3、Run the following command to achieve dynamic changes
        prlimit --pid 95051 --nofile=65535:65535
2.4. Check again, the modification is successful

proposal

It is recommended that new servers first change the system default parameters

Pikachu vulnerability is installed in the shooting range, and an error is reported when connecting to the MySQL database

During the installation of Pikachu vulnerability shooting range, the processing methods of connecting to MySQL database and reporting errors are as follows:

1. Confirm that the database can be connected normally. Try connecting with tools. If it is not normal, please check the configuration problems such as service, user name and password
2. Modify the IP address, user name and password of the database in config.inc.php to the IP, user name and password of the database. Both the root directory and pkxss have this file and need to be modified.

Config.inc.php in the root directory \ pkxss \ Inc also needs to be modified. It’s difficult.

SQL Server Deletes a table foreign key constraint Error [Solved]

  Create two tables tbltesta and tbltesb, and delete tbltesta


			create table dbo.TblTestA(
			Id					bigint			primary key identity(1, 1),
			name			varchar(20)     unique,
		    )
	
			create table dbo.TblTestB(
			Id					bigint			primary key identity(1, 1),
			TestAId				bigint			not null foreign key references 
			Status				varchar(1),
	     	)

Error reported: it is referenced by a foreign key constraint

Reason: other tables refer to the foreign key of this table

Solution:

1. Find the foreign key of this table referenced by other tables

exec sp_Helpconstraint ‘table name’;

2. Find the associated foreign key constraint table name

select name
from   sys.foreign_key_columns f join sys.objects o on f.constraint_object_id=o.object_id
where f.parent_object_id=object_ID (‘foreign key association table name ‘)

3. Delete the foreign key constraint

Alter table foreign key constraint table, Drop constraint name (constraint name found above)


4. Delete table (events can be added)

BEGIN TRY
    BEGIN TRANSACTION
        ALTER TABLE TblTestB DROP CONSTRAINT FK__TblTestB__TestAI__635CD8E4
        DROP TABLE dbo.TblTestA
    COMMIT TRANSACTION
        PRINT 'commit sucesss'
END TRY
BEGIN CATCH
    ROLLBACK TRANSACTION
    PRINT 'rollback sucesss'
END CATCH

 

[Solved] MySQL 8 Connect Navicat error: error 2059

#Error message:

the reason for this error is the encryption rule MySQL in versions before MySQL 8_native_Password, and the encryption rule after MySQL 8 is caching_sha2_password. There are two ways to solve this problem. One is to update the Navicat driver to solve this problem, and the other is to modify the encryption rules of MySQL user login to MySQL_native_password. The second method is adopted here
# solution
log in to the database
set the password to never expire

alter user 'root'@'localhost' identified by 'root' password expire never;

Set the encryption rule to MySQL_native_password

alter user 'root'@'localhost' identified with mysql_native_password by 'root';

Access Navicat again and you will be prompted that the connection is successful

MYSQL8 Startup Error: mysqld_safe error: log-error set to ‘/var/log/mariadb/mariadb.log‘

Starting MySQL.2021-11-17T11:04:25.022108Z mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.
 ERROR! The server quit without updating PID file (/data/mysql/data/localhost.localdomain.pid).

After msyql8 compilation and installation, start MySQL with/etc/init.d/mysqld start command. The above errors are reported, and then I rechecked the content of my.cnf, as follows:

[mysqld]
server-id=1
port=3306
datadir=/data/mysql/data
basedir=/usr/local/mysql
socket=/usr/local/mysql/mysql.sock
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[client]
socket=/usr/local/mysql/mysql.sock


[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

There is no problem with the overall configuration of my.cnf, and then the startup fails all the time. Finally, it is found that it is the log directory configured by mysqld_safe was not created

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

So create authorization directly

Note: the path of log error I configured here is under/var/log/MariaDB. The created path is configured according to its own actual path. Be sure not to forget to create mariadb.log, otherwise an error will be reported

mkdir /var/log/mariadb     
touch /var/log/mariadb/mariadb.log

MySQL users and users authorize directories

chown -R mysql:mysql /var/log/mariadb/

Start the MySQL service again

/usr/local/mysql/support-files/mysql.server start

perhaps

/etc/init.d/mysqld start

Other startup methods are implemented according to their actual situation

[Solved] flash initializate database error: Keyerror: ‘migrate’

from flask_sqlalchemy import SQLAlchemy

from flask_migrate import Migrate, migrate

def create_app(register_all=True, **kwargs):
    #Add this code under this method, add the database package and initialize,
     db=SQLAlchemy()
     db.init_app(app)
     #Import and initialize
    migrate=Migrate(db=db)
    migrate.init_app(app)
    return app

directory = current_ app.extensions[‘migrate’].directory

This sentence means that migrations are not generated

So you need to add migrate and initialize

DB needs to be added for initialization

[Solved] Python import Error: pip –upgrade Error: ERROR: Cannot uninstall ‘dnspython‘. It is a distutils installed

Background:
today we use package to install the module dnspython

[root@makel ~] wget http://www.dnspython.org/kits/1.9.4/dnspython-1.9.4.tar.gz
[root@makel ~] tar -xvf dnspython-1.9.4.tar.gz
[root@makel ~] cd dnspython-1.9.4/
[root@makel dnspython-1.9.4] python3 setup.py install

Solution process
1. Enter Python and import reports an error (problem found)

[root@makel ~] python3
Python 3.8.5 (default, Nov  7 2021, 21:47:38) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns.resolver
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python3/lib/python3.8/site-packages/dns/resolver.py", line 26, in <module>
    import dns.message
  File "/usr/local/python3/lib/python3.8/site-packages/dns/message.py", line 175
    return '<DNS message, ID ' + `self.id` + '>'
                                 ^
SyntaxError: invalid syntax

2. Try upgrading (– upgrade) and find that it still can’t be installed

[root@makel ~] pip3 install dnspython --upgrade
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: dnspython in /usr/local/python3/lib/python3.8/site-packages (1.9.4)
Collecting dnspython
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f5/2d/ae9e172b4e5e72fa4b3cfc2517f38b602cc9ba31355f9669c502b4e9c458/dnspython-2.1.0-py3-none-any.whl (241 kB)
     |████████████████████████████████| 241 kB 898 kB/s            
Installing collected packages: dnspython
  Attempting uninstall: dnspython
    Found existing installation: dnspython 1.9.4
ERROR: Cannot uninstall 'dnspython'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

3. A new error occurred while attempting to uninstall

[root@makel ~] pip3 uninstall dnspython
Found existing installation: dnspython 1.9.4
ERROR: Cannot uninstall 'dnspython'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

4. If the command cannot be unloaded, delete the file manually

[root@makel ~] cd /usr/local/python3  #Go to the directory where python is installed
[root@makel python3] find ./-name "*package*" #Fuzzy search package
./lib/python3.8/site-packages
./lib/python3.8/site-packages/setuptools/package_index.py
./lib/python3.8/site-packages/setuptools/__pycache__/package_index.cpython-38.pyc
./lib/python3.8/site-packages/setuptools/__pycache__/package_index.cpython-38.opt-1.pyc
......
[root@makel python3] cd lib/python3.8/site-packages/ #Find site-packages from the above results and go to this directory
[root@makel site-packages] ll  
total 96
drwxr-xr-x. 4 root root  4096 Nov 16 17:18 dns
-rw-r--r--. 1 root root  1277 Nov  9 22:31 dnspython-1.9.4-py3.8.egg-info
....
[root@makel site-packages] rm -rf dnspython-1.9.4-py3.8.egg-info   #Delete all files containing the module name

5. Reinstall and import successfully after installation

[root@makel site-packages] pip3 install dnspython #reinstall
[root@makel site-packages] python3
Python 3.8.5 (default, Nov  7 2021, 21:47:38) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dns.resolver
>>> exit

[Linux Docker Mirror] MYSQL Run sql Script Error: Failed to open file ‘/home/mydatabase.sql‘, error: 2

Failed to open file ‘/ home/mydatabase. SQL’, error: 2 when running SQL script in docker image MySQL in Linux

Today, an error occurred when using docker in centos7 to start MySQL and run SQL script files. The error information is as follows:

mysql> source /home/mydatabase.sql;
ERROR: 
Failed to open file '/home/mydatabase.sql', error: 2

After checking the Internet, the cause of the error should be the problem of path matching. The default path is the installation path of MySQL, so MySQL can only access all directories and files under its source directory. The solution is to directly specify the SQL script file to run when logging in. The specific steps are as follows:
first log in to MySQL and create the database to be used. The name of the database I created is Mydatabase1

root@4994c041aa3a: mysql -uroot -p 
Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database mydatabase1;

Exit MySQL and log in again by running SQL script files

# Here mydatabase1 is the database created in the first step, and the file after'<' is the path of the sql script file to be run
root@4994c041aa3a: mysql -uroot -p mydatabase1 < /home/mydatabase.sql

log in again and find that the file has run successfully

root@4994c041aa3a: mysql -uroot -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| mydatabase1        |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use mydatabase1;
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

mysql> show tables;
+-----------------------------+
|    Tables_in_mydatabase1    |
+-----------------------------+
| t_disk                      |
| t_crl                       |
| t_menu                      |
| t_user                      |
+-----------------------------+
4 rows in set (0.00 sec)

Supplement:

# Docker start MySQL command under CentOS7
docker pull mysql:5.7
docker run -tid --name mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 mysql:5.7
docker exec -it mysql /bin/bash
mysql -uroot -p
Enter password:

[Solved] Error occurred during connect to primary: exception 3000301: Connection could not be established

Problem:
the Hana system replication standby machine cannot take over the host, and the Hana host can be used normally.

The following errors are reported in the trace file:
SR_dataaccess DisasterRecoverySecondaryImpl.cpp(00882) : Error occurred during connect to primary: exception 3000301: Connection could not be established

Solution:
this problem is generally caused by a network problem between the active and standby computers
for the above error reports, you can first check whether the 3xx00-3xx99 port segment of the standby machine to the host is occupied or blocked.

Exception occurred when Django created app: from exc ^ syntaxerror: invalid syntax

Execute command Python   manage.py   startapp   Myjango

  App reports an error: file “manage. Py”, line 16) from exc ^ syntax error: invalid syntax

reason:

Python 3 is installed, but Python is used for execution

solve:

Change Python to python3 and execute the above command

python3 manage.py   startapp   myjango