Category Archives: MySQL

MySQL automatically creates partitions through events

Automatic execution using mysql event timing

BEGIN
	set @table_name = concat('p', DATE_FORMAT(DATE_ADD(NOW(),INTERVAL 1 DAY),'%Y%m%d'));
	set @max_value  = DATE_FORMAT(DATE_ADD(NOW(),INTERVAL 1 DAY),'%Y%m%d');
	set @excutesql  = CONCAT('ALTER TABLE TITLE ADD PARTITION (PARTITION ',@table_name,' VALUES LESS THAN ("',@max_value,'"))');
	SELECT @excutesql;
	PREPARE stmt from @excutesql;
	EXECUTE stmt;
	DEALLOCATE PREPARE stmt;
END

How To Change ASM SYS PASSWORD

To change the ASM SYS Password
Things tried:
SQL> password
Changing password for SYS
Old password:
New password:
Retype new password:
ERROR:
ORA-00600: internal error code, arguments: [15051], [], [], [], [], [], [], []

SQL> select INSTANCE_NAME from v$instance;

INSTANCE_NAME
—————-
+ASM

SQL> ALTER USER sys IDENTIFIED BY <new_password> REPLACE <old_password>;
ALTER USER sys IDENTIFIED BY <new_password> REPLACE <old_password>
*
ERROR at line 1:
ORA-01109: database not open

The following error also might occur:
SQL> alter user sys identified by ;
alter user sys identified by
*
ERROR at line 1:
ORA-01031: insufficient privileges

Solution
We can not change the password for ASM databases via alter user command.
The password should be the one provided when the password file was created,also REMOTE_LOGIN_PASSWORDFILE should be set to EXCLUSIVE on all instances.

If you want to change the password then you would need to recreate the password file using the orapwd utility
Recreate the password file for the ASM instance as follows:
1.   Set the ORACLE_HOME and ORACLE_SID to the ASM instance
2.  connect /as sysdba from sqlplus
3.  If the value of the “remote_login_passwordfile” parameter in the pfile or spfile is EXCLUSIVE, you must shutdown your instance
4.  RENAME or DELETE the existing password file PWD<SID>. ora( In Windows) / orapw<SID> ( in UNIX)
5.  Issue the command:
WINDOWS:
orapwd file=<ORACLE_HOME>/database/PWD<SID>. ora password=<sys_password>

UNIX:
orapwd file=<ORACLE_HOME>/dbs/PWD<SID> password=<sys_password>

The passwordfile can be recreated for ASM while ASM instance is up. Usually for normal DB instances, we recommended that DB instances be shutdown before changing the passwordfile.

Error [err] is reported when redirecting_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

When nodejs connected to mysql database, there was a problem that the data was received normally at the first connection, but when the page redirection was updated, it was wrong, and the node service would be disconnected. As shown in figure

error code is as follows:

after searching online, it was found that res.send() contains res.end() method. After calling res.end() once, the data returned normally, but res.end() was executed at the same time
The solution
Will res. The send (); Just comment it out.
, but then it reports an Error, as shown in figure

Error: Cannot enqueue Quit after invoking Quit.
I use the mysql module, because I call connection.end() frequently; This error occurred, so the final code is as follows

//Search School List
router.get('/school', function(req, res, next) {
  connection.query("select * from school",function (err, result) {
    if(err){
      // res.send(err.message);
      res.json({
        status:"1",
        msg:err.message
      });
      return;
    }else{
      // res.send(result);
      res.json({
        status:"0",
        msg:result
      });
    }
  });
  // connection.end();
  // res.send('respond with a resource');
});

[305]MYSQL 1062 error: duplicate entry ‘…’ for key ‘primary

Explanation:
Duplicate entry ‘… ‘For key ‘PRIMARY, the PRIMARY key data to be inserted into the data. It already exists. You can’t add it again. Example: Duplicate entry ‘0’ for key ‘PRIMARY refers to the data with a PRIMARY key value of 0 already exists, so the data with a PRIMARY key value of 0 can no longer be inserted.
Problem Solving:
Before the insert operation, you can perform the search operation SELECT for the primary key value, such as:
Perform an insert (0, “triple”) operation

insert into table(id,name) values(0,'Mr Three');

