-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Một vài ghi chép nhỏ về Galera - MariaDB, MySQL #1
Comments
Đọc binlog để sinh ra SQL: https://github.com/danfengcao/binlog2sql
|
How to fix “error no 1062” in MySQL servers and clusters Here at Bobcares, we provide Server Administration and Maintenance services to website owners and web solution providers. An error we sometimes see in MySQL servers while updating, restoring or replicating databases is: “Error No: 1062” or “Error Code: 1062” or “ERROR 1062 (23000)“ A full error log that we recently saw in a MySQL cluster is:
What is MySQL Error No: 1062? Simply put, error 1062 is displayed when MySQL finds a DUPLICATE of a row you are trying to insert. We’ve seen primarily 4 reasons for this error:
In rare cases, this error is shown when the table becomes too big, but let’s not worry about that for now. How to fix Error No 1062 when your web appilcation is broken Every database driven application like WordPress, Drupal or OpenCart distinguishes one user or data set from another using something called a “primary field”. This primary field should be unique for each user, post, etc. Web apps use a code like this to insert data: INSERT INTO table ('id','field1','field2','field3') VALUES ('NULL','data1','data2','data3'); Where “id” is the unique primar key, and is set to auto-increment (that is a number inserted will always be greater than the previous one so as to avoid duplicates). This will work right if the value inserted is “NULL” and database table is set to “auto-increment”. Some web apps make the mistake of passing the value as VALUES ('','data1','data2','data3'); where the first field is omitted. This will insert random numbers into the primary field, rapidly increasing the number to the maximum field limit (usually 2147483647 for numbers). All subsequent queries will again try to over-write the field with “2147483647”, which MySQL interprets as a Duplicate. Web app error solution When we see a possible web application code error, the developers at our Website Support Services create a patch to the app file that fixes the database query. Now, we have the non-sequential primary key table to be fixed. For that, we create a new column (aka field), set it as auto-increment, and then make it the primary key. The code looks approximately like this: alter table table1 drop primary key; Once the primary key fields are filled with sequential values, the name of the new field can be changed to the old one, so that all web app queries will remain the same. Warning : These commands can get very complex, very fast. So, if you are not sure how these commads work, it’s best to get expert assistance. How to fix MySQL replication Error Code : 1062 Due to quirks in network or synching MySQL is sometimes known to try and write a row when it is already present in the slave. So, when we see this error in a slave, we try either one of the following depending on many factors such as DB write traffic, time of day etc.
How to delete the row First delete the row using the primary key. delete from table1 where field1 is key1; Then stop and start the slave: stop slave; Once it is done, check the slave status to see if replication is continuing. show slave status; If all is well, you’ll see “Seconds_Behind_Master” as a number. If not, your replication is broken and it needs to be fixed. How to skip the row For this, you can set the Skip counter to 1. Here’s how it could look like: stop slave; Then check the slave status to see if replication is continuing. show slave status; Again, if all is well, you’ll see “Seconds_Behind_Master” as a number. If not, your replication is broken and it needs to be fixed. Proceed with caution Stopping and starting the slave cannot cause any issue unless you havea very busy database. But, the delete statement, skipping and following up with a broken replication requires expert knowledge about MySQL organization and functioning. If you are not sure how these commands will affect your database, we recommend you talk to a DB administrator. How to fix MySQL restore errors Restore errors usually take the form of: ERROR 1062 (23000) at line XXXX: Duplicate entry ‘XXXXXX’ for key X” When restoring database dumps, this error can happen due to 2 reasons:
To find out what is exactly going wrong, we look at the conflicting rows and see if they have the same or different data. If it’s the same data, then the issue could be due to duplicate index rows. If it is different data, the SQL dump file needs to be fixed. How to fix duplicate entries in database dumps This situation can happen when two or more tables are dumped into a single file without checking for duplicates. To resolve this, one way we’ve used is to create a new primary key field with auto-increment and then change the queries to insert NULL value into it. Then go ahead with the dump. Once the new primary field table is fully populated, the name of the field is changed to the old primary table name to preserve the old queries. The alter table command will look like this: alter table table1 change column 'newprimary' 'oldprimary' varchar(255) not null; If your index file is corrupted There’s no easy way to fix an index file if there are duplicate entries in it. You’ll have to delete the index file, and restore that file either from backups or from another server where your database dump is restored to a fresh DB server. The steps involved are quite complex to list out here. We recommend that you consult a DB expert if you suspect the index file is corrupted. Summary MySQL error no 1062 can occur due to buggy web applications, corrupted dump files or replication issues. Today we’ve seen the various ways in which the cause of this error can be detected, and how it can be resolved. |
Mysql replication error 1594 - Relay log read failure - Could not parse relay log event entry Sometimes mysql replication crash with corrupted relay binlogs and it is not possible to restart it with simple "start slave" command. Here is step by step manual how to fix it. To check the current slave status execute command: show slave status\G You should see result similar to this:
Important values you should notice are Relay_Master_Log_File and Exec_Master_Log_Pos. You will need them to correctly restart replication on your slave. To restart replication execute following commands:
To check if replication is working again, execute again command:
Before you will call your slave as synced, check value of parameter Seconds_Behind_Master from the status command. In our case I have seen value (5187 seconds): Seconds_Behind_Master: 5187 Within next few minutes was replication synced again with master and replication lag was 0s Seconds_Behind_Master: 0 This is the time, when we can start using mysql slave again in the production. |
MySQL table to JSON:
|
|
MySQL Error 1062 Run SQL:
Or set in mysql config:
|
Sửa lỗi database bị crash
HOẶC
Đăng nhập vào console MySQL
Đổi port mặc định của MySQL/MariaDB
/etc/my.cnf.d/server.cnf
Thêm tùy chọn
port
vào phần cấu hình[mysqld]
Lưu ý:
Tham khảo: https://www.tecmint.com/change-default-mysql-mariadb-port-in-linux/
Cách RESET password
root
trong MariaDB/MySQLKiểm tra lại các tiến trình mysql đã kết thúc hay chưa? Nếu chưa sử dụng lệnh sau để ngắt toàn bộ tiến trình của MySQL.
Cập nhật password mới:
Tham khảo: https://www.tecmint.com/reset-mysql-or-mariadb-root-password/
Backup toàn bộ Database trên Server
Thay đổi Password cho một USER
Tuning một vài thông số cho MariaDB
Thư viện libssl 1.0.0 Ubuntu 20.04
The text was updated successfully, but these errors were encountered: