Tag Archives: mysql

php_ network_ Getaddresses: getaddressinfo failed: name or service not known solution

php_network_getaddresses: getaddrinfo failed: Name or service not known

PHP connects to alicycle RDS version database. At the beginning, the project domain name is configured. After the resolution is successful, the access is

that cannot be connected to the database

the solution is to restart the PHP service

service php-fpm restart

connect successfully after restart

MySQL Workbench Failed to Connect to MySQL at 127.0.0.1:3306 with user root Bad handshake

Msi

installation package: mysql-workbench-community-8.0.18-winx64. Msi

version no. : MySQL Workbench 8.0 CE

connection tip:

tried

1. Neither localhost nor ::1

2. Query whether host exists under user, -> Invalid


3. Add
bind-address = 127.0.0.1


” under [mysqld] in my. Navicat and hedisql can both connect

finally found a solution in bug-75745: due to the high version of the incompatible, download version 6.3.10 at the workbench download address to install

why do you want to use MySQL Workbench?Because you need to switch databases in multiple environments in your work, so after using heidisql(GPL open source) and navicat(charged), I tried a wave of MySQL Workbench(Community GPL open source) and found that there are multiple tabs to switch multiple environment databases, which can be used. If you are used to heidisql and navicat, you can use them without changing

1822 – Failed to add the foreign key constraint. Missing index for constraint ‘tb_emp_ibfk_1’ in the

mysql, error reported: 1822-failed to add the foreign key constraint. Missing index for constraint ‘tb_emp_ibfk_1’ in the referenced table ‘tb_dept’

reason: if table A has no primary key set, the fields in table A cannot be used as foreign keys for table B.

solution, on the premise of not deleting table A, add the following SQL text:

ALTER TABLE tb_dept ADD PRIMARY KEY(deptno);

SQL:

DROP DATABASE IF EXISTS tb_test;
CREATE DATABASE tb_test DEFAULT charset utf8;

USE tb_test;
# 部门表
CREATE TABLE tb_dept ( 
	deptno INT NOT NULL COMMENT '编号', 
	deptname VARCHAR ( 10 ) NOT NULL COMMENT '名称', 
	deptaddr VARCHAR ( 20 ) NOT NULL COMMENT '地址' 
);
INSERT INTO tb_dept VALUES
	( 101, '研发部门', '武汉' ),
	( 127, '会计部门', '上海' );
# 员工表
DROP TABLE IF EXISTS tb_emp;
CREATE TABLE tb_emp (
	empno INT NOT NULL COMMENT '编号',
	empname VARCHAR ( 10 ) NOT NULL COMMENT '姓名',
	empjob VARCHAR ( 10 ) NOT NULL COMMENT '职位',
	empsal INT NOT NULL DEFAULT 3000 COMMENT '薪酬',
	deptno INT NOT NULL COMMENT '所属部门',
	PRIMARY KEY ( empno ),
	FOREIGN KEY ( deptno ) REFERENCES tb_dept ( deptno )
);
INSERT INTO tb_emp VALUES
	(10001,'杨过','研发主管',2000000,101),
	(40001,'张三丰','总裁',90000000,127);

operation result:

DROP DATABASE IF EXISTS tb_test
> OK
> 时间: 0.32s


CREATE DATABASE tb_test DEFAULT charset utf8
> OK
> 时间: 0.991s


USE tb_test
> OK
> 时间: 0.008s


# 部门表
CREATE TABLE tb_dept ( 
	deptno INT NOT NULL COMMENT '编号', 
	deptname VARCHAR ( 10 ) NOT NULL COMMENT '名称', 
	deptaddr VARCHAR ( 20 ) NOT NULL COMMENT '地址' 
)
> OK
> 时间: 1.74s


INSERT INTO tb_dept VALUES
	( 101, '研发部门', '武汉' ),
	( 127, '会计部门', '上海' )
> Affected rows: 2
> 时间: 0.532s


# 员工表
DROP TABLE IF EXISTS tb_emp
> OK
> 时间: 0.393s


CREATE TABLE tb_emp (
	empno INT NOT NULL COMMENT '编号',
	empname VARCHAR ( 10 ) NOT NULL COMMENT '姓名',
	empjob VARCHAR ( 10 ) NOT NULL COMMENT '职位',
	empsal INT NOT NULL DEFAULT 3000 COMMENT '薪酬',
	deptno INT NOT NULL COMMENT '所属部门',
	PRIMARY KEY ( empno ),
	FOREIGN KEY ( deptno ) REFERENCES tb_dept ( deptno )
)
> 1822 - Failed to add the foreign key constraint. Missing index for constraint 'tb_emp_ibfk_1' in the referenced table 'tb_dept'
> 时间: 0.034s


