Tag Archives: mysql

Error 1045 (28000) access denied for user ‘root’ @’localhost ‘appears in MySQL under Windows system

Error 1045(28000) Access Denied for user ‘root’@’localhost’

From http://zxy5241.spaces.live.com/blog/cns! 7682A3008CFA2BB0! 361.entry
When installing mysql database in Windows operating system, you encounter Error 1045(28000) Access Denied for user ‘root’@’localhost’, you need to reset the password.
the specific method is:
1. First, find my. Ini configuration file in the installation directory, open the configuration file, find the line [mysqld], add skip-gran-tables below and save the file, and restart mysql dynamic service.
2. Then execute mysql -u root mysql
mysql> update user set password=password(‘newpassword’) where user=’root’;
mysql> Flush privileges;
where newpassword is root’s newpassword. 3. Remove the line that added to my. Ini configuration file just now, and finally restart mysql.

After installing mysql or uninstalling the downloaded free version, the default is no my.ini file.
. However, there are several similar files, such as [code] my-small-ini, my-media.ini, my-large. Ini, my-huge. Ini, [/code].
these files are the different configuration information recommended by mysql for different applications; But these configurations will only be applied if you put them in my. Ini.
where:
1, my-small. Ini is designed for small database. This model should not be used for databases that contain common items.
2, my-media.ini is designed for medium-sized databases. If you are using RHEL in the enterprise, you will have significantly more physical memory than the minimum RAM requirements for this operating system (256MB). As you can see, if you have that much RAM memory available, you can naturally run other services on the same machine.
3, my-larg.ini is designed for use exclusively with a SQL database. Since it can use up to 512MB of memory for the database, at least 1GB of RAM will be required on this type of system so that it can handle both operating system and database applications.
4, my-huge. Ini is designed for databases in enterprises. Such a database would require a dedicated server and 1GB or more of RAM. These choices are highly dependent on the amount of memory, the speed of the computer, the size of the database details, the number of users accessing the database, and the number of users loading and accessing data into the database. The performance of the database may change as the number of databases and users increases.

according to their own situation, select a file configuration copy to my. Ini file, of course, you need to create your own, just create a new file, and then copy into the configuration information.

The MySQL load data command parses and handles error 29 (errCode: 13) errors (in the Ubuntu environment)

On the mysql server, you can use the following command:

load data infile 'file_name' into table table_name; 

Stores all data in a text file into the specified table. The crudest form of example:

load data infile 'test.txt' into table test_table;

By default, the Load Data Infile behavior for text is:
A

    row corresponds to a record in the database table separated by the TAB key the value of each field is not enclosed by any characters and the row is not prefixed to ignore

For example, a line of text:
1 test “xx”
reads into the database, and the value of the third field is “xx” instead of xx. Of course these fields can be set, the full Load Data Infile command is:

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'
   [REPLACE | IGNORE]
  INTO TABLE tbl_name
   [FIELDS
    [TERMINATED BY 'string']
   [[OPTIONALLY] ENCLOSED BY 'char']
   [ESCAPED BY 'char' ]
 ]
   [LINES
   [STARTING BY 'string']
  [TERMINATED BY 'string']
  ]
   [IGNORE number LINES]
  [(col_name_or_user_var,...)]
   [SET col_name = expr,...]]

Ignore and replace are used to distinguish between the way in which the text is read and the record in the original table that has a primary key conflict. The terminated by setting field (delimiter) after
fields, enclosed by setting outer enclosing characters, and escape by setting escape characters (this is unclear).
lines, starting by sets the line prefix, will be ignored when reading, and the newline character is set. Refer to the first link for more details.
Then in the process of use, it is easy to have errors:
ERROR 29 (HY000): File ‘test.txt’ not found (Errcode: 13) But it is of no damn use From the command line you can see that errcode 13 refers to the access issue:

xyb@xyb-computer:~$ perror 13
OS error code 13: Permission denied

Even if you change the access to the test.txt file, such as chmod O +r test.txt, the problem will still occur. It involves AppArmor. This is a protection mechanism that restricts each program’s access to specific directories and files. In other words, it is restricted by AppArmor, which provides access to the file for the current mysql program. See link to article 2 about AppArmor (Wikipedia).
can really do is to mysql program reads the file permissions, according to the following steps can be done:
1) open the/etc/apparmor. D/usr. Sbin. Mysqld file
2) can see a lot about mysql can read and write at this time for the directory and file records, such as:

