Tag Archives: mysql

Solution to MySQL Error 1130 problem

Local Error 1130 problem solution
When connecting to mysql database, ERROR 1130 (HY000) occurs: the Host ‘XXXX’ is not allowed to connect to this mysql Server. Local localhost will not work either. If you reinstall mysql database, you will be afraid that the original database cannot be restored.
Appear this kind of problem may be caused by illegal power off and remove the root user, mysql database user without root, in the table if localhost is also unable to log in, you need to. In my ini finally add skip – grant – tables, so you don’t need a password login, after landing in the following SQL statement to create the root user (I am using version 5.1, different versions can be different SQL statements)

INSERT INTO `user` VALUES ('localhost', 'root', 'your password', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', '0', '0', '0', '0');

After success, delete ski-grant-tables in my.ini, and you can now log in using the root password locally.
Remember in the database installed mysql, do not illegally shut down, forced power off, otherwise this problem will occur.
If Error 1130 appears locally, then the remote connection must also appear. If the local connection problem is solved, the remote connection problem may not be solved.
Error 1130 appears in the remote connection
There are two ways to solve this problem
1. Table modification
Maybe your account doesn’t allow you to log in remotely, only at localhost. At this time, as long as the computer at localhost, after logging into mysql, change the “host” item in the “User” table in the “mysql” database, and change the name from “localhost” to “%”.

mysql -u root -pvmware
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>flush privileges;
mysql>select host, user from user

2. Authorization law
For example, if you want myUser to use MyPassword to connect to a mysql server from any host.

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

If you want to allow user MyUser to connect to the mysql server from a host with IP of 192.168.1.3, use myPassword as the password

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

Supplement: Reinstalling mysql database is not a successful solution
Sometimes you have to reinstall the mysql database, but the installation is always unsuccessful due to the impact of the previous installation of mysql files. You can completely remove the mysql legacy files in the following two steps
1. Full text search MySQL and delete by looking up registry Regedit.
2. Delete MySQL data, generally in the MySQL directory under C: \ProgramData (it is recommended to backup this folder before deleting, so as to restore the data in the future).

MySQL – ERROR 1146 (42S02): Table ‘mysql.user’ doesn’t exist

When we were testing the service and restarting it, we failed and reported an error of “Table ‘mysqlm. user’ doesn’t exist”. This user Table was created before, and it saved the data of users and permissions of the whole database. How could it not exist?
The database login is still normal, indicating that the user is still available, but the query is executed after entering
SELECT * FROM mysql. The user;
ERROR 1146 (42S02): Table ‘mysql.user’ doesn’t exist
Do something!!
When I checked the status of the cluster, I found that it was not normal. The USER table of 3 Mqsql in the cluster was gone, and only Master node was left working alone. Although the other two were RUNNING, they were working independently from the cluster, which was so strange…
Looking for a circle on the Internet, there are some good ways to try;
1 stop service
2 data directory mysql folder rename
3 execute mysql_install_db regenerate authorization table
4 start service
So since the Master can’t move, so I’m going to try slave first, execute mysql_install_DB
The user table is generated, but just like when it was installed, there is no data. The login password has to be reconfigured. In this way, if you join the cluster, there will be some problems.
I had to consult my database-savvy colleagues, and at their suggestion, COPY a user table from somewhere else, and then re-add the user information to the database user table according to the various existing services (fortunately, most of the services in this cluster were applications under test). When you rejoin the cluster, it’s back to normal…
Also, although the user data for the service is not in the table copied, when I restart the service and recreate the user to create the table, It tells me that the user already exists. DROP USER ‘username ‘@’ %’ first; And then “flush privileges”; Refresh permission operation; Recreate the user again, and that’s fine. Does MySQL have a cache of places to store this information??
But why does the mysql.user table disappear?I didn’t see any drop table operation through the MySQL log. It’s so strange… Can only restore the service first, the problem first record and then slowly check…

MySQL operation and maintenance slave_ skip_ errors

1 introduction

mysql during master-slave replication, due to various reasons, the slave server may encounter SQL errors in BINLOG execution. By default, the server will stop the replication process, no longer synchronize, and wait until the user handles it by himself.

slave-skip-errors is used to define the error number that can be automatically skipped from the server during the replication process. When the error number defined during the replication process is encountered, it can be automatically skipped and directly execute the following SQL statement.

2 Official Reference

Command-Line Format –slave-skip-errors=name
System Variable Name slave_skip_errors
Variable Scope Global

Dynamic Variable

No

Permitted Values

Type

string

Default

OFF

Valid Values OFF
[list of error codes]
all
ddl_exist_errors

The slave_skip_errors option has four values available, which are:
Off, all, ErorCode, DDL_exist_errors.

by default, this parameter value is off, we can list the specific error code, you can also choose all, mysql5.6 and MySQL Cluster NDB ddl_exist_errors version 7.3 and subsequent increase the parameter, the parameter contains a series of error code (1007100 8105 0105 1105 4106 0106 1106 8109 4114 6)

some error codes represent the following errors:

Database exists, database creation failed

Database does not exist, database deletion failed

Data table exists. Failed to create data table

Data table does not exist. Deleting data table failed

1054: The field does not exist, or the program file conflicts with the database

1060: Field duplicates and cannot be inserted

1061: Duplicate key name

1068: Multiple primary keys are defined

1094: Location thread ID

1146: Data table missing, please restore database

1053: The primary server went down during replication

1062: Primary key conflict Duplicate entry ‘%s’ for key %d

My. Written in CNF:

slave_skip_errors=1062,1053
slave_skip_errors=all
slave_skip_errors=ddl_exist_errors

As a mysql startup parameter:

--slave-skip-errors=1062,1053
--slave-skip-errors=all
--slave-skip-errors=ddl_exist_errors

View the value of this parameter from the database:

mysql> show variables like 'slave_skip%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| slave_skip_errors | 1007  |
+-------------------+-------+

3. Analysis of Examples

3.1 test instructions
configure mysql master-slave synchronization, and then write data on the slave, causing master-slave inconsistency.
3.2 prepare test table structure
create table on host:

create table replication (c1 int not null primary key, c2 varchar(10));

3.3 Preparation of test data

inserts the underlying data on the host

mysql> insert into replication values (1, 'test1');
mysql> insert into replication values (2, 'test2');

At this point, the host has two records
from the machine replication table. 3.4 starts testing
and inserts one record
from the machine

mysql> insert into replication values (3, 'test3');

Then do the same on the host

mysql> insert into replication values (3, 'test3');

View the replication status on the slave

mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.222
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 16700
               Relay_Log_File: mysql-relay-bin.000003
                Relay_Log_Pos: 16595
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: mysql.ibbackup_binlog_marker
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: mysql.backup_%
                   Last_Errno: 1062
                   Last_Error: Error 'Duplicate entry '3' for key 'PRIMARY'' on query. Default database: 'test'. Query: 'insert into replication values (3, 'test3')'
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 16425
              Relay_Log_Space: 17544

You can see that the SQL thread has stopped working Slave_SQL_Running: No

error number is: Last_Errno: 1062

Error message: Last_Error: Error ‘Duplicate entry ‘3’ for key ‘PRIMARY’ on query.default database: ‘test’. Query: ‘insert into replication values (3, ‘test3′)’

if we add the following option in my.cnf, we can skip this error and the data synchronization continues.

[mysqld]
slave_skip_errors=1062

The specific test method is the same as above, you can verify by yourself.

4 Some explanations for copying errors from machine while recovering from BACKUP
Meb, the mysql Enterprise edition backup tool, provides online hot standby function. If DDL operation is performed during the backup process, the slave machine may be abnormal when it needs to restore from the backup of the host machine, thus causing the slave machine to fail to synchronize data. Reason from the machine need to recover from a backup file when recovery (DDL statements contained in the backup process execution), synchronization is not from perfect after the last position synchronization, but from the last position of the DDL synchronization, if again the DDL statements from the machine will not result in a conflict, which synchronous continue, if can lead to conflict, synchronization is terminated. The solution to this conflict is to add a line to the my.cnF file

[mysqld]
slave_skip_errors=ddl_exist_errors

5 Matters needing Attention

5.1 this parameter is a global static parameter, which cannot be dynamically adjusted. It can take effect by restarting mysql server after adding this parameter list in my.cnf.

5.2 it must be noted that if this parameter is started improperly, it is likely to cause the data in the master-slave database to be out of sync. In the application, it needs to be based on the actual situation. If the data integrity requirements are not very strict, then this option can indeed reduce the maintenance cost

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
the original address: http://blog.csdn.net/jesseyoung/article/details/40585809
the blog home page: http://blog.csdn.net/jesseyoung
****************************************************************************************

MySQL:Foreign key fails with error Error Code: 1452.

Today in MySQL, we add foreign keys to A table, the type is int, the name is not wrong, I temporarily want to add foreign keys to Table A table B, that is, the foreign keys in table A are associated with the primary key in table B.
NavigateSQL, however, always saves an operation with an error:
Foreign key fails with error error Code: 1452. Cannot add or update a child row: a Foreign key constraint fails: XXX.< result 2…

Go through Google and solve from StackOverflow!

The original B table I created temporarily had no data. When I added data to B table, I reported the same error again.

Originally, table A associated table B primary key field value, and table B value inconsistent, I manually changed the consistent “content consistent” can be!

StachOverflow:
http://stackoverflow.com/questions/7354032/foreign-key-fails-with-error-error-code-1452-cannot-add-or-update-a-child-row

Record here for accumulation!

Error 1045 (28000): solution to access denied for user ‘root’ @’localhost ‘(using password: no)


This problem was encountered when installing MySQL service under Windows, which was installed with MySQL green version. After installation, when connecting to MySQL service, enter the command “mysql-uroot-p”. Because the password was not set for the first login, the error message was as follows:
“ERROR 1045 (28000): Access Denied for user ‘root’@’localhost’ (using password: NO)”

The diagram below:

Solutions:
First you need to turn off the MySQL service and enter the command:
mysql> net stop MySQL
To start the local MySQL service in safe mode (note: launch the CMD window as an administrator), enter the command “MySQld — Defaults file=”G:\Install_Applications\ mysql.8.0.11 \ My.ini” –console –skip-grant — tables “to start the MySQL service, the cursor will stop without any output, which indicates that the MySQL service has been started.

Start the CMD window, and enter the command “mysql-uroot-p” to directly enter and log in to the mysql server, and then modify, you can enter the command:
(before 5.7.11) & GT; update user set password=password(“123456″) where user=”root”;

(5.7.11 or later) & GT; update user set authentication_string=password(“123456″) where user=”root”;
Here I’m using:
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘HuaZai12345! ‘;
The diagram below:

Now exit, enter the command “mysql-uroot-p” and enter the password just set, and you can log in to the mysql server normally, as shown in the figure below:

Ok, this is the solution for ERROR 1045 (28000): Access Denied for user ‘root’@’localhost’ (using password: NO). If you have any questions, please feel free to leave me a message.

: “learn together, make progress together”, I also hope that we will pay more attention to the IT community of CSND.

com.microsoft.sqlserver . jdbc.SQLServerException : invalid object name ‘XX’

Myeclipse error message:
Error: com. Microsoft. Essentially. JDBC. SQLServerException: object name ‘xx’ is invalid
Warning: SQL Error: 208, SQLState: S0002
 
Error behavior: HQL statements can run in sqlserver, but run in hibernate to report an error.
Solution: The Settings in the.hbm.xml file of the data table mapping are incorrect. The database name catalog=”eportal” should be added, and the schema name schema=” DBO “should also be added.
This is a new feature in sqlserver2005, in mysql can be omitted.

node.js Server MySQL database connection timeout (error: connect etimeout)

Node. js server mysql database connection timeout problem
Sometimes connection timeouts occur while the Node server is connecting to the database. This Error is Error: Connect ETIMEDOUT. The error position in the code is line 421 to 433 of mysql’s Connection.js file:

Connection.prototype._handleConnectTimeout = function() {
  if (this._socket) {
    this._socket.setTimeout(0);
    this._socket.destroy();
  }

  var err = new Error('connect ETIMEDOUT');
  err.errorno = 'ETIMEDOUT';
  err.code = 'ETIMEDOUT';
  err.syscall = 'connect';

  this._handleNetworkError(err);
};

This error is literally a connection timeout, and then my error is due to the database connection problem, when creating the database should carefully compare the parameters of the problem, like me:
when creating the database connection pool:

pool = mysql.createPool({  
        host: "127.0.0.1",
        user: "user",
        password: "",
        database: "nodejs",
        port: 3306,
    });

The header information in the database is:

Source Server         : localhost
Source Server Version : 50624
Source Host           : localhost:3306
Source Database       : nodejs

Target Server Type    : MYSQL
Target Server Version : 50624
File Encoding         : 65001

It can be seen that there is a problem with the connection address of the server, so the connection was successful after changing to localhost

Can’t connect to MySQL server error 111

20
down vote
favorite

8

http://stackoverflow.com/questions/1420839/cant-connect-to-mysql-server-error-111
I installed mysql server on linux box IP = 192.168.1.100 but when i try to connect to this IP it alway error(111). but use localhost and 127.0.0.1 is OK.

beer@beer-laptop# ifconfig | grep "inet addr"
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0

beer@beer-laptop# mysql -ubeer -pbeer -h192.168.1.100
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.100' (111)

beer@beer-laptop# mysql -ubeer -pbeer -hlocalhost
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 160
Server version: 5.1.31-1ubuntu2 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> 

beer@beer-laptop# mysql -ubeer -pbeer -h127.0.0.1
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 161
Server version: 5.1.31-1ubuntu2 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> 

Connect from another machine it also error 111.

another@another-laptop# mysql -ubeer -pbeer -h192.168.1.100
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.100' (111)

How difference between use localhost/127.0.0.1 and 192.168.1.100 in this case. I don’t know how to connect to this database from another machine.
Help please. Thank.

mysql 
linux 
mysql-error-2003

share
|
improve this question

edited 
Jul 6 ’11 at 16:30

OMG Ponies

107k
13
107
191

asked 
Sep 14 ’09 at 10:47

bugbug

569
2
11
27

61% accept rate

 

Was this post useful to you?  
  

4 Answers

active
oldest
votes

up vote
41
down vote
accepted

It probably means that your MySQL server is only listening the localhost interface.
If you have lines like this :

skip-networking
bind-address = 127.0.0.1

In your my.cnf configuration file, you should comment them (add a # at the beginning of the lines), and restart MySQL.
Of course, to do this, you must be the administrator of the server.

share
|
improve this answer

answered 
Sep 14 ’09 at 10:53

Pascal MARTIN

132k
14
202
310

 

obviously, he doesn’t have the skip-networking line 😉 – 
Michael Krelin – hacker 
Sep 14 ’09 at 10:54

feedback


up vote
8
down vote

111 means connection refused, which in turn means that your mysqld only listens to the localhostinterface.
To alter it you may want to look at the bind-address value in the mysqld section of your my.cnffile.

share
|
improve this answer

answered 
Sep 14 ’09 at 10:50

Michael Krelin – hacker

34.3k
38
68

 

feedback

up vote
2
down vote

If all the previous answers didn’t give any solution, you should check your user privileges.
If you could login as root to mysql then you should add this:

CREATE USER 'root'@'192.168.1.100' IDENTIFIED BY  '***';
GRANT ALL PRIVILEGES ON * . * TO  'root'@'192.168.1.100' IDENTIFIED BY  '***' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

Then try to connect again using mysql -ubeer -pbeer -h192.168.1.100. It should work.

share
|
improve this answer

edited 
Sep 13 ’11 at 10:16

Gilles

23.7k
5
36
77

answered 
Sep 12 ’11 at 21:55

xnome

21
1

 
1  

i don’t think that user privileges related error would give error 111. – 
ufk 
Jun 5 ’12 at 16:16

feedback

up vote
1
down vote

If you’re running cPanel/WHM, make sure that IP is whitelisted in the firewall. You will als need to add that IP to the remote SQL IP list in the cPanel account you’re trying to connect to.

share
|
improve this answer

edited 
May 28 ’12 at 7:38

bfrohs

5,357
9
28

answered 
Apr 30 ’12 at 18:34

Dragos.

11
1

 

feedback

In depth analysis of mysq exceeding the number of connections error 1040 (HY000): too many connections

ERROR 1040 (HY000): Too many connections indicates that mysql has more than one connection
The first solution (not recommended) :
Need to wait for a period of time (quite long), let the existing connection timeout automatically released; Or restart mysql (CentOS7: SystemCTL Restart Mysqld.Service)
The second option (use with caution) :
Login to mysql: mysql-uroot-p your root password
Look at the maximum number of connections mysql is currently setting. In general, the default number of connections to mysql is over 100, and the maximum number can be set to 16384 (2 ^ 14)
show variables like ‘%max_connections%’;
Set the maximum number of connections as needed, so I’m going to set 1000 here
set GLOBAL max_connections = 1000;

Note: This is used with caution because once the server or mysql service is restarted, the Settings will not take effect and the default Settings will be restored
 
The third option (the conditions allow the recommended use) :
Add or modify the max_connections parameter in the mysql configuration file
Linux (centos7) environment:
Windows environment:
Find my.ini in the installation directory. If you don’t have it, find My-default.ini, make a copy and rename it my.ini. Add or modify the max_connections parameter
After setting parameters, restart mysql service.
 
Resources:
FAQ for Installing Mysql5.7 and mysql under Linux(Centos7)

MySQL error 1205 (HY000): lock wait timeout exceeded; try restarting transaction



after querying the current thread, it was found that multiple threads were running at the same time…

to view all currently running transactions:

SELECT * FROM information_schema.INNODB_TRX;


you can find three transactions all running at the same time… So you can find the direct cause of the error reported by the shopkeeper here is:
before the stored procedure (which opened the transaction) ran for half a day, MySQL was manually closed without any response… Didn’t make it commit… And the subsequent deletion of data in the same transaction creates a transaction lock…
The fundamental reason is that MySQL USES the Innodb engine by default, and the default parameter of Innodb: innodb_lock_wait_timeout, which sets the maximum time for transactions to wait for acquiring resources (default 50s). Once the maximum time is exceeded, it will report errors such as questions without obtaining resources.
Well, now that the cause of the error has been identified, there are three solutions:
Find the thread of the current transaction, kill the thread; Enlarge this parameter: innodb_lock_wait_TIMEOUT wait time; Optimize stored procedures.
Here the shopkeeper takes the first approach, killing the redundant threads and then checking all the currently running transactions again:

find something strange?The killed thread Number 10 is still working??Its current state is “ROLLING BACK,” which means that the transaction that was killed a while ago has been in a rollback state. So the shopkeeper continued to look up materials and found that such a situation occurred because although the kill command was triggered, it took a long time to terminate the kill logic, and it was also affected by IO resources. Therefore, rollback occurred even though the kill was executed.
Solutions:
One is to wait for it to roll back; Another is to restart the MySQL, but restart MySQL, the transaction will roll back, so in general is actually etc. It can be rolled back end 😂!

waited for about seven or eight minutes before everything was cleared, and all transactions were over:

and then delete again:

mysql ERROR 1050 (42S01): Table already exists

At the time of database startup, I accidentally deleted the data file, and then I kept working on this table and kept reporting errors. The query report did not exist, but a new table with the same name already existed. The solution is to create a table with the same name in another database and copy its data files.
mysql> show databases;
+ — — — — — — — — — — — — — — — — — — — — +
| Database |
+ — — — — — — — — — — — — — — — — — — — — +
| information_schema |
| mysql |
| performance_schema |
| test |
+——————–+
mysql> use test
mysql> create table t1(id int);
ERROR 1813 (HY000): Tablespace for table ‘`test`.`t1`’ exists. Please DISCARD the tablespace before IMPORT.
mysql> alter table t1 DISCARD tablespace;
ERROR 1146 (42S02): Table ‘test.t1’ doesn’t exist

mysql> create database gg;
mysql> show databases;
+ — — — — — — — — — — — — — — — — — — — — +
| Database |
+ — — — — — — — — — — — — — — — — — — — — +
| information_schema |
| gg |
| mysql |
| performance_schema |
| test
| + — — — — — — — — — — — — — — — — — — — — +
mysql> use gg
Database changed
mysql> create table t1(id int);

go to the database gg
cp-a t1.frm.. /test/t1.frm

mysql> select * from t1;
ERROR 1146 (42S02): Table ‘test.t1’ doesn’t exist
mysql> Alter TABLE T1, TABLESPACE;
Query OK, 0 rows affected, 2 warnings (0.01 SEC)

goes to database gg
cp -a t1.ibd .. /test/t1.ibd
mysql> use test
mysql> select * from t1;
ERROR 1814 (HY000): Tablespace has been discarded for table ‘t1’
mysql> Alter TABLE T1 Import TABLESpace;
Query OK, 0 rows affected, 1 warning (0.04 SEC)
mysql> select * from t1;
Empty set (0.00 SEC)

Mysql error 1452 – Cannot add or update a child row: a foreign key constraint fails

Today, when you add a foreign key to a mysql table, you always report an error. Here is the SQL statement:

Alter table A  

Add constraint FK_1 Foreign Key (‘ relation_ID ‘) References B(‘ id ‘) on UPDATE Cascade on DELETE Cascade

Error code: 1452
See the table is also no problem, and the field of RELATION_ID is no foreign key ah ~~~
Finally, a solution is found in Google. The general method is as follows:

mysql> SET foreign_key_checks = 0;

mysql> alter table tblUsedDestination add constraint f_operatorId foreign key(iOperatorId) references tblOperators (iOperatorId); Query
OK, 8 rows affected (0.23 sec) Records: 8  Duplicates: 0  Warnings: 0

mysql> SET foreign_key_checks = 1;

Make foreign_key_checks invalid first, then add foreign keys to the table, and finally make foreign_key_checks effective!
There is a reason for foreign_key_checks. If you cannot add a foreign key because it violates the constraint, you should correct the data first. Turning off checks and then adding keys puts you in an inconsistent state. Foreign key checks add overhead, and if you don’t want to use them, use myisam instead of