PHP link database error PHP_ network_ getaddresses: getaddrinfo failed: Name or service not known

error:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

environment: thinkphp framework, Linux, ali cloud RDS database

ping link address normal:

error reporting process: access the background address, most are normal access, refresh 10-20 times may appear 1-2 error, not continuous error

solution 1:

restart php-fpm service

service php-fpm restart 

the original view: https://stackoverflow.com/questions/2661546/php-network-getaddresses-getaddrinfo-failed-name-or-service-not-known

special thanks to: https://blog.csdn.net/qq_37500838/article/details/85008432#commentBox

solution 2:

configure DNS resolution to 114.114.114.114

check DNS configuration: cat /etc/resolv.conf

I use the first solution, the second solution is temporarily useless, configuration method can be found on the Internet

Error 1396 (HY000): Operation create user failed for ‘xxx’ @’xxx ‘

create user ‘test’ @’ % ‘identified by’ test ‘;
create user ‘test’ @% ‘identified by’ test ‘;
display ERROR 1396 (HY000): Operation CREATE USER failed for ‘test’ @ ‘%’
check whether there is this USER
select USER from USER;
found no such user.
remember you deleted this user last time.
flush privileges may not be flush;
, ERROR 1396 (HY000): Operation CREATE USER failed for ‘test’ @ ‘%’
drop USER ‘test’ @ ‘%’;
drop USER ‘test’ @ ‘%’;
failed for ‘test’ @ ‘%’;
drop USER ‘test’ @ ‘%’;
flush privileges;
create user ‘test’ @ ‘%’ identified by ‘test’;
create user ‘test’ @ ‘%’ identified by ‘test’;
success.
Assume the user is there, so drop the user
After deleting the user, there is need to flush the mysql privileges
Now create the user.

http://stackoverflow.com/questions/5555328/error-1396-hy000-operation-create-user-failed-for-jacklocalhost

How to Fix SQL Error: 1054, SQLState: 42S22 Unknown column ‘markcardex0_.art_service_time’ in ‘field list’

SQL Error: 1054, SQLState: 42S22 this is the Error caused by the missing field, first attach the Error log:

2020-03-04 10:30:00. 221 WARN [pool – 8 – thread – 1] [org. Hibernate. Engine. JDBC. Spi. SqlExceptionHelper. Java: 127] – SQL Error: 1054, SQLState: 42 s22
the 2020-03-04 10:30:00. 221 ERROR [pool – 8 – thread – 1] [org. Hibernate. Engine. JDBC. Spi. SqlExceptionHelper. Java: 129] – Unknown column ‘markcardex0_. Art_service_time’ in ‘field List ‘
the 2020-03-04 10:30:00. 225 ERROR [pool – 8 – thread – 1] [org. Springframework. Scheduling. Support. TaskUtils $LoggingErrorHandler. Java: 95] – Unexpected ERROR occurred in scheduled task.
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; Nested exception is org. Hibernate. Exception….

under Caused by: org. Hibernate. Exception. SQLGrammarException: could not extract the ResultSet
… 24 common frames omitted
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘markcardex0_. Art_service_time’ in ‘the field list’
the at sun, reflect the NativeConstructorAccessorImpl. NewInstance0 (Native Method)
the at Sun. Reflect. NativeConstructorAccessorImpl. NewInstance (NativeConstructorAccessorImpl. Java: 62)
the at Sun. Reflect. DelegatingConstructorAccessorImpl. NewInstance (DelegatingConstructorAccessorImpl. Java: 45)
the at Java lang. Reflect. Constructor. NewInstance (423) Constructor. Java:
the at Com. Mysql. JDBC. Util. HandleNewInstance Util. Java: (411)
at the mysql. JDBC. Util. GetInstance (Util. Java: 386)
at the mysql. JDBC. SQLError. CreateSQLException (SQLError. Java: 1053)
the at Com. Mysql. JDBC. MysqlIO. CheckErrorPacket MysqlIO. Java: (4074)
at the mysql. JDBC. MysqlIO. CheckErrorPacket (MysqlIO. Java: 4006)
at the mysql. JDBC. MysqlIO. SendCommand (MysqlIO. Java: 2468)
At com. Mysql. JDBC. MysqlIO. SqlQueryDirect (MysqlIO. Java: 2629)
at the mysql. JDBC. ConnectionImpl. ExecSQL (ConnectionImpl. Java: 2719)
the at . Com. Mysql. JDBC PreparedStatement. ExecuteInternal (PreparedStatement. Java: 2155)
at the mysql.. JDBC PreparedStatement. ExecuteQuery (2318) a PreparedStatement. Java:
the at Com. Alibaba. Druid. Filter. FilterChainImpl. PreparedStatement_executeQuery (FilterChainImpl. Java: 2714)
the at Com. Alibaba. Druid. Filter. FilterEventAdapter. PreparedStatement_executeQuery (FilterEventAdapter. Java: 465)
the at Com. Alibaba. Druid. Filter. FilterChainImpl. PreparedStatement_executeQuery (FilterChainImpl. Java: 2711)
the at Com. Alibaba. Druid. Proxy. JDBC. PreparedStatementProxyImpl. ExecuteQuery (PreparedStatementProxyImpl. Java: 145)
the at Com. Alibaba. Druid. Pool. DruidPooledPreparedStatement. ExecuteQuery (DruidPooledPreparedStatement. Java: 227)
the at Org. Hibernate. Engine. JDBC. Internal. ResultSetReturnImpl. Extract (ResultSetReturnImpl. Java: 70)
… 60 common frames omitted