#Other contents
/usr/sbin/mysqld {
    #Other contents
    /var/log/mysql.log rw,
    /var/log/mysql.err rw,

    #Other contents

    #This will be your dir definition
    /tmp/ r,
    /tmp/* rw,

    #Other contents
}

Add the appropriate permissions for the file you want to read and write at the end, save and exit. D/AppArmor reload
. At this point, the problem should be solved. But this can be an unsafe solution and requires caution. Refer to the third link for details.
Reference links:

https://en.wikipedia.org/wiki/AppArmor http://www.2cto.com/database/201108/99655.html https://oldwildissue.wordpress.com/2013/12/11/fixing-mysql-error-29-errcode-13-in-ubuntu/

The server just without updating PID file and can’t connect to local MySQL server through socket are solved

1. Report an error when logging into mysql

$ mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

This error occurs because MySQL has not been started. To verify this guess, you can turn on the activity monitor and search mySQld, which cannot be found. Since I took the screenshot after fixing the problem myself, the mySQld process was already started when I searched.

Or type a command to view mysql.server Status

$ mysql.server status
/usr/local/mysql/support-files/mysql.server: line 365: pidof: command not found
 ERROR! MySQL is not running

As you can see, MySQL is not running. Since MySQL isn’t running, we definitely need to start MySQL.
Second, MySQL startup also reported an error

$mysql.server start
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/XXXX.local.pid).

The boot report is wrong, is the permission not enough?So first change the permissions of /usr/local/var/mysql

sudo chown -R _mysql:mysql /usr/local/var/mysql

Once the permissions are resolved, test it with SUdo and restart it
3. Start sudo

$ sudo mysql.server start
Password:
Starting MySQL
.. SUCCESS! 

Surprisingly, MySQL started successfully, and then logged in again

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21-log Homebrew

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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.

Summary: The problem of Can’t connect to local MySQL Server through socket is caused by MySQL not being started. The Server Quit without updating The PID file is due to permissions problem, which is solved and The first problem is solved accordingly.
Of course, due to different environment configuration and different installation methods, there will be some differences in the solution, but the cause of the problem should be the same. I am a Mac, homebrew installed mysql, through this method, successfully solved the problem.
Refer to the information on StackOverflow:
MySql server startup error ‘The server quit without updating PID file ‘
For a newbie: ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’
 

MySQL failed to add foreign key error 1452

MySQL failed to add foreign keys, error 1452
For example:
Two tables user table: User class table: Grade
Each user in the user table corresponds to a class ID, namely gradeId
Namely: The primary key of the User table gradeId is the Id in the Grade table
The user table is called the primary table and the Grade table is called the slave table
[SQL]

alter table user

Add Foreign Key (gradeId) References Grade (Id);  

[error]

ERROR 1452 : Cannot add or update a child row: a foreign key constraint fails

“Why”
Some gradeId in the User table do not belong to the ID in the Grade table
【 Solution 】
Modify the data so that all gradeId in the User table belong to ids in the Grade table

Mybatis batch insert data

Due to the project need to generate more data, and saved to the database, in the program encapsulates a List collection objects, then need to put the collection of entities in the inserted into the database, the project USES the Spring + MyBatis, therefore intends to use the MyBatis bulk insert, should be better than that of circular insert, because before used bulk insert, finally achieved after got some information on the Internet, stick process in detail. For future reference and study.
Java code:

Java code:

Explain MySQL replication error 1032 & 1205

Most of the businesses using MySQL involve Replication, and master-slave mechanisms are often used for reading and writing separation,HA, hot backup, or incremental Replication.
However, in many cases, 1032 and 1205 errors are reported
1032 in the first place.
Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND;
The root cause of the 1032 error was inconsistency in the master-slave database data, resulting in the synchronization operation not being performed on the slave library.
There are two kinds of situations I have encountered so far:
For Replication, I used master –binlog-do-db=db_name or slave — Replicate_do_db =db_name.
If two libraries pubs and test, ignore the test, the results have a SQL in the master test library implementation: insert into pubs. Tname values (XXXXX);
Then, depending on the configuration of the service, a 1032 error is raised if the master executes successfully and the master does not
2 TRIGGER and PROCEDURE version problem. If the master-slave version is inconsistent, for example, five pieces of data are written after the execution of a PROCEDURE on the master-slave version, while only one line of data is written after the execution of a PROCEDURE on the master-slave version, then a 1032 error is bound to occur

Solutions:
1. It doesn’t use –binlog-do-db and — Replicate_do_DB =db_name
Change from top — Replicate_wild_do_table =db_name.%
2 Ensure that the master-slave TRIGGER and PROCEDURE versions are consistent

Say again 1205:
This error is easy to understand. Typically, the primary operation connection is autocommit, and as a result, the runtime fails and an error is reported when synchronizing from the library.
Two ways to do it:
Set my.cnF Innodb_rollback_on_TIMEOUT =1 on the primary, rollback for timeout
2. Ignore 1052. My. CNF — slave-skipping-errors =1205 from above

1205 occurs on the main library, often because of lock timeouts. For example, using a transaction on a table results in one transaction not committing late, another transaction waiting for the previous transaction to commit, lock wait timeout, and the latter transaction hanging. A 1205 error occurred on the main library. The most common is when a table has a self-growing ID, and an INSERT initiated transaction is delayed for several reasons, so that subsequent transactions wait for the previous INSERT operation to commit when performing the insert operation on the table. These all require DBAs and R& D Cooperate to complete. The service performance is low CPU utilization, but load is unusually high. If you look innoDB status, you can catch lock conflicts randomly.

[ERROR] ERROR reading packet from Server: Lost Connection to MySQL Server during Query (server_errno=2013)
In general, three situations will lead to 2013 errors
1 Reverse parsing
2 Max_allowed_packet is inconsistent
3. Network Problems

The solution
1 Skip-name-resolve is forbidden to reverse resolve
Configure master slave max_allowed_packet with the same value
3 Adjust the value of net_write_TIMEOUT

A friend of mine reported a mistake in 2013 when I was writing notes. None of the three schemes mentioned above worked, and Lost Connection to MySQL Server appeared very timely. Finally, I found out that the network agent controlled the connection for more than 30 minutes and automatically hung up…

Cannot connect to MySQL server on “host” (113)

Connection to remote MySQL error:
ERROR 2003 (HY000): Can’t connect to MySQL Server ‘IP’ (113)
View error types (Linux system)

perror 113

The results are as follows:
OS error code 113: No route to host
The reason for this error is that the server-side firewall does not open the port used by the MySQL program. By default, it is 3306 and the open port is ok

/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT 

Save the Settings and restart the firewall

service iptables save
service iptables restart

Error 1364 (HY000): field ‘SSL_ cipher’ doesn’t have a default value

When creating a user in mysql today, you can see how to insert data directly into the User table when someone is using it, as follows:

mysql> insert into mysql.user(Host,User,Password) values("localhost","test",password("1234"));

So I also tried to create users with this method in the database, but got the following error:

mysql> insert into mysql.user(Host,User,Password) values('localhost','siu',password('siu'));       
ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value

The reason for this error is that mysql’s default configuration is strict mode, which prohibits adding new users by directly modifying the USER table in the mysql library by INSERT.
solution is to modify my. Ini (Windows system) or my. Conf (Linux system) configuration file, taking Linux system as an example:

sql-mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Modified to:

sql-mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Then restart the mysql service

service mysql restart

Create the user again and it will be successful

mysql> insert into mysql.user(Host,User,Password) values("localhost","joey",password("1234"));    
Query OK, 1 row affected, 3 warnings (0.00 sec)

It is important to note, however, that since mysql by default forbids this method to create users for database security, we should also avoid creating users by inserting. The correct way to create a user is:

mysql> create user 'joey'@'localhost' identified by 'joey';
Query OK, 0 rows affected (0.00 sec)

This user is then authorized for certain databases:

grant all privileges on joey.* to 'joey'@'localhost' identified by 'joey'; 
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

HTTP status 500 – internal server error (resolved) for Tomcat running project

Today, when I was working on the student information management system, I just ran tomcat and opened the web page and clicked on the student table.

program could not go when I went to the Servlet. I checked the content of the Servlet and found that there was no mistake, and there was no problem after I looked at the interface implementation of Dao layer.
Finally, I thought about it and found that My Mysql was turned off when I ran PHPstudy yesterday. Then I opened the service and found that my Mysql was in a stopped state.

here because yesterday when using PHPStudy, because the integrated environment in PHPStudy contains Mysql, when Mysql on our computer is turned on, Mysql in PHPStudy cannot run. So I shut down Mysql on my computer.
So if we right click on Mysql, we can start, and Mysql is up and running, and our project is running successfully.

Txt import MySQL: error 1062 (23000): duplicate entry ‘0’ for key ‘primary’

Existing problems:
When importing TXT file into Mysql database, ERROR 1062(23000) always appears: Duplicate entry ‘0’ for key ‘PRIMARY’ ERROR, but TXT file does not have a data with ID (PRIMARY key) of 0.


Reason for error:
This is still not clear, because I have no record of ID=0, so I don’t know why the duplicate ID is 0. At first, I thought it was the data encoding that caused the data chaos, but later I found that even the same encoding could not solve the problem.

Solutions:
Setting the primary key (ID) to AI (Auto Incremental) is sufficient. Setup has been completed and import has been successful

Note:
I thought that if I set the primary key to AI, the primary key column would be 1, 2, 3… , because the primary key in TXT file is discontinuous, but I found that this understanding is wrong, after insertion, the primary key still maintains its discontinuity.

Linux-mysql8.0 password reset problem – error 1396 (HY000): Operation alter user failed for ‘root’ @’localhost ‘

Step 1: open my.cnf configuration file and add skip-gran-tables


. CNF cannot be found, so you can edit a

by yourself in /etc. Step 2: restart mysql

step 3: after login, leave the password empty and modify it. Otherwise, an error will be reported
Update User Set Authentication_string = ‘” Where user=’ root ‘;
ALTER USER ‘root’ @’ localhost ‘IDENTIFIED WITH mysql_native_password BY’ password ‘;
ALTER USER ‘root’ @’ localhost ‘IDENTIFIED WITH mysql_native_password BY’ password ‘