Duplicate entry ‘0’ for key ‘PRIMARY
can be added a judgment before insertion. If the PRIMARY key value is 0, it can be found, and it exists. If it cannot be found, the insert operation is performed.

select id from table where id = 0;

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

ERROR 2002 (HY000) : Can ‘t connect to local MySQL server through socket’/var/run/mysqld/mysqld. (2) the sock ‘
The server encountered a familiar problem today
Input:

#mysql -u root -p
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

Then he searched the Internet for answers
I’m going to try each of the methods that you’ve given me
Plan 1

#ps -A|grep mysql

Display similar to:

1829 ?       00:00:00 mysqld_safe
1876 ?       00:00:31 mysqld
#kill -9 1829
  #kill -9 1876
#/etc/init.d/mysqld restart
#mysql -u root -p

His problem is solved, mine is not solved!
keep looking for
Scheme 2
Check the/etc/rc. D/init. D/mysqld status to see if the mysql has already started.
see if other permissions problems.
— — — — — — — — — — — — — —

[root@localhost beinan]#chown -R mysql:mysql /var/lib/mysql
[root@localhost beinan]# /etc/init.d/mysqld start

Start MySQL: [OK]

[root@localhost lib]# mysqladmin -uroot password ‘123456’
[root@localhost lib]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 3 to server version: 4.1.11

Type ‘help;’ or ‘/h’ for help. Type ‘/c’ to clear the buffe

His was solved, and my troubles continued, and my search continued
Scheme 3
problem solved, but max_connections=1000. He said too much, then changed it to 500, but the problem was solved.
Still won’t do
Plan 4

	/var/lib/mysql All file permissions change to mysql.mysql

No, no
Scheme 5
abstract: Solve by mysql. The problem of the sock to connect mysql main hint is that the problem can’t ‘/ TMP/mysql. The sock’ connected to the server, and PHP standard configuration is used ‘/ TMP/mysql. The sock, but some mysql installation method will mysql. The sock in/var/lib/mysql. Where the sock or other, you can modify the/etc/my CNF file to correct it, open the file, you can see the following things:

 	[mysqld] 
	socket=/var/lib/mysql .sock 

A change would be fine, but it could also cause other problems, such as the mysql program can’t be connected. Add one more point:

	[mysql ] 
  socket=/tmp/mysql .sock 

Or you can modify the configuration in php.ini to make PHP use another mysql.sock, and you can find this for yourself
or you can do it this way:

ln -s /var/lib/mysql /mysql .sock /tmp/mysql .sock

It worked. That was ln-s /var/lib/mysql. sock/TMP/mysql. sock
OK!
Solution to MySQL. Sock loss problem under MySQL 6
[ubuntu, Linux, mysqld.sock]
MySQL. Sock loss is generally caused by inconsistent configuration files. The solution:
It is judged that ordinary people did not switch to mysql user when solving the failure, which caused some permission problems. Therefore, they could not create mysql authorization table, so they could not create/TMP/mysqlm. sock and Hostname. pid files. Therefore, the summary solution is as follows (note: using root is also acceptable) :

#su mysql
$/usr/local/bin/mysql_install_db //Reconstruction authorization table
$/usr/local/bin/mysqld_safe &
$/usr/local/bin/mysql //Test
mysq>bye;
$

The file has been solved, and the new/TMP /mysql.sock and hostname.pid
have been generated.
Share source address: https://blog.csdn.net/thanklife/article/details/69225724

The fifth plan, which I borrowed from the Internet, was not successful for me. Only the sixth one succeeded!

C# System.Data.SQLite.SQLiteException:“SQL logic error or missing database no such table: XX”

System. Data. SQLite. SQLiteException: “SQL logic error or missing the database no to the table: XX”

new SQLiteConnection(“Data Source=xxx.sqlite; Version=3;” );

solution: specify absolute path of database file
new SQLiteConnection(“Data Source=D:\111\222\333\xxx.sqlite; Version=3;” );

SQL statement to calculate the distance between two coordinates

The article directories
Preface one, the code is as follows


preface
how to quickly calculate the distance between two coordinates in SQL native statement?


One, the code is as follows
code as follows (example) :


$lng=input('longtitude'); //Enter the vertical coordinates
$lat=input('latitude'); //Horizontal coordinates of the input
 