error occurs mainly because the variables in the entity class do not match the classes in the database table, which is a headache, especially when the data is complex. I used to be stupid, one by one, but now I can sum up a simple method:

1. Look at the reason for this error: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘markcardex0_. Art_service_time ‘in ‘field List’ is Unknown column ‘markcardex0_. Art_service_time ‘in ‘field list’ is Unknown column’ mark_service_time ‘in ‘field list’ Find –> Find In Path) quickly search artServiceTime, Find the entity class that defines the variable artServiceTime, click In, as follows:

2. After entering the entity class corresponding to this variable, you can see the database Table corresponding to this entity through the annotation @table (name = “uk_markcard_xxxx”) :

opens the database and verifies the existence of this attribute in the table through the query, as follows:

as shown in the figure above, we found the same error as the console, at this time we add the corresponding entity variable property on the table, note:

(1) attribute type must be the same as the entity variable type

(2) MySQL makes no case difference, but if the variable in the entity class is named aaaBcc, the attribute name in the database should be aaa_bcc, not

MySQL error — multiple methods of failed to find valid data directory and MySQL setting password appear

MYSQL error – Failed to find valid data directory

operating environment: windows10

database version: mysql.8.0.16

problem description:

MySQL service is starting.
MySQL service cannot start. The
service did not report any errors.

solution:

  • manually empty the files in the data folder under the installation path (possibly due to incomplete files due to previous initialization failure)
  • into the bin path remove mysql service
  • under the bin path enter mysqld –initialize-insecure (the program will create many files under the data folder)
  • continue to enter mysqld -install (service has been reinstalled)
  • start mysql service, enter net start mysql

the MYSQL error, Failed to find valid data directory. _Nikita – _failed CSDN blog to find valid data directory.
https://blog.csdn.net/Hellen0708/article/details/93377724

=================================================================================

=================================================================================

=================================================================================

the mysql database password _qq_26486949 blog blog – CSDN _mysql password
https://blog.csdn.net/qq_26486949/article/details/88373487

mysql database password Settings

mysql newly installed does not have a password by default, so it needs to be set manually.

method 1: use the SET PASSWORD command

log in to MySQL first.

format: mysql> Set password for username @localhost = password(‘ new password ‘);

example: mysql> set password for root@localhost = password(‘123’);

method 2: mysqladmin

format: mysqladmin-u username -p old password password new password

example: mysqladmin-uroot-p123456 password 123

method 3: edit user table

directly with UPDATE

log in to MySQL first.

mysql> use mysql;

mysql> update user set password=password(‘123′) where user=’root’ and host=’localhost’;

mysql> flush privileges;

method 4: use the GRANT statement mysql> Grant all on *.* to ‘root’@’localhost’ IDENTIFIED BY ‘your password ‘with grant option; mysql> flush privileges;

method 5: when you forget the root password or initialize the password, you can do this:

Take Windows as an example:

1. Close the running MySQL service.
2. Open a DOS window and go to mysql\bin directory.

3. Enter mysqld –skip-grant-tables enter. Skip-grant-tables means to skip permission table authentication when starting MySQL service.

4. Open another DOS window (because the DOS window is no longer active) and go to the mysql\bin directory.
5. Enter mysql enter. If successful, mysql prompt &gt will appear. .

6. Connection permission database: use mysql; .

. Update user set password=password(“123″) where user=”root”; Don’t forget to put a semicolon at the end.

if ERROR 1054(42S22) Unknown column ‘password’ in ‘field list’ occurs, this is because the password field is no longer available in mysql database in version 5.7, and the password field is changed to authentication_string. The statement should be update User Set Authentication_string =password(“123″) where user=”root”;

7. Flush privileges (mandatory step) : flush privileges; .

8. Quit quit.
9. Log out of the system, enter again, log in with the username root and the new password 123 that you just set.

MySQL master-slave replication. An error is reported when starting slave. Slave failed to initialize relay log info structure from the repository

symptoms:

MySQL master slave copy, when starting slave, the following error occurs:
mysql> start slave;
ERROR 1872 (HY000): Slave failed to initialize relay log info structure from the repository

solution: check the log,

can see the error, it was not found originally./server246-relay-bin.index file, find the reason, because I used an instance of cold backup file recovery, in mysql library slave_relay_log_info table still retain the previous relay_log information, so it caused to start slave error.
mysql provides tools for deleting records: slave reset;
slave reset does a few things when executed:
1, delete slave_master_info, slave_relay_log_info in both tables; 2. Delete all relay log files and recreate new relay log files; 3, will not change the value of gtid_executed or gtid_purged

mysql> reset slave;
Query OK, 0 rows affected (0.01 sec)

mysql> change master to ......

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

So it’s

so that slave can start.

How to Fix Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications

this problem is in the database connection failure, looked up from the Internet, the solution is varied, there are configuration files, and change the code. But everyone makes the same mistake for different reasons.

will be stupid, suddenly realized that the database can not connect, either url, or a user name or password. Turning back, the real cause was found…

error code:

String url="jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true";
String username="root";
String password="123456";

remove (with warning) or change to false after url:

String url="jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=false";
String username="root";
String password="123456";

is not an error, you can query out.

Global lock, table lock and row lock in MySQL

🔒 global lock

locks the entire database instance. Use the Flush tables with read lock (FTWRL) to keep the entire database read-only, after which the database update statement (add, delete), data definition statement (build, modify table structure), and update class transaction commit statement will be blocked

locks the entire database, so an obvious use case for global locks would be to do a full library logical backup; There is another way to use set global readonly=true to make the entire library read-only, with one big difference:

exception handling, if the client is abnormal to disconnect, MySQL will automatically release the global lock, so that the whole library back to the normal state; After the entire library is set to READOnly, the database will remain readOnly after the exception is disconnected, resulting in the database being unwritable for a long time.

🔒 table level lock

MySQL has two table level locks: table lock and meta data lock (MDL)

table lock syntax lock tables... Read /write, unlock unlock talbes. It is automatically released when the client is disconnected. In addition to restricting the reading and writing of other threads, table locks also restrict the following operation objects of this thread. For example, thread A executes lock tables t1 read,t2 write, while other threads write t1 and read t2 are blocked. Before tables, A thread can only read t1 and write t2

metadata lock is automatically added when accessing a table to ensure that the table structure cannot be modified

when accessing data

🔒 row locks

MySQL row lock is implemented in each storage engine, InnoDB on the support of row lock, MyISAM engine does not support row lock

row lock is the lock that locks A row of records in the table. When A is processing this row of data and B also wants to process this data, B can only continue

after A has finished processing

two-stage locking protocol

in InnoDB transactions, row locks are added when they are needed, but they are not immediately released when they are not needed, but wait until the current transaction is completed.

so if more than one row needs to be locked in a transaction, put the rows that are most likely to cause concurrency as far back as possible.

an 🌰 :

the ticketing business of a ticketing system is approximately:

  1. customer A ticket, A balance to deduct price

  2. cinema B account balance increase ticket

  3. record transaction log

    , the point of concurrency is cinema B to increase revenue. If each customer purchases tickets in the business order of 1, 2, and 3, then concurrent point 2 will hold the lock for a long time. If you change it to 3, 1, or 2 after processing the concurrent points, the row-level lock is released, reducing the wait time for locks between things.

    deadlock and deadlock detection

    different threads hold each other’s locks, A and B release the lock, B and A release the lock, then deadlock

    deadlock treatment strategy:

    1. one strategy is to go straight into the wait until the timeout occurs. This timeout can be set with the parameter innodb_lock_wait_timeout to

    2. to initiate deadlock detection. When a deadlock is found, it will actively roll back a transaction in the death chain bar to allow other transactions to continue execution. The parameter innodb_deadlock_detect is set to on, indicating that this logic is turned on,

      . Note here:

      (1) deadlock detection is performed only when there is a row lock on the accessed row

      (2) not all transactions are scanned for each deadlock detection. For example, at some point, the transaction waiting state is like this:

      , B is waiting for A, D is waiting for C, and now there is an E, and it is found that E needs to wait for D, then E will judge whether there will be deadlock with D and C, this detection does not care about B and A

[MySQL] [serialize] [error record] after modifying data, no data will be returned (in fact, MySQL does not support it)

summary: mysql does not support update to return data. Only Postgres is supported.

this is the definition tip, and the return value is an array of Numbers and a Model array.


That means only Postgres plus configuration is supported.

...
  /**
   * Return the affected rows (only for postgres)
   */
  returning?: boolean;

  /**

is very angry.