$distance="ACOS(SIN(( $lat * 3.1415)/180 ) *SIN((latitude * 3.1415)/180 ) +COS(( $lat* 3.1415)/180 ) * COS((latitude * 3.1415)/180 ) *COS(( $lng* 3.1415)/180 - (longtitude * 3.1415)/180 ) ) * 6380";

$fds=Db::table('activity')
->field($distance.' as distance')
->select();


How to Fix MySQL error 1005: can’t create table (errno: 150)

Mysql ERROR 1005: Can’t create Table (errno: 150) when creating a reference constraint in mysql results in an ERROR message that cannot create a reference constraint.
A rough picture of what went wrong
1, foreign key reference type is different, such as the primary key is int foreign key is char
2. The column referenced in the main table could not be found
3, the primary key and foreign key character encoding is not consistent, may also be different storage engineThe problem I ran into was that none of the above was true, but it did succeed after removing a foreign key constraint. One thing is for sure, this error was caused by a foreign key constraint.

To summarize the experience:

In fact, in a MySQL database, if there are more than one database, it is better to write SQL with the name of the database, such as:

CREATE TABLE  `testdb`.`user_visitor_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` varchar(45) COLLATE utf8_bin DEFAULT NULL COMMENT 'id',
  `user_ip` varchar(15) COLLATE utf8_bin DEFAULT NULL COMMENT 'ip',
  `refer_url` varchar(45) COLLATE utf8_bin DEFAULT NULL COMMENT 'source',
  `visit_time` timestamp NULL DEFAULT NULL COMMENT 'time',
  `leave_time` timestamp NULL DEFAULT NULL COMMENT 'leave time',
  `module_name` varchar(45) COLLATE utf8_bin DEFAULT NULL COMMENT 'moudle name',
  `news_id` int(11) DEFAULT NULL COMMENT 'Access to information on the information page id',
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  KEY `seoID_idx` (`seo_id`),
  CONSTRAINT `seo_msg_id` FOREIGN KEY (`seo_id`) REFERENCES `college_seo_msg` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='User access log';

 

How to Fix MySQL ERROR 1130 (HY000): Host ‘XXXX’ is not allowed to connect to this MySQL server

Environment: mysql5.7.11 + windows10 64-bit
Problem: When using mysql remote login command mysql — uroot — h192.168.1.102-p, ERROR mysql ERROR 1130 (HY000): Host ‘XXXX’ is not allowed to connect to this mysql server
The reason for the problem: For security reasons, the mysql server allows only local login to the database server by default.
Fix the problem: After you log in to mysql, change the “host” TAB in the “User” table in the “mysql” database, change the name from “localhost” to “%”, and restart mysql so that all remote machines can access it.
step 1: modify the mysql table
mysql -u root -pvmware
mysql> use mysql;
mysql> update user set host = ‘%’ where user = ‘root’;
mysql> flush privileges;
mysql> select host, user from user;
mysql> quit
Step 2: Restart mysql
Method 1: Find “View Local Services” in Windows Settings, find mysql service, and restart mysql service



Method 2:
Win 7 or XP will start and stop mysql directly from the CMD command line by calling NET stop mysql /net Start mysql.
win8 and above versions need to use administrator privileges to use the CMD command to start the service. The author USES windows10, so you need to find CMD. Exe, right click and select “run as administrator”, and then enter net stop mysql /net start mysql to start and stop the service.

Step 3: Use the remote login command again and the login is successful.

ERROR 1265 (01000): Data truncated for column ‘ENABLED’ at row 7

mysql> UPDATE performance_schema. setup_consumers SET ENABLED = ‘OFF’ WHERE NAME LIKE ‘events_transactions%’;

ERROR 1265 (01000): Data truncated for column ‘ENABLED’ at row 7

mysql> show create table  performance_schema. setup_consumers \G

*************************** 1. row ***************************

Table: setup_consumers

Create Table: CREATE TABLE `setup_consumers` (

`NAME` varchar(64) NOT NULL,

`ENABLED` enum(‘YES’,’NO’) NOT NULL

) ENGINE=PERFORMANCE_SCHEMA DEFAULT CHARSET=utf8

1 row in set (0.00 sec)

It turns out that ENABLED is an enumeration type, where only the YES,NO.

mysql> UPDATE performance_schema. setup_consumers SET
ENABLED = ‘NO’ WHERE NAME LIKE ‘events_transactions